[Git][ghc/ghc][wip/hadrian-windows-bindist-cross] Check for --target linker flag separately to C compiler

Matthew Pickering (@mpickering) gitlab at gitlab.haskell.org
Thu Aug 24 14:51:26 UTC 2023



Matthew Pickering pushed to branch wip/hadrian-windows-bindist-cross at Glasgow Haskell Compiler / GHC


Commits:
b976134c by Matthew Pickering at 2023-08-24T15:51:11+01:00
Check for --target linker flag separately to C compiler

There are situations where the C compiler doesn't accept `--target` but
when used as a linker it does (but doesn't do anything most likely)

In particular with old gcc toolchains, the C compiler doesn't support
--target but when used as a linker it does.

- - - - -


3 changed files:

- configure.ac
- m4/fp_cc_supports_target.m4
- + m4/fp_prog_cc_linker_target.m4


Changes:

=====================================
configure.ac
=====================================
@@ -493,6 +493,7 @@ FP_PROG_LD_IS_GNU
 FP_PROG_LD_NO_COMPACT_UNWIND
 FP_PROG_LD_FILELIST
 
+
 dnl ** Which nm to use?
 dnl --------------------------------------------------------------
 FP_FIND_NM
@@ -658,9 +659,12 @@ AC_SUBST(LlvmTarget)
 
 dnl ** See whether cc supports --target=<triple> and set
 dnl CONF_CC_OPTS_STAGE[012] accordingly.
-FP_CC_SUPPORTS_TARGET([$CC_STAGE0], [CONF_CC_OPTS_STAGE0], [CONF_CXX_OPTS_STAGE0], [CONF_GCC_LINKER_OPTS_STAGE0])
-FP_CC_SUPPORTS_TARGET([$CC], [CONF_CC_OPTS_STAGE1], [CONF_CXX_OPTS_STAGE1], [CONF_GCC_LINKER_OPTS_STAGE1])
-FP_CC_SUPPORTS_TARGET([$CC], [CONF_CC_OPTS_STAGE2], [CONF_CXX_OPTS_STAGE2], [CONF_GCC_LINKER_OPTS_STAGE2])
+FP_CC_SUPPORTS_TARGET([$CC_STAGE0], [CONF_CC_OPTS_STAGE0], [CONF_CXX_OPTS_STAGE0])
+FP_CC_SUPPORTS_TARGET([$CC], [CONF_CC_OPTS_STAGE1], [CONF_CXX_OPTS_STAGE1])
+FP_CC_SUPPORTS_TARGET([$CC], [CONF_CC_OPTS_STAGE2], [CONF_CXX_OPTS_STAGE2])
+
+FP_PROG_CC_LINKER_TARGET([CONF_CC_OPTS_STAGE1], [CONF_GCC_LINKER_OPTS_STAGE1])
+FP_PROG_CC_LINKER_TARGET([CONF_CC_OPTS_STAGE2], [CONF_GCC_LINKER_OPTS_STAGE2])
 
 dnl Pass -Qunused-arguments or otherwise GHC will have very noisy invocations of Clang
 dnl TODO: Do we need -Qunused-arguments in CXX and GCC linker too?


=====================================
m4/fp_cc_supports_target.m4
=====================================
@@ -10,7 +10,6 @@
 # $1 = CC
 # $2 = CC_OPTS variable
 # $3 = CXX_OPTS variable
-# $4 = GCC_LINK_OPTS variable
 AC_DEFUN([FP_CC_SUPPORTS_TARGET],
 [
    AC_REQUIRE([GHC_LLVM_TARGET_SET_VAR])
@@ -28,7 +27,6 @@ AC_DEFUN([FP_CC_SUPPORTS_TARGET],
    if test $CONF_CC_SUPPORTS_TARGET = YES ; then
        $2="--target=$LlvmTarget $$2"
        $3="--target=$LlvmTarget $$3"
-       $4="--target=$LlvmTarget $$4"
    fi
 ])
 


=====================================
m4/fp_prog_cc_linker_target.m4
=====================================
@@ -0,0 +1,23 @@
+# FP_PROG_CC_LINKER_TARGET
+# -------------------
+# Check to see if the C compiler used as a linker supports `--target`
+#
+# $1 - Variable which contains the options passed to the C compiler when compiling a C file
+# $2 - Variable which contains the options passed to the C compiler when used as
+#      a linker
+AC_DEFUN([FP_PROG_CC_LINKER_TARGET],
+[
+    AC_MSG_CHECKING([whether $CC used as a linker understands --target])
+    echo 'int foo() { return 0; }' > conftest1.c
+    echo 'int main() { return 0; }' > conftest2.c
+    "${CC}" $$1 -c conftest1.c || AC_MSG_ERROR([Failed to compile conftest1.c])
+    "${CC}" $$1 -c conftest2.c || AC_MSG_ERROR([Failed to compile conftest2.c])
+    if "$CC" $$2 --target=$LlvmTarget -o conftest conftest1.o conftest2.o;
+    then
+        $2="--target=$LlvmTarget $$2"
+        AC_MSG_RESULT([yes])
+    else
+        AC_MSG_RESULT([no])
+    fi
+    rm -rf conftest*
+])# FP_PROG_CC_LINKER_TARGET



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b976134c1cfb3383be2a51614ece56ecf07e48dd

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b976134c1cfb3383be2a51614ece56ecf07e48dd
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230824/9217a06e/attachment-0001.html>


More information about the ghc-commits mailing list