@@ -76,7 +76,7 @@ let self =
7676 # don't use gold with with musl. Still seems to be
7777 # affected by 22266.
7878 && ! stdenv . targetPlatform . isMusl )
79-
79+ , useLdLld ? false
8080, ghc-version ? src-spec . version
8181, ghc-version-date ? null
8282, ghc-commit-id ? null
@@ -95,6 +95,8 @@ assert !(enableIntegerSimple || enableNativeBignum) -> gmp != null;
9595assert enableNativeBignum -> ! enableIntegerSimple ;
9696assert enableIntegerSimple -> ! enableNativeBignum ;
9797
98+ assert ! ( useLdGold && useLdLld ) ;
99+
98100let
99101 src = src-spec . file or ( fetchurl { inherit ( src-spec ) url sha256 ; } ) ;
100102
212214 "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold"
213215 "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold"
214216 "CONF_LD_LINKER_OPTS_STAGE2=-fuse-ld=gold" # See: <https://gitlab.haskell.org/ghc/ghc/-/issues/22550#note_466656>
217+ ] ++ lib . optionals useLdLld [
218+ "LD=${ llvmPackages . bintools } /bin/ld.lld"
219+ "CFLAGS=-fuse-ld=lld"
220+ "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=lld"
221+ "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=lld"
215222 ] ++ lib . optionals enableDWARF [
216223 "--enable-dwarf-unwind"
217224 "--with-libdw-includes=${ lib . getDev elfutils } /include"
@@ -449,7 +456,10 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
449456 ''
450457 # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177
451458 + ''
452- export LD="${ targetCC . bintools } /bin/${ targetCC . bintools . targetPrefix } ld${ lib . optionalString useLdGold ".gold" } "
459+ export LD="${ if useLdLld then
460+ "${ targetPackages . llvmPackages . bintools } /bin/${ targetPackages . llvmPackages . bintools . targetPrefix } ld.lld"
461+ else
462+ "${ targetCC . bintools } /bin/${ targetCC . bintools . targetPrefix } ld${ lib . optionalString useLdGold ".gold" } " } "
453463 export AS="${ targetCC . bintools . bintools } /bin/${ targetCC . bintools . targetPrefix } as"
454464 export AR="${ targetCC . bintools . bintools } /bin/${ targetCC . bintools . targetPrefix } ar"
455465 export NM="${ targetCC . bintools . bintools } /bin/${ targetCC . bintools . targetPrefix } nm"
@@ -467,6 +477,8 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
467477 # set LD explicitly if we want gold even if we aren't cross compiling
468478 ''
469479 export LD="${ targetCC . bintools } /bin/ld.gold"
480+ '' + lib . optionalString ( targetPlatform == hostPlatform && useLdLld ) ''
481+ export LD="${ llvmPackages . bintools } /bin/ld.lld"
470482 '' + lib . optionalString ( targetPlatform . isWindows ) ''
471483 export DllWrap="${ targetCC . bintools . bintools } /bin/${ targetCC . bintools . targetPrefix } dllwrap"
472484 export Windres="${ targetCC . bintools . bintools } /bin/${ targetCC . bintools . targetPrefix } windres"
@@ -533,7 +545,8 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
533545 nativeBuildInputs = [
534546 perl autoconf automake m4 python3 sphinx
535547 ghc bootPkgs . alex bootPkgs . happy bootPkgs . hscolour
536- ] ++ lib . optional ( patches != [ ] ) autoreconfHook ;
548+ ] ++ lib . optional ( patches != [ ] ) autoreconfHook
549+ ++ lib . optional useLdLld llvmPackages . bintools ;
537550
538551 # For building runtime libs
539552 depsBuildTarget = toolsForTarget ;
@@ -684,7 +697,7 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
684697 '' ;
685698
686699 passthru = {
687- inherit bootPkgs targetPrefix libDir llvmPackages enableShared enableTerminfo useLLVM hadrian hadrianProject ;
700+ inherit bootPkgs targetPrefix libDir llvmPackages enableShared enableTerminfo useLLVM useLdLld hadrian hadrianProject ;
688701
689702 # Our Cabal compiler name
690703 haskellCompilerName = "ghc-${ version } " ;
0 commit comments