From 11db9385c39155441ee97d986d5284109a070102 Mon Sep 17 00:00:00 2001 From: Matthew Pickering Date: Wed, 5 Jan 2022 11:48:52 +0000 Subject: Add support for using mold linker If mold is on your path when configuring, now GHC will use the `-fuse-ld=mold` flag which very recent clang and in-future GCC 12 will support. Fixes #20871 --- compiler/GHC/Driver/Session.hs | 1 + compiler/GHC/SysTools/Info.hs | 3 +++ m4/find_ld.m4 | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs index b0b37a822c..3a6813e9a1 100644 --- a/compiler/GHC/Driver/Session.hs +++ b/compiler/GHC/Driver/Session.hs @@ -4840,6 +4840,7 @@ sccProfilingEnabled dflags = profileIsProfiling (targetProfile dflags) data LinkerInfo = GnuLD [Option] | GnuGold [Option] + | Mold [Option] | LlvmLLD [Option] | DarwinLD [Option] | SolarisLD [Option] diff --git a/compiler/GHC/SysTools/Info.hs b/compiler/GHC/SysTools/Info.hs index 83a76b9efb..8c2f62017d 100644 --- a/compiler/GHC/SysTools/Info.hs +++ b/compiler/GHC/SysTools/Info.hs @@ -97,6 +97,7 @@ https://gcc.gnu.org/onlinedocs/gcc-5.2.0/gcc.pdf : neededLinkArgs :: LinkerInfo -> [Option] neededLinkArgs (GnuLD o) = o neededLinkArgs (GnuGold o) = o +neededLinkArgs (Mold o) = o neededLinkArgs (LlvmLLD o) = o neededLinkArgs (DarwinLD o) = o neededLinkArgs (SolarisLD o) = o @@ -126,6 +127,8 @@ getLinkerInfo' logger dflags = do -- Try to grab the info from the process output. parseLinkerInfo stdo _stde _exitc + | any ("mold" `isPrefixOf`) stdo = + return (Mold [Option "-Wl,--no-as-needed"]) | any ("GNU ld" `isPrefixOf`) stdo = -- GNU ld specifically needs to use less memory. This especially -- hurts on small object files. #5240. diff --git a/m4/find_ld.m4 b/m4/find_ld.m4 index 3d4443be54..985ec24d4d 100644 --- a/m4/find_ld.m4 +++ b/m4/find_ld.m4 @@ -24,13 +24,15 @@ AC_DEFUN([FIND_LD],[ # Manually iterate over possible names since we want to ensure that, e.g., # if ld.lld is installed but gcc doesn't support -fuse-ld=lld, that we # then still try ld.gold and -fuse-ld=gold. - for possible_ld in ld.lld ld.gold ld; do + for possible_ld in mold ld.lld ld.gold ld; do TmpLd="" # In case the user set LD AC_CHECK_TARGET_TOOL([TmpLd], [$possible_ld]) if test "x$TmpLd" = "x"; then continue; fi out=`$TmpLd --version` case $out in + "mold"*) + FP_CC_LINKER_FLAG_TRY(mold, $2) ;; "GNU ld"*) FP_CC_LINKER_FLAG_TRY(bfd, $2) ;; "GNU gold"*) -- cgit v1.2.1