@@ -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
244246 "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold"
245247 "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold"
246248 "CONF_LD_LINKER_OPTS_STAGE2=-fuse-ld=gold" # See: <https://gitlab.haskell.org/ghc/ghc/-/issues/22550#note_466656>
249+ ] ++ lib . optionals useLdLld [
250+ "LD=${ llvmPackages . bintools } /bin/ld.lld"
251+ "CFLAGS=-fuse-ld=lld"
252+ "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=lld"
253+ "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=lld"
247254 ] ++ lib . optionals enableDWARF [
248255 "--enable-dwarf-unwind"
249256 "--with-libdw-includes=${ lib . getDev elfutils } /include"
@@ -504,7 +511,10 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
504511 ''
505512 # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177
506513 + ''
507- export LD="${ targetCC . bintools } /bin/${ targetCC . bintools . targetPrefix } ld${ lib . optionalString useLdGold ".gold" } "
514+ export LD="${ if useLdLld then
515+ "${ targetPackages . llvmPackages . bintools } /bin/${ targetPackages . llvmPackages . bintools . targetPrefix } ld.lld"
516+ else
517+ "${ targetCC . bintools } /bin/${ targetCC . bintools . targetPrefix } ld${ lib . optionalString useLdGold ".gold" } " } "
508518 export AS="${ targetCC . bintools . bintools } /bin/${ targetCC . bintools . targetPrefix } as"
509519 export AR="${ targetCC . bintools . bintools } /bin/${ targetCC . bintools . targetPrefix } ar"
510520 export NM="${ targetCC . bintools . bintools } /bin/${ targetCC . bintools . targetPrefix } nm"
@@ -522,6 +532,8 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
522532 # set LD explicitly if we want gold even if we aren't cross compiling
523533 ''
524534 export LD="${ targetCC . bintools } /bin/ld.gold"
535+ '' + lib . optionalString ( targetPlatform == hostPlatform && useLdLld ) ''
536+ export LD="${ llvmPackages . bintools } /bin/ld.lld"
525537 '' + lib . optionalString ( targetPlatform . isWindows ) ''
526538 export DllWrap="${ targetCC . bintools . bintools } /bin/${ targetCC . bintools . targetPrefix } dllwrap"
527539 export Windres="${ targetCC . bintools . bintools } /bin/${ targetCC . bintools . targetPrefix } windres"
@@ -588,7 +600,8 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
588600 nativeBuildInputs = [
589601 perl autoconf automake m4 python3 sphinx
590602 ghc bootPkgs . alex bootPkgs . happy bootPkgs . hscolour
591- ] ++ lib . optional ( patches != [ ] ) autoreconfHook ;
603+ ] ++ lib . optional ( patches != [ ] ) autoreconfHook
604+ ++ lib . optional useLdLld llvmPackages . bintools ;
592605
593606 # For building runtime libs
594607 depsBuildTarget = toolsForTarget ;
@@ -739,7 +752,7 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
739752 '' ;
740753
741754 passthru = {
742- inherit bootPkgs targetPrefix libDir llvmPackages enableShared enableTerminfo useLLVM hadrian hadrianProject ;
755+ inherit bootPkgs targetPrefix libDir llvmPackages enableShared enableTerminfo useLLVM useLdLld hadrian hadrianProject ;
743756
744757 # Our Cabal compiler name
745758 haskellCompilerName = "ghc-${ version } " ;
0 commit comments