summaryrefslogtreecommitdiff
path: root/aclocal.m4
diff options
context:
space:
mode:
authorBen Gamari <bgamari.foss@gmail.com>2017-06-29 19:38:51 -0400
committerBen Gamari <ben@smart-cactus.org>2017-06-29 19:38:52 -0400
commit625143f473b58d770d2515b91c2566b52d35a4c3 (patch)
tree5da1910c86956cb4ae6ea8534d0867bfeae134e3 /aclocal.m4
parent007f255644f885d445e47e291e50eb12b5ecd08d (diff)
downloadhaskell-625143f473b58d770d2515b91c2566b52d35a4c3.tar.gz
configure: Coerce gcc to use $LD instead of system default
The configure script will now try to coerce gcc to use the linker pointed to by $LD instead of the system default (typically bfd ld). Moreover, we now check for `ld.gold` and `ld.lld` before trying `ld`. The previous behavior can be reverted to by using the new --disable-ld-override flag. On my machine gold seems to trigger an apparent infelicity in constructor behavior, causing T5435_asm to fail. I've opened #13883 to record this issue and have accepted the questionable constructor ordering for the time being. Test Plan: Validate with `config_args='--enable-ld-override'` Reviewers: austin, hvr, simonmar Subscribers: duog, nh2, rwbarton, thomie, erikd, snowleopard GHC Trac Issues: #13541, #13810, #13883 Differential Revision: https://phabricator.haskell.org/D3449
Diffstat (limited to 'aclocal.m4')
-rw-r--r--aclocal.m4106
1 files changed, 60 insertions, 46 deletions
diff --git a/aclocal.m4 b/aclocal.m4
index b94f70bada..677c0e77bc 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -590,7 +590,7 @@ AC_DEFUN([FP_SET_CFLAGS_C99],
# FPTOOLS_SET_C_LD_FLAGS
# ----------------------------------
-# Set the C, LD and CPP flags for a given platform
+# Set the C, LD and CPP flags for a given platform.
# $1 is the platform
# $2 is the name of the CC flags variable
# $3 is the name of the linker flags variable when linking with gcc
@@ -598,7 +598,6 @@ AC_DEFUN([FP_SET_CFLAGS_C99],
# $5 is the name of the CPP flags variable
AC_DEFUN([FPTOOLS_SET_C_LD_FLAGS],
[
- FIND_LD([$$1],[UseLd])
AC_MSG_CHECKING([Setting up $2, $3, $4 and $5])
case $$1 in
i386-*)
@@ -665,15 +664,6 @@ AC_DEFUN([FPTOOLS_SET_C_LD_FLAGS],
esac
- case $UseLd in
- *ld.gold)
- $3="$$3 -fuse-ld=gold"
- ;;
- *ld.bfd)
- $3="$$3 -fuse-ld=bfd"
- ;;
- esac
-
# If gcc knows about the stack protector, turn it off.
# Otherwise the stack-smash handler gets triggered.
echo 'int main(void) {return 0;}' > conftest.c
@@ -2015,41 +2005,6 @@ AC_DEFUN([FIND_LLVM_PROG],[
fi
])
-# FIND_LD
-# ---------
-# Find the version of `ld` to use. 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
-#
-AC_DEFUN([FIND_LD],[
- AC_CHECK_TARGET_TOOL([LD], [ld])
- case $1 in
- arm*linux* | \
- aarch64*linux* )
- # Arm and Aarch64 requires use of the binutils ld.gold linker.
- # This case should catch at least arm-unknown-linux-gnueabihf,
- # arm-linux-androideabi, arm64-unknown-linux and
- # aarch64-linux-android
- AC_CHECK_TARGET_TOOL([LD_GOLD], [ld.gold])
- if test "$LD_GOLD" != ""; then
- $2="$LD_GOLD"
- elif test `$LD --version | grep -c "GNU gold"` -gt 0; then
- AC_MSG_NOTICE([ld is ld.gold])
- $2="$LD"
- else
- AC_MSG_WARN([could not find ld.gold, falling back to $LD])
- $2="$LD"
- fi
- ;;
- *)
- $2="$LD"
- ;;
- esac
- CHECK_LD_COPY_BUG($1)
-])
-
# CHECK_LD_COPY_BUG()
# -------------------
# Check for binutils bug #16177 present in some versions of the bfd ld
@@ -2284,4 +2239,63 @@ AC_DEFUN([FP_BFD_SUPPORT], [
)
])
+
+# FP_CC_LINKER_FLAG_TRY()
+# --------------------
+# Try a particular linker to see whether we can use it. In particular, determine
+# whether we can convince gcc to use it via a -fuse-ld=... flag.
+#
+# $1 = the name of the linker to try
+# $2 = the variable to set with the appropriate GHC flag if the linker is
+# found to be usable
+AC_DEFUN([FP_CC_LINKER_FLAG_TRY], [
+ AC_MSG_CHECKING([whether C compiler supports -fuse-ld=$1])
+ echo 'int main(void) {return 0;}' > conftest.c
+ if $CC -o conftest.o -fuse-ld=$1 conftest.c > /dev/null 2>&1
+ then
+ $2="-fuse-ld=$1"
+ AC_MSG_RESULT([yes])
+ else
+ AC_MSG_RESULT([no])
+ fi
+ rm -f conftest.c conftest.o
+])
+
+# 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,
+ [AC_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])
+
+ if test "x$enable_ld_override" = "xyes"; then
+ AC_CHECK_TARGET_TOOLS([LD], [ld.gold ld.lld ld])
+ UseLd=''
+
+ out=`$LD --version`
+ case $out in
+ "GNU ld"*) FP_CC_LINKER_FLAG_TRY(bfd, $2) ;;
+ "GNU gold"*) FP_CC_LINKER_FLAG_TRY(gold, $2) ;;
+ "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 '$LD'])
+ fi
+ else
+ AC_CHECK_TARGET_TOOL([LD], [ld])
+ fi
+
+ CHECK_LD_COPY_BUG([$1])
+])
+
# LocalWords: fi