From 6daa4a5c045d40e6eae60a3b6e427e8700f1c07f Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Wed, 1 Dec 2021 10:48:36 +0100 Subject: [PATCH] haskell.compiler.*: use wrapped darwin bintools on aarch64 On aarch64-darwin we have additional wrappers for install_name_tool and strip to deal with codesigning requirements (e. g. updating the signature / checksum after changing a binary). These wrappers don't exist on x86_64-darwin which is why the unwrapped versions were used before, causing the kernel to kill (some) executables produced by GHC. --- pkgs/development/compilers/ghc/8.10.7.nix | 22 ++++++++++++++++++++-- pkgs/development/compilers/ghc/9.0.1.nix | 22 ++++++++++++++++++++-- pkgs/development/compilers/ghc/9.2.1.nix | 22 ++++++++++++++++++++-- pkgs/development/compilers/ghc/head.nix | 22 ++++++++++++++++++++-- 4 files changed, 80 insertions(+), 8 deletions(-) diff --git a/pkgs/development/compilers/ghc/8.10.7.nix b/pkgs/development/compilers/ghc/8.10.7.nix index 5be64bebcd4d..1b4dac4a9768 100644 --- a/pkgs/development/compilers/ghc/8.10.7.nix +++ b/pkgs/development/compilers/ghc/8.10.7.nix @@ -130,6 +130,24 @@ let targetCC = builtins.head toolsForTarget; + # Sometimes we have to dispatch between the bintools wrapper and the unwrapped + # derivation for certain tools depending on the platform. + bintoolsFor = { + # GHC needs install_name_tool on all darwin platforms. On aarch64-darwin it is + # part of the bintools wrapper (due to codesigning requirements), but not on + # x86_64-darwin. + install_name_tool = + if stdenv.targetPlatform.isAarch64 + then targetCC.bintools + else targetCC.bintools.bintools; + # Same goes for strip. + strip = + # TODO(@sternenseemann): also use wrapper if linker == "bfd" or "gold" + if stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin + then targetCC.bintools + else targetCC.bintools.bintools; + }; + # Use gold either following the default, or to avoid the BFD linker due to some bugs / perf issues. # But we cannot avoid BFD when using musl libc due to https://sourceware.org/bugzilla/show_bug.cgi?id=23856 # see #84670 and #49071 for more background. @@ -207,10 +225,10 @@ stdenv.mkDerivation (rec { export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm" export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib" export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf" - export STRIP="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}strip" + export STRIP="${bintoolsFor.strip}/bin/${bintoolsFor.strip.targetPrefix}strip" '' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") '' export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool" - export INSTALL_NAME_TOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}install_name_tool" + export INSTALL_NAME_TOOL="${bintoolsFor.install_name_tool}/bin/${bintoolsFor.install_name_tool.targetPrefix}install_name_tool" '' + lib.optionalString useLLVM '' export LLC="${lib.getBin llvmPackages.llvm}/bin/llc" export OPT="${lib.getBin llvmPackages.llvm}/bin/opt" diff --git a/pkgs/development/compilers/ghc/9.0.1.nix b/pkgs/development/compilers/ghc/9.0.1.nix index d377328692cb..cd4a8acebba0 100644 --- a/pkgs/development/compilers/ghc/9.0.1.nix +++ b/pkgs/development/compilers/ghc/9.0.1.nix @@ -125,6 +125,24 @@ let targetCC = builtins.head toolsForTarget; + # Sometimes we have to dispatch between the bintools wrapper and the unwrapped + # derivation for certain tools depending on the platform. + bintoolsFor = { + # GHC needs install_name_tool on all darwin platforms. On aarch64-darwin it is + # part of the bintools wrapper (due to codesigning requirements), but not on + # x86_64-darwin. + install_name_tool = + if stdenv.targetPlatform.isAarch64 + then targetCC.bintools + else targetCC.bintools.bintools; + # Same goes for strip. + strip = + # TODO(@sternenseemann): also use wrapper if linker == "bfd" or "gold" + if stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin + then targetCC.bintools + else targetCC.bintools.bintools; + }; + # Use gold either following the default, or to avoid the BFD linker due to some bugs / perf issues. # But we cannot avoid BFD when using musl libc due to https://sourceware.org/bugzilla/show_bug.cgi?id=23856 # see #84670 and #49071 for more background. @@ -173,10 +191,10 @@ stdenv.mkDerivation (rec { export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm" export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib" export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf" - export STRIP="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}strip" + export STRIP="${bintoolsFor.strip}/bin/${bintoolsFor.strip.targetPrefix}strip" '' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") '' export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool" - export INSTALL_NAME_TOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}install_name_tool" + export INSTALL_NAME_TOOL="${bintoolsFor.install_name_tool}/bin/${bintoolsFor.install_name_tool.targetPrefix}install_name_tool" '' + lib.optionalString useLLVM '' export LLC="${lib.getBin llvmPackages.llvm}/bin/llc" export OPT="${lib.getBin llvmPackages.llvm}/bin/opt" diff --git a/pkgs/development/compilers/ghc/9.2.1.nix b/pkgs/development/compilers/ghc/9.2.1.nix index 20062358db50..8361d4e939b7 100644 --- a/pkgs/development/compilers/ghc/9.2.1.nix +++ b/pkgs/development/compilers/ghc/9.2.1.nix @@ -126,6 +126,24 @@ let targetCC = builtins.head toolsForTarget; + # Sometimes we have to dispatch between the bintools wrapper and the unwrapped + # derivation for certain tools depending on the platform. + bintoolsFor = { + # GHC needs install_name_tool on all darwin platforms. On aarch64-darwin it is + # part of the bintools wrapper (due to codesigning requirements), but not on + # x86_64-darwin. + install_name_tool = + if stdenv.targetPlatform.isAarch64 + then targetCC.bintools + else targetCC.bintools.bintools; + # Same goes for strip. + strip = + # TODO(@sternenseemann): also use wrapper if linker == "bfd" or "gold" + if stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin + then targetCC.bintools + else targetCC.bintools.bintools; + }; + # Use gold either following the default, or to avoid the BFD linker due to some bugs / perf issues. # But we cannot avoid BFD when using musl libc due to https://sourceware.org/bugzilla/show_bug.cgi?id=23856 # see #84670 and #49071 for more background. @@ -173,10 +191,10 @@ stdenv.mkDerivation (rec { export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm" export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib" export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf" - export STRIP="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}strip" + export STRIP="${bintoolsFor.strip}/bin/${bintoolsFor.strip.targetPrefix}strip" '' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") '' export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool" - export INSTALL_NAME_TOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}install_name_tool" + export INSTALL_NAME_TOOL="${bintoolsFor.install_name_tool}/bin/${bintoolsFor.install_name_tool.targetPrefix}install_name_tool" '' + lib.optionalString useLLVM '' export LLC="${lib.getBin llvmPackages.llvm}/bin/llc" export OPT="${lib.getBin llvmPackages.llvm}/bin/opt" diff --git a/pkgs/development/compilers/ghc/head.nix b/pkgs/development/compilers/ghc/head.nix index 537b735b4a21..d88d4493bb64 100644 --- a/pkgs/development/compilers/ghc/head.nix +++ b/pkgs/development/compilers/ghc/head.nix @@ -139,6 +139,24 @@ let targetCC = builtins.head toolsForTarget; + # Sometimes we have to dispatch between the bintools wrapper and the unwrapped + # derivation for certain tools depending on the platform. + bintoolsFor = { + # GHC needs install_name_tool on all darwin platforms. On aarch64-darwin it is + # part of the bintools wrapper (due to codesigning requirements), but not on + # x86_64-darwin. + install_name_tool = + if stdenv.targetPlatform.isAarch64 + then targetCC.bintools + else targetCC.bintools.bintools; + # Same goes for strip. + strip = + # TODO(@sternenseemann): also use wrapper if linker == "bfd" or "gold" + if stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin + then targetCC.bintools + else targetCC.bintools.bintools; + }; + # Use gold either following the default, or to avoid the BFD linker due to some bugs / perf issues. # But we cannot avoid BFD when using musl libc due to https://sourceware.org/bugzilla/show_bug.cgi?id=23856 # see #84670 and #49071 for more background. @@ -187,10 +205,10 @@ stdenv.mkDerivation (rec { export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm" export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib" export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf" - export STRIP="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}strip" + export STRIP="${bintoolsFor.strip}/bin/${bintoolsFor.strip.targetPrefix}strip" '' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") '' export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool" - export INSTALL_NAME_TOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}install_name_tool" + export INSTALL_NAME_TOOL="${bintoolsFor.install_name_tool}/bin/${bintoolsFor.install_name_tool.targetPrefix}install_name_tool" '' + lib.optionalString useLLVM '' export LLC="${lib.getBin llvmPackages.llvm}/bin/llc" export OPT="${lib.getBin llvmPackages.llvm}/bin/opt"