Skip to content

Commit e4187cd

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 e4187cd

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-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: 9 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
@@ -212,6 +212,11 @@ let
212212
"CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold"
213213
"CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold"
214214
"CONF_LD_LINKER_OPTS_STAGE2=-fuse-ld=gold" # See: <https://gitlab.haskell.org/ghc/ghc/-/issues/22550#note_466656>
215+
] ++ lib.optionals useLdLld [
216+
"LD=${llvmPackages.bintools}/bin/ld.lld"
217+
"CFLAGS=-fuse-ld=lld"
218+
"CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=lld"
219+
"CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=lld"
215220
] ++ lib.optionals enableDWARF [
216221
"--enable-dwarf-unwind"
217222
"--with-libdw-includes=${lib.getDev elfutils}/include"
@@ -449,7 +454,7 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
449454
''
450455
# Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177
451456
+ ''
452-
export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString useLdGold ".gold"}"
457+
# export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString useLdGold ".gold"}"
453458
export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as"
454459
export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar"
455460
export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm"
@@ -533,6 +538,7 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
533538
nativeBuildInputs = [
534539
perl autoconf automake m4 python3 sphinx
535540
ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
541+
llvmPackages.bintools
536542
] ++ lib.optional (patches != []) autoreconfHook;
537543

538544
# For building runtime libs
@@ -684,7 +690,7 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
684690
'';
685691

686692
passthru = {
687-
inherit bootPkgs targetPrefix libDir llvmPackages enableShared enableTerminfo useLLVM hadrian hadrianProject;
693+
inherit bootPkgs targetPrefix libDir llvmPackages enableShared enableTerminfo useLLVM useLdLld hadrian hadrianProject;
688694

689695
# Our Cabal compiler name
690696
haskellCompilerName = "ghc-${version}";

0 commit comments

Comments
 (0)