Skip to content

Allow using GHC with ld.lld #2391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions builder/comp-builder.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, stdenv, buildPackages, pkgsBuildBuild, ghc, lib, gobject-introspection ? null, haskellLib, makeConfigFiles, haddockBuilder, ghcForComponent, hsPkgs, compiler, runCommand, libffi, gmp, windows, zlib, ncurses, nodejs, nonReinstallablePkgs }@defaults:
{ 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:
lib.makeOverridable (
let self =
{ componentId
Expand Down Expand Up @@ -430,7 +430,8 @@ let
nativeBuildInputs =
[ghc buildPackages.removeReferencesTo]
++ executableToolDepends
++ (lib.optional stdenv.hostPlatform.isGhcjs buildPackages.nodejs);
++ (lib.optional stdenv.hostPlatform.isGhcjs buildPackages.nodejs)
++ (lib.optional (ghc.useLdLld or false) llvmPackages.bintools);

outputs = ["out"]
++ (lib.optional keepConfigFiles "configFiles")
Expand Down
5 changes: 3 additions & 2 deletions builder/haddock-builder.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, buildPackages, lib, haskellLib, ghc, ghcForComponent, nonReinstallablePkgs, runCommand, writeText, writeScript, makeConfigFiles }:
{ stdenv, buildPackages, lib, haskellLib, ghc, ghcForComponent, nonReinstallablePkgs, runCommand, writeText, writeScript, makeConfigFiles, llvmPackages }:

{ componentId
, component
Expand Down Expand Up @@ -80,7 +80,8 @@ let

nativeBuildInputs =
[ ghc buildPackages.removeReferencesTo ]
++ componentDrv.executableToolDepends;
++ componentDrv.executableToolDepends
++ (lib.optional (ghc.useLdLld or false) llvmPackages.bintools);

configurePhase = ''
mkdir -p $configFiles
Expand Down
4 changes: 2 additions & 2 deletions builder/setup-builder.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, stdenv, lib, buildPackages, haskellLib, ghc, nonReinstallablePkgs, hsPkgs, makeSetupConfigFiles }@defaults:
{ pkgs, stdenv, lib, buildPackages, haskellLib, ghc, nonReinstallablePkgs, hsPkgs, makeSetupConfigFiles, llvmPackages }@defaults:

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

passthru = {
inherit (package) identifier;
Expand Down
21 changes: 17 additions & 4 deletions compiler/ghc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let self =
# don't use gold with with musl. Still seems to be
# affected by 22266.
&& !stdenv.targetPlatform.isMusl)

, useLdLld ? false
, ghc-version ? src-spec.version
, ghc-version-date ? null
, ghc-commit-id ? null
Expand All @@ -95,6 +95,8 @@ assert !(enableIntegerSimple || enableNativeBignum) -> gmp != null;
assert enableNativeBignum -> !enableIntegerSimple;
assert enableIntegerSimple -> !enableNativeBignum;

assert !(useLdGold && useLdLld);

let
src = src-spec.file or (fetchurl { inherit (src-spec) url sha256; });

Expand Down Expand Up @@ -212,6 +214,11 @@ let
"CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold"
"CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold"
"CONF_LD_LINKER_OPTS_STAGE2=-fuse-ld=gold" # See: <https://gitlab.haskell.org/ghc/ghc/-/issues/22550#note_466656>
] ++ lib.optionals useLdLld [
"LD=${llvmPackages.bintools}/bin/ld.lld"
"CFLAGS=-fuse-ld=lld"
"CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=lld"
"CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=lld"
] ++ lib.optionals enableDWARF [
"--enable-dwarf-unwind"
"--with-libdw-includes=${lib.getDev elfutils}/include"
Expand Down Expand Up @@ -449,7 +456,10 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
''
# Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177
+ ''
export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString useLdGold ".gold"}"
export LD="${if useLdLld then
"${targetPackages.llvmPackages.bintools}/bin/${targetPackages.llvmPackages.bintools.targetPrefix}ld.lld"
else
"${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString useLdGold ".gold"}"}"
export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as"
export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar"
export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm"
Expand All @@ -467,6 +477,8 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
# set LD explicitly if we want gold even if we aren't cross compiling
''
export LD="${targetCC.bintools}/bin/ld.gold"
'' + lib.optionalString (targetPlatform == hostPlatform && useLdLld) ''
export LD="${llvmPackages.bintools}/bin/ld.lld"
'' + lib.optionalString (targetPlatform.isWindows) ''
export DllWrap="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}dllwrap"
export Windres="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}windres"
Expand Down Expand Up @@ -533,7 +545,8 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
nativeBuildInputs = [
perl autoconf automake m4 python3 sphinx
ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
] ++ lib.optional (patches != []) autoreconfHook;
] ++ lib.optional (patches != []) autoreconfHook
++ lib.optional useLdLld llvmPackages.bintools;

# For building runtime libs
depsBuildTarget = toolsForTarget;
Expand Down Expand Up @@ -684,7 +697,7 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
'';

passthru = {
inherit bootPkgs targetPrefix libDir llvmPackages enableShared enableTerminfo useLLVM hadrian hadrianProject;
inherit bootPkgs targetPrefix libDir llvmPackages enableShared enableTerminfo useLLVM useLdLld hadrian hadrianProject;

# Our Cabal compiler name
haskellCompilerName = "ghc-${version}";
Expand Down
Loading