Skip to content

Commit 09f4a8e

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 9a3ae43 commit 09f4a8e

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
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
@@ -431,7 +431,8 @@ let
431431
nativeBuildInputs =
432432
[ghc buildPackages.removeReferencesTo]
433433
++ executableToolDepends
434-
++ (lib.optional stdenv.hostPlatform.isGhcjs buildPackages.nodejs);
434+
++ (lib.optional stdenv.hostPlatform.isGhcjs buildPackages.nodejs)
435+
++ (lib.optional (ghc.useLdLld or false) llvmPackages.bintools);
435436

436437
outputs = ["out"]
437438
++ (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: 17 additions & 4 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"
@@ -433,7 +440,10 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
433440
''
434441
# Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177
435442
+ ''
436-
export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString useLdGold ".gold"}"
443+
export LD="${if useLdLld then
444+
"${targetPackages.llvmPackages.bintools}/bin/${targetPackages.llvmPackages.bintools.targetPrefix}ld.lld"
445+
else
446+
"${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString useLdGold ".gold"}"}"
437447
export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as"
438448
export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar"
439449
export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm"
@@ -451,6 +461,8 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
451461
# set LD explicitly if we want gold even if we aren't cross compiling
452462
''
453463
export LD="${targetCC.bintools}/bin/ld.gold"
464+
'' + lib.optionalString (targetPlatform == hostPlatform && useLdLld) ''
465+
export LD="${llvmPackages.bintools}/bin/ld.lld"
454466
'' + lib.optionalString (targetPlatform.isWindows) ''
455467
export DllWrap="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}dllwrap"
456468
export Windres="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}windres"
@@ -517,7 +529,8 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
517529
nativeBuildInputs = [
518530
perl autoconf automake m4 python3 sphinx
519531
ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
520-
] ++ lib.optional (patches != []) autoreconfHook;
532+
] ++ lib.optional (patches != []) autoreconfHook
533+
++ lib.optional useLdLld llvmPackages.bintools;
521534

522535
# For building runtime libs
523536
depsBuildTarget = toolsForTarget;
@@ -668,7 +681,7 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
668681
'';
669682

670683
passthru = {
671-
inherit bootPkgs targetPrefix libDir llvmPackages enableShared useLLVM hadrian hadrianProject;
684+
inherit bootPkgs targetPrefix libDir llvmPackages enableShared useLLVM useLdLld hadrian hadrianProject;
672685

673686
# Our Cabal compiler name
674687
haskellCompilerName = "ghc-${version}";

0 commit comments

Comments
 (0)