From 4c75874560d114032e3d3ee0e6ffe9dd880a3859 Mon Sep 17 00:00:00 2001 From: sternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org> Date: Tue, 3 Aug 2021 13:25:59 +0200 Subject: [PATCH 1/2] binutils-unwrapped: expose if built with ld.gold MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ld.gold is “A new, faster, ELF only linker”. Thus we only should pass the configure flag --with-gold if our target platform will actually support gold (in which case binutil's configure script silently disables it). With this change, not only will configureFlags represent the actual configuration more closely, but we can also expose if the binutils derivation contains ld.gold via a passthru attr. Specifically this means that: nix-repl> pkgsCross.mingwW64.stdenv.cc.bintools.bintools.hasGold false The intended way to use this is to check `stdenv.cc.bintools.bintools or false` which returns accurate results regardless of the actual linker derivation. TODO: maybe also add hasGold to binutils wrapper as it also symlinks ld.gold in? --- pkgs/development/tools/misc/binutils/default.nix | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkgs/development/tools/misc/binutils/default.nix b/pkgs/development/tools/misc/binutils/default.nix index 7a06e290a966..0185677e0363 100644 --- a/pkgs/development/tools/misc/binutils/default.nix +++ b/pkgs/development/tools/misc/binutils/default.nix @@ -1,16 +1,24 @@ +let + execFormatIsELF = platform: platform.parsed.kernel.execFormat.name == "elf"; +in + { stdenv, lib, buildPackages , fetchFromGitHub, fetchurl, zlib, autoreconfHook, gettext # Enabling all targets increases output size to a multiple. , withAllTargets ? false, libbfd, libopcodes , enableShared ? !stdenv.hostPlatform.isStatic , noSysDirs -, gold ? true +, gold ? execFormatIsELF stdenv.targetPlatform , bison ? null , flex , texinfo , perl }: +# configure silently disables ld.gold if it's unsupported, +# so we need to make sure that intent matches result ourselves. +assert gold -> execFormatIsELF stdenv.targetPlatform; + # Note: this package is used for bootstrapping fetchurl, and thus # cannot use fetchpatch! All mutable patches (generated by GitHub or # cgit) that are needed here should be included directly in Nixpkgs as @@ -163,6 +171,7 @@ stdenv.mkDerivation { passthru = { inherit targetPrefix; + hasGold = gold; isGNU = true; }; From 0908812372ad7f983645530de1d32e1563adacd3 Mon Sep 17 00:00:00 2001 From: sternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org> Date: Tue, 3 Aug 2021 13:33:12 +0200 Subject: [PATCH 2/2] haskell.compiler.*: check bintools.hasGold before enabling ld.gold --- pkgs/development/compilers/ghc/8.10.4.nix | 3 ++- pkgs/development/compilers/ghc/8.8.4.nix | 3 ++- pkgs/development/compilers/ghc/9.0.1.nix | 3 ++- pkgs/development/compilers/ghc/head.nix | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pkgs/development/compilers/ghc/8.10.4.nix b/pkgs/development/compilers/ghc/8.10.4.nix index 07784c426479..b0fb726e9c6f 100644 --- a/pkgs/development/compilers/ghc/8.10.4.nix +++ b/pkgs/development/compilers/ghc/8.10.4.nix @@ -122,7 +122,8 @@ let # 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. - useLdGold = targetPlatform.linker == "gold" || (targetPlatform.linker == "bfd" && !targetPlatform.isMusl); + useLdGold = targetPlatform.linker == "gold" || + (targetPlatform.linker == "bfd" && (targetPackages.stdenv.cc.bintools.bintools.hasGold or false) && !targetPlatform.isMusl); runtimeDeps = [ targetPackages.stdenv.cc.bintools diff --git a/pkgs/development/compilers/ghc/8.8.4.nix b/pkgs/development/compilers/ghc/8.8.4.nix index bb2267c930de..74260af7d31c 100644 --- a/pkgs/development/compilers/ghc/8.8.4.nix +++ b/pkgs/development/compilers/ghc/8.8.4.nix @@ -131,7 +131,8 @@ let # 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. - useLdGold = targetPlatform.linker == "gold" || (targetPlatform.linker == "bfd" && !targetPlatform.isMusl); + useLdGold = targetPlatform.linker == "gold" || + (targetPlatform.linker == "bfd" && (targetPackages.stdenv.cc.bintools.bintools.hasGold or false) && !targetPlatform.isMusl); runtimeDeps = [ targetPackages.stdenv.cc.bintools diff --git a/pkgs/development/compilers/ghc/9.0.1.nix b/pkgs/development/compilers/ghc/9.0.1.nix index 30a7f7a4f40a..37e03ccd4c9e 100644 --- a/pkgs/development/compilers/ghc/9.0.1.nix +++ b/pkgs/development/compilers/ghc/9.0.1.nix @@ -123,7 +123,8 @@ let # 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. - useLdGold = targetPlatform.linker == "gold" || (targetPlatform.linker == "bfd" && !targetPlatform.isMusl); + useLdGold = targetPlatform.linker == "gold" || + (targetPlatform.linker == "bfd" && (targetPackages.stdenv.cc.bintools.bintools.hasGold or false) && !targetPlatform.isMusl); runtimeDeps = [ targetPackages.stdenv.cc.bintools diff --git a/pkgs/development/compilers/ghc/head.nix b/pkgs/development/compilers/ghc/head.nix index 2ea14b78cc4a..7c4c419d4a1d 100644 --- a/pkgs/development/compilers/ghc/head.nix +++ b/pkgs/development/compilers/ghc/head.nix @@ -133,7 +133,8 @@ let # 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. - useLdGold = targetPlatform.linker == "gold" || (targetPlatform.linker == "bfd" && !targetPlatform.isMusl); + useLdGold = targetPlatform.linker == "gold" || + (targetPlatform.linker == "bfd" && (targetPackages.stdenv.cc.bintools.bintools.hasGold or false) && !targetPlatform.isMusl); runtimeDeps = [ targetPackages.stdenv.cc.bintools