From 2cc754a7baa72659430ec961608f0fc1dbe128df Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Fri, 24 Dec 2021 10:00:23 +0200 Subject: [PATCH] cc-wrapper: Fortran: disable stackprotector hardening on darwin aarch64 --- pkgs/build-support/cc-wrapper/default.nix | 9 ++++++++- pkgs/build-support/cc-wrapper/fortran-hook.sh | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 3738f628b187..de2842ba4fb8 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -245,12 +245,19 @@ stdenv.mkDerivation { wrap ${targetPrefix}gdc $wrapper $ccPath/${targetPrefix}gdc '' - + optionalString cc.langFortran or false '' + + optionalString cc.langFortran or false ('' wrap ${targetPrefix}gfortran $wrapper $ccPath/${targetPrefix}gfortran ln -sv ${targetPrefix}gfortran $out/bin/${targetPrefix}g77 ln -sv ${targetPrefix}gfortran $out/bin/${targetPrefix}f77 export named_fc=${targetPrefix}gfortran '' + # Darwin aarch64 fortran compilations seem to fail otherwise, see: + # https://github.com/NixOS/nixpkgs/issues/140041 + + (if (stdenvNoCC.isDarwin && stdenvNoCC.isAarch64) then '' + export fortran_hardening="pic strictoverflow relro bindnow" + '' else '' + export fortran_hardening="pic strictoverflow relro bindnow stackprotector" + '')) + optionalString cc.langJava or false '' wrap ${targetPrefix}gcj $wrapper $ccPath/${targetPrefix}gcj diff --git a/pkgs/build-support/cc-wrapper/fortran-hook.sh b/pkgs/build-support/cc-wrapper/fortran-hook.sh index d72f314c01ce..59e493e1836d 100644 --- a/pkgs/build-support/cc-wrapper/fortran-hook.sh +++ b/pkgs/build-support/cc-wrapper/fortran-hook.sh @@ -5,7 +5,7 @@ export FC${role_post}=@named_fc@ # If unset, assume the default hardening flags. # These are different for fortran. -: ${NIX_HARDENING_ENABLE="stackprotector pic strictoverflow relro bindnow"} +: ${NIX_HARDENING_ENABLE="@fortran_hardening@"} export NIX_HARDENING_ENABLE unset -v role_post