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
GCC has unwanted flags #18995
Comments
I believe this was caused by #12895 |
Not only that, but these flags are in the |
One workaround is putting
in a nix-shell. Since I was already using a nix-shell for my environment, this is an acceptable workaround. Still, seems weird to assert -O2 by default and have to disable it to get previously expected behavior. |
I think this can be fixed by adding a special flag, BTW having |
You can use
to disable all hardening flags. This should also work if set as an environment variable. We will work on a solution after 16.09 using gcc spec files that can detect for example if libraries are built or debugging is enabled. This was just our first iteration and we agree that it is not perfect. Changes to the cc-wrapper always require a full rebuild, which is very painful. More feedback on #12895 would've been helpful. We didn't anticipate and test that those flags would be propagated to regular gcc invocations outside of nix builds. Not entirely sure how to fix it yet but @abbradar's proposal sounds reasonable. I will look into it after 16.09.
|
FWIW I found that level 1 fortifying requires inlining:
I haven't been able to find anything except of anecdotal evidence that |
I'm always open for suggestions. Thanks! |
Unfortunately it may need peeking into |
Just as a quick reminder when you talk about |
So this is why recently gdb suddenly tells me different things in my code and gcc no longer does a good job optimizing my code. I almost thought gcc 5.4 had optimization regressions. How do I get back a reasonable working gcc? Which nixpkgs version should I revert to? Does this mean I should put I'm using nixpkgs on a ubuntu without root privilege. It is NOT okay to leave |
We're all in agreement here @jxy and going to fix it soon. This is why it's called unstable! The workaround you mentioned is working for me and is probably the reasonable thing to do until this is fixed. |
Right, thanks for the workaround. It wasn't easy to find this thread. I guess I'll need some performance regression tests after changing my system. |
Does NixOS 16.09 release version have this issue? If so, I'll put off upgrading until this is fixed. |
Yes, both 16.09 and unstable/master. |
I'm currently working on a fix. |
even though I knew about this, I temporarily forgot and it caused me to file a bogus issue report on another project: thejoshwolfe/legend-of-swarkland#36 |
I'm running into this issue when compiling older versions of GCC. gcc 4.8 compiles fine, but at run time, it tries to use stack-protector-strong, which is not supported. I've wasted about 8 hours so far trying to fix this broken thing.... Our fork of nixpkgs is based on 16.09 and is here: is there any commit I could pull to fix this ? |
There is no optimal fix yet, workaround is still to |
Thanks. |
/ping @edolstra I hate to bug you personally/directly, but would you be able to specify your desired approach to fixing this bug - or if you can't spare the cycles for that, could you name an individual or two that you'd feel comfortable deferring to? There's enough subtlety to the problem that I doubt everyone here will come to anything approaching a consensus. Nonetheless, the problem needs fixing, and I'd like to do the work to fix it - if someone with authority can state what an acceptable solution is. Just as a reminder, I have this PR open: #28029 There's some feedback regarding cross compilation from @Ericson2314 that I can address, but I'm first waiting to know if we're going to accept that general approach, a variant of it, or something else entirely. |
@cstrahan The PR looks good to me, thanks. It might be nice to issue an error/warning if there is a conflict between a hardening flag and a user-supplied |
@edolstra Awesome - thanks! I'll address @Ericson2314's points and try to get it ready for merging soon as I can - probably before the weekend is up. |
Even though I originally filed the bug, and it bit me again after that, I still forgot about it again and got bit by this issue again, wasting the musl-lib developers' time. |
Hopefully @cstrahan's PR will be done soon. My bad recently for reviewing it slowly when he took it up again. |
I ran into this as well, even though I'm on 18.09. After writing out most of a comment here to ask why, I realized I needed to re-instantiate my default.nix in order to actually pull in the new stuff. After doing that, I promptly got:
whenever I tried to build my project (which uses Since I've been reading this thread, I knew to try (Yes I could've disabled |
We continue to be plagued by this; I've opened a new issue on #60919. Copying the descrpition here, so that people subscribed here can see what it's about and subscribe there if interested (I think the discussion should probably continue there): 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 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
because the fortify hardening adds 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 Reading the PR description of #28029, it says
so I suspect that this isn't good enough, because most development builds don't add I think we must do something about it because it's a total pain. |
This is asinine behaviour. See: - NixOS/nixpkgs#18995 - NixOS/nixpkgs#60919
set/unset `NIX_HARDENING_ENABLE` env var; https://stackoverflow.com/a/27719330/2768067 We need to unset this because `delve` debugger is failing to debug with some error. ``` runtime/cgo warning _FORTIFY_SOURCE requires compiling with optimization (-O) | ^~~~~~~ cc1: all warnings being treated as errors exit status 2 ``` see issue: NixOS/nixpkgs#18995 also see PR: https://github.com/NixOS/nixpkgs/pull/28029/files on how it is set
Got hit by that too in 2022. So apparently it's not fixed. Been using gcc in a Nix shell, and couldn't perform debug on tests in Go because of the fortify flag. |
It's important to note that fortification isn't the only issue here. Having any behavioral flags passed to the compiler implicitly is unexpected to people who use Nix to obtain a development environment for C and C++ (and even Rust, where bindgen also uses cc-wrapper). For the use case of C and C++ development, as opposed to the use case of writing Nix packages for inclusion in Nixpkgs, the only wrapping that should really be done is passing directories to the compiler, so that it can find crt1, libc, compiler-rt, etc. I think the cleanest and most flexible solution would be to have a Nix function that takes a toolchain configuration and returns a set of toolchain derivations that generate appropriate wrappers. For the use case of writing Nix packages for inclusion in Nixpkgs, this function would be applied to the list of flags that are currently supplied by cc-wrapper. But if a C or C++ programmer wants different flags, they can easily do so. |
I was able to get go testing / delve working in VS Code by launching it as |
These flags should be enabled when compiling nix packages, but they should not be always on for general compiler use.
This has caused a broken debugging experience for me on the project I was working on.
Most projects have a "debug build" that has optimizations off, and this prevents that from working correctly.
NixOS version 16.09pre90254.6b20d5b (Flounder)
The text was updated successfully, but these errors were encountered: