Skip to content

Commit bf7a53d

Browse files
committed
Allow using GHC with ld.lld
We need to add llvmPackages.bintools to the nativeBuildInputs of builders when using this and we need to configure GHC to use ld.lld.
1 parent cd9ddc0 commit bf7a53d

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

builder/comp-builder.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ pkgs, stdenv, buildPackages, pkgsBuildBuild, ghc, lib, gobject-introspection ? null, haskellLib, makeConfigFiles, haddockBuilder, ghcForComponent, hsPkgs, compiler, runCommand, libffi, gmp, windows, zlib, ncurses, nodejs, nonReinstallablePkgs }@defaults:
1+
{ pkgs, stdenv, buildPackages, pkgsBuildBuild, ghc, llvmPackages, lib, gobject-introspection ? null, haskellLib, makeConfigFiles, haddockBuilder, ghcForComponent, hsPkgs, compiler, runCommand, libffi, gmp, windows, zlib, ncurses, nodejs, nonReinstallablePkgs }@defaults:
22
lib.makeOverridable (
33
let self =
44
{ componentId
@@ -430,7 +430,8 @@ let
430430
nativeBuildInputs =
431431
[ghc buildPackages.removeReferencesTo]
432432
++ executableToolDepends
433-
++ (lib.optional stdenv.hostPlatform.isGhcjs buildPackages.nodejs);
433+
++ (lib.optional stdenv.hostPlatform.isGhcjs buildPackages.nodejs)
434+
++ (lib.optional (ghc.useLdLld or false) llvmPackages.bintools);
434435

435436
outputs = ["out"]
436437
++ (lib.optional keepConfigFiles "configFiles")

builder/haddock-builder.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ stdenv, buildPackages, lib, haskellLib, ghc, ghcForComponent, nonReinstallablePkgs, runCommand, writeText, writeScript, makeConfigFiles }:
1+
{ stdenv, buildPackages, lib, haskellLib, ghc, ghcForComponent, nonReinstallablePkgs, runCommand, writeText, writeScript, makeConfigFiles, llvmPackages }:
22

33
{ componentId
44
, component
@@ -80,7 +80,8 @@ let
8080

8181
nativeBuildInputs =
8282
[ ghc buildPackages.removeReferencesTo ]
83-
++ componentDrv.executableToolDepends;
83+
++ componentDrv.executableToolDepends
84+
++ (lib.optional (ghc.useLdLld or false) llvmPackages.bintools);
8485

8586
configurePhase = ''
8687
mkdir -p $configFiles

builder/setup-builder.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ pkgs, stdenv, lib, buildPackages, haskellLib, ghc, nonReinstallablePkgs, hsPkgs, makeSetupConfigFiles }@defaults:
1+
{ pkgs, stdenv, lib, buildPackages, haskellLib, ghc, nonReinstallablePkgs, hsPkgs, makeSetupConfigFiles, llvmPackages }@defaults:
22

33
let self =
44
{ component, package, name, src, enableDWARF ? false, flags ? {}, revision ? null, patches ? [], defaultSetupSrc
@@ -67,7 +67,7 @@ let
6767
++ builtins.concatLists component.pkgconfig
6868
++ configFiles.libDeps
6969
++ [ghc]; # Needs to be a build input so that the boot libraries are included
70-
nativeBuildInputs = [ghc] ++ executableToolDepends;
70+
nativeBuildInputs = [ghc] ++ executableToolDepends ++ (lib.optional (ghc.useLdLld or false) llvmPackages.bintools);
7171

7272
passthru = {
7373
inherit (package) identifier;

compiler/ghc/default.nix

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
9595
assert enableNativeBignum -> !enableIntegerSimple;
9696
assert enableIntegerSimple -> !enableNativeBignum;
9797

98+
assert !(useLdGold && useLdLld);
99+
98100
let
99101
src = src-spec.file or (fetchurl { inherit (src-spec) url sha256; });
100102

@@ -212,6 +214,11 @@ let
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,6 +545,7 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
533545
nativeBuildInputs = [
534546
perl autoconf automake m4 python3 sphinx
535547
ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
548+
llvmPackages.bintools
536549
] ++ lib.optional (patches != []) autoreconfHook;
537550

538551
# For building runtime libs
@@ -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

Comments
 (0)