summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2022-01-05 11:48:52 +0000
committerMatthew Pickering <matthewtpickering@gmail.com>2022-01-10 16:20:19 +0000
commit11db9385c39155441ee97d986d5284109a070102 (patch)
tree8efc4eca1d6b1829ecae4b9ecc5c4d001239f0ab
parent7dc805ead3540075433c381ca43ccc4ffc91ee60 (diff)
downloadhaskell-wip/generalise-linker.tar.gz
Add support for using mold linkerwip/generalise-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
-rw-r--r--compiler/GHC/Driver/Session.hs1
-rw-r--r--compiler/GHC/SysTools/Info.hs3
-rw-r--r--m4/find_ld.m44
3 files changed, 7 insertions, 1 deletions
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"*)