summaryrefslogtreecommitdiff
path: root/m4/find_ld.m4
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2021-04-02 11:52:47 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-05-05 05:42:38 -0400
commit7ffbdc3fa603c6411249ba9b758cf8f109c5fb30 (patch)
tree8a05d6e03ce2790e6e59651c824e569fee088d33 /m4/find_ld.m4
parent6acadb79afe685c635fd255f90551a0fbfcbe3dc (diff)
downloadhaskell-7ffbdc3fa603c6411249ba9b758cf8f109c5fb30.tar.gz
Break up aclocal.m4
Diffstat (limited to 'm4/find_ld.m4')
-rw-r--r--m4/find_ld.m470
1 files changed, 70 insertions, 0 deletions
diff --git a/m4/find_ld.m4 b/m4/find_ld.m4
new file mode 100644
index 0000000000..a6b5c9c598
--- /dev/null
+++ b/m4/find_ld.m4
@@ -0,0 +1,70 @@
+# FIND_LD
+# ---------
+# Find the version of `ld` to use and figure out how to get gcc to use it for
+# linking (if --enable-ld-override is enabled). This is used in both in the top
+# level configure.ac and in distrib/configure.ac.in.
+#
+# $1 = the platform
+# $2 = the variable to set with GHC options to configure gcc to use the chosen linker
+#
+AC_DEFUN([FIND_LD],[
+ AC_ARG_ENABLE(ld-override,
+ [AS_HELP_STRING([--disable-ld-override],
+ [Prevent GHC from overriding the default linker used by gcc. If ld-override is enabled GHC will try to tell gcc to use whichever linker is selected by the LD environment variable. [default=override enabled]])],
+ [],
+ [enable_ld_override=yes])
+
+ find_ld() {
+ # Make sure the user didn't specify LD manually.
+ if test "z$LD" != "z"; then
+ AC_CHECK_TARGET_TOOL([LD], [ld])
+ return
+ fi
+
+ # 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
+ 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
+ "GNU ld"*)
+ FP_CC_LINKER_FLAG_TRY(bfd, $2) ;;
+ "GNU gold"*)
+ FP_CC_LINKER_FLAG_TRY(gold, $2)
+ if test "$cross_compiling" = "yes"; then
+ AC_MSG_NOTICE([Using ld.gold and assuming that it is not affected by binutils issue 22266]);
+ fi
+ ;;
+ "LLD"*)
+ FP_CC_LINKER_FLAG_TRY(lld, $2) ;;
+ *) AC_MSG_NOTICE([unknown linker version $out]) ;;
+ esac
+ if test "z$$2" = "z"; then
+ AC_MSG_NOTICE([unable to convince '$CC' to use linker '$TmpLd'])
+ # a terrible hack to prevent autoconf from caching the previous
+ # AC_CHECK_TARGET_TOOL result since next time we'll be looking
+ # for another ld variant.
+ $as_unset ac_cv_prog_ac_ct_TmpLd
+ else
+ LD="$TmpLd"
+ return
+ fi
+ done
+
+ # Fallback
+ AC_CHECK_TARGET_TOOL([LD], [ld])
+ }
+
+ if test "x$enable_ld_override" = "xyes"; then
+ find_ld
+ else
+ AC_CHECK_TARGET_TOOL([LD], [ld])
+ fi
+
+ CHECK_LD_COPY_BUG([$1])
+])
+