git.iko.soy/typeable/nixpkgs
on master help sign in
stdenv: Fix regression on ARM+static when enabling hardening (#115363)

4e9dc46dea0ef8cf15c567fa863796bb23099d0b re-enabled hardening for Musl, which is good. Though static builds for ARM fail in various ways - cross armv7l static does not build - cross aarch64 static produces segfaulting dynamically linked binaries - native aarch64 static also produces segfaulting dynamically linked binaries It seems that for native x86_64-linux, static builds are fine though. This works around the issue by removing PIE from the hardening flags, keeping all other hardening flags. This is an improvement (I think) from before 4e9dc46d. Fixes #114953

commit76552e95cc6679de7b690ef624135b71b3b326d7 authorSamuel Dionne-Riel <samuel@dionne-riel.com> dateTue 23 Mar 2021, 18:45 (6 years ago) parent924b214
1 file changed+6−1
pkgs/stdenv/generic/make-derivation.nix+6−1
pkgs/stdenv/generic/make-derivation.nix+6−1
@@ -106,7 +106,12 @@ in rec {
106106 ++ depsTargetTarget ++ depsTargetTargetPropagated) == 0;
107107 dontAddHostSuffix = attrs ? outputHash && !noNonNativeDeps || (stdenv.noCC or false);
108108 supportedHardeningFlags = [ "fortify" "stackprotector" "pie" "pic" "strictoverflow" "format" "relro" "bindnow" ];
109− defaultHardeningFlags = if stdenv.hostPlatform.isMusl
109+ # Musl-based platforms will keep "pie", other platforms will not.
110+ defaultHardeningFlags = if stdenv.hostPlatform.isMusl &&
111+ # Except when:
112+ # - static aarch64, where compilation works, but produces segfaulting dynamically linked binaries.
113+ # - static armv7l, where compilation fails.
114+ !((stdenv.hostPlatform.isAarch64 || stdenv.hostPlatform.isAarch32) && stdenv.hostPlatform.isStatic)
110115 then supportedHardeningFlags
111116 else lib.remove "pie" supportedHardeningFlags;
112117 enabledHardeningOptions =