Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fortify hardening still overrides debug builds in many cases #60919

Open
nh2 opened this issue May 4, 2019 · 8 comments
Open

fortify hardening still overrides debug builds in many cases #60919

nh2 opened this issue May 4, 2019 · 8 comments

Comments

@nh2
Copy link
Contributor

nh2 commented May 4, 2019

This is in some way a continuation of #18995 GCC has unwanted flags.

Even though that one is marked as solved, I have over the last 2 years encountered many situations where silently -O2 -D_FORTIFY_SOURCE=2 is added to builds where I have explicitly requested that a debug build be done (which should result in -O0 / no -O flag being passed).

For example, right now on meson-based builds (on Darwin, but I believe on Linux too), if I set

mesonBuildType = "debug";

it does not have the desired effect unless I also add

hardeningDisable = [ "fortify" ];

because the fortify hardening adds -O2 -D_FORTIFY_SOURCE=2 no matter what.

The same happend to me in various C++ builds, and it's always a big drag in development time when you just can't get your -O0 debug builds working.


Reading the PR description of #28029, it says

user supplied -O flags should take precedence over the hardening flags

so I suspect that this isn't good enough, because most development builds don't add -O0 explicitly -- instead they add no -O flag at all, so even with the PR -O2 is still added.

I think we must do something about it because it's a total pain.

@matthewbauer matthewbauer added this to the 19.09 milestone May 27, 2019
@jirkadanek
Copy link
Member

As a more universal workaround, one might want to use the catch-all

hardeningDisable = [ "all" ];

for example when the build error is

cc1plus: error: -Wformat-security ignored without -Wformat [-Werror=format-security]

@stale
Copy link

stale bot commented Jun 2, 2020

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 2, 2020
@jiridanek
Copy link
Contributor

still an issue, but not really important to me

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 2, 2020
vs49688 added a commit to UQ-RCC/nimrodg-agent that referenced this issue Oct 14, 2020
@stale
Copy link

stale bot commented Nov 29, 2020

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 29, 2020
@nh2
Copy link
Contributor Author

nh2 commented Nov 29, 2020

still important to me

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 29, 2020
@veprbl veprbl removed this from the 19.09 milestone May 31, 2021
@cstrahan
Copy link
Contributor

cstrahan commented Apr 4, 2023

@nh2 maybe we should implicitly disabled the fortify hardening if the build type is debug? That seems to be the most logical solution, IIUC.

@zarelit
Copy link
Member

zarelit commented Apr 5, 2023

Just putting this here since it backlinks to the old issue. This behavior impacts people working with Go as well, I have to disable fortify to make delve debugger work in vscode. go-delve/delve#3085

I don't know the infrastructure good enough to decide if the "unable to run delve" should be another issue on its own

@coreyoconnor
Copy link
Contributor

This also impact scala-native - can't seem to not have fortify hardening applied.

huynguyen added a commit to huynguyen/Hyprland that referenced this issue Jan 17, 2024
This disables '_FORTIFY_SOURCE' Werrors trying to compile wlroots.
Long standing issue in NixOS/nixpkgs#60919
afaik.

After this change you should be able to:
```
nix develop
mmeson setup build -Dbuildtype=debug
ninja -C build
```
fufexan pushed a commit to hyprwm/Hyprland that referenced this issue Jan 17, 2024
This disables '_FORTIFY_SOURCE' Werrors trying to compile wlroots.
Long standing issue in NixOS/nixpkgs#60919
afaik.

After this change you should be able to:
```
nix develop
mmeson setup build -Dbuildtype=debug
ninja -C build
```
yipengsun added a commit to HamPepper/template-project-cpp that referenced this issue Oct 9, 2024
nixpkgs enables fortification by default, which adds `-O2` flag to gcc.
This breaks the debug build. For more info, see:

NixOS/nixpkgs#60919
NixOS/nixpkgs#18995

I also manually added `-O0` flag in debug flags in cmake.
This is, gcc would complain if I forgot to disable fortification.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants