What’s the best way to set a cross compiler’s unsupportedHardeningFlags attribute?
This attribute is used by the cc-wrapper to disable specified hardening flags in add-hardening.sh. I’d like to disable the stackprotector flag for my cross compiler (because it’s broken on powerpc-musl), which I managed to do so using the snippet below:
import <nixpkgs> {
overlays = [ (
self: super: {
gcc = if super.stdenv.targetPlatform != super.stdenv.hostPlatform && super.stdenv.targetPlatform.isPowerPC then super.gcc.overrideAttrs (old: {
postFixup = builtins.replaceStrings [''export hardening_unsupported_flags="''] [''export hardening_unsupported_flags="stackprotector''] super.gcc.postFixup;
}) else super.gcc;
}
) ];
crossSystem = {
config = "powerpc-unknown-linux-musl";
};
}
I can succesfully enter an env using the code above, i.e.:
# nix-shell -E 'with import ./test.nix; mkShell { buildInputs = [ zlib ]; }'
Even though this works, its an obvious hack. I’m new to nix(os), so I’m sure there’s a better approach.
I’ve come up with two alternate approaches, which both didn’t work.
- It would seem a cleaner way would be to override
cc
, becausecc.hardeningUnsupportedFlags
is actually used to emit the code I’m crudely replacing. I don’t know how to do this though, as it’s passed in as an argument to thecc-wrapper
function.
## Hardening support
##
+ ''
export hardening_unsupported_flags="${builtins.concatStringsSep " " (cc.hardeningUnsupportedFlags or [])}"
''
- I tried overlaying
gcc-unwrapped
to sethardeningUnsupportedFlags
in my overlay, assuming this would somehow end up being thecc
passed tocc-wrapper
. Unfortunately, this doesn’t seem to be the case. My main problem with this approach is that I do not understand how (or if) I can influencecc
by overlayinggcc-unwrapped
(orgcc10
).
Any suggestions for a cleaner approach - or an explanation why my other ideas won’t work - would be appreciated.