Skip to content

Commit d199096

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 d199096

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
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: 12 additions & 2 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"
@@ -467,6 +474,8 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
467474
# set LD explicitly if we want gold even if we aren't cross compiling
468475
''
469476
export LD="${targetCC.bintools}/bin/ld.gold"
477+
'' + lib.optionalString useLdLld ''
478+
export LD="${llvmPackages.bintools}/bin/ld.lld"
470479
'' + lib.optionalString (targetPlatform.isWindows) ''
471480
export DllWrap="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}dllwrap"
472481
export Windres="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}windres"
@@ -533,6 +542,7 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
533542
nativeBuildInputs = [
534543
perl autoconf automake m4 python3 sphinx
535544
ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
545+
llvmPackages.bintools
536546
] ++ lib.optional (patches != []) autoreconfHook;
537547

538548
# For building runtime libs
@@ -684,7 +694,7 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
684694
'';
685695

686696
passthru = {
687-
inherit bootPkgs targetPrefix libDir llvmPackages enableShared enableTerminfo useLLVM hadrian hadrianProject;
697+
inherit bootPkgs targetPrefix libDir llvmPackages enableShared enableTerminfo useLLVM useLdLld hadrian hadrianProject;
688698

689699
# Our Cabal compiler name
690700
haskellCompilerName = "ghc-${version}";

0 commit comments

Comments
 (0)