[Git][ghc/ghc][wip/ghc-toolchain-fixes] 3 commits: configure: MergeObjsCmd - distinguish between empty string and unset variable

Matthew Pickering (@mpickering) gitlab at gitlab.haskell.org
Tue Aug 8 10:13:58 UTC 2023



Matthew Pickering pushed to branch wip/ghc-toolchain-fixes at Glasgow Haskell Compiler / GHC


Commits:
8f4854fd by Matthew Pickering at 2023-08-07T16:29:05+01:00
configure: MergeObjsCmd - distinguish between empty string and unset variable

If `MergeObjsCmd` is explicitly set to the empty string then we should
assume that MergeObjs is just not supported.

This is especially important for windows where we set MergeObjsCmd to ""
in m4/fp_setup_windows_toolchain.m4.

- - - - -
d393c70d by Matthew Pickering at 2023-08-08T10:50:58+01:00
configure: Add proper check to see if object merging works

- - - - -
891ee449 by Matthew Pickering at 2023-08-08T11:08:44+01:00
ghc-toolchain: If MergeObjsCmd is not set, replace setting with Nothing

If the user explicitly chooses to not set a MergeObjsCmd then it is
correct to use Nothing for tgtMergeObjs field in the Target file.

- - - - -


3 changed files:

- hadrian/cfg/default.target.in
- m4/find_merge_objects.m4
- m4/prep_target_file.m4


Changes:

=====================================
hadrian/cfg/default.target.in
=====================================
@@ -34,6 +34,6 @@ Target
 
 , tgtRanlib = Just (Ranlib {ranlibProgram = Program {prgPath = "@RanlibCmd@", prgFlags = []}})
 , tgtNm = Nm {nmProgram = Program {prgPath = "@NmCmd@", prgFlags = []}}
-, tgtMergeObjs = Just (MergeObjs {mergeObjsProgram = Program {prgPath = "@MergeObjsCmd@", prgFlags = @MergeObjsArgsList@}, mergeObjsSupportsResponseFiles = @MergeObjsSupportsResponseFilesBool@})
+, tgtMergeObjs = @MergeObjsCmdMaybe@
 , tgtWindres = @WindresCmdMaybeProg@
 }


=====================================
m4/find_merge_objects.m4
=====================================
@@ -3,25 +3,59 @@
 # Find which linker to use to merge object files.
 #
 # See Note [Merging object files for GHCi] in GHC.Driver.Pipeline.
+
+
+AC_DEFUN([CHECK_MERGE_OBJECTS],[
+  AC_REQUIRE([FP_FIND_NM])
+  AC_MSG_NOTICE([Checking whether $MergeObjsCmd can merge objects])
+  echo 'int funA(int x) {return x;}' > conftesta.c
+  echo 'int funB(int x) {return x;}' > conftestb.c
+  $CC -c -o conftesta.o conftesta.c
+  $CC -c -o conftestb.o conftestb.c
+  $MergeObjsCmd $MergeObjsArgs conftesta.o conftestb.o -o conftestc.o || AC_MSG_ERROR([ $MergeObjsCmd could not merge objects ])
+
+  # Check the resulting object file has both functions.
+  $NM conftestc.o | grep funA > /dev/null 2>&1 || AC_MSG_ERROR([ $MergeObjsCmd could not merge objects ])
+  $NM conftestc.o | grep funB > /dev/null 2>&1 || AC_MSG_ERROR([ $MergeObjsCmd could not merge objects ])
+
+  rm -r conftest*.c conftest*.o
+])
+
 AC_DEFUN([FIND_MERGE_OBJECTS],[
     AC_REQUIRE([FIND_LD])
 
-    if test -z "$MergeObjsCmd"; then
+    if test -z ${MergeObjsCmd+x}; then
+        AC_MSG_NOTICE([Setting cmd])
         MergeObjsCmd="$(command -v $LD)"
     fi
-    if test -z "$MergeObjsArgs"; then
+    if test -z ${MergeObjsArgs+x}; then
         MergeObjsArgs="-r"
     fi
 
-    CHECK_FOR_GOLD_T22266($MergeObjsCmd)
-    if test "$result" = "1"; then
-        AC_MSG_NOTICE([$MergeObjsCmd is broken due to binutils 22266, looking for another linker...])
-        MergeObjsCmd=""
-        AC_CHECK_TARGET_TOOL([MergeObjsCmd], [ld])
-        CHECK_FOR_GOLD_T22266($MergeObjsCmd)
-        if test "$result" = "1"; then
-            AC_MSG_ERROR([Linker is affected by binutils 22266 but couldn't find another unaffected linker. Please set the MergeObjsCmd variable to a functional linker.])
-        fi
+
+    # If MergeObjsCmd="" then we assume that the user is explicitly telling us that
+    # they do not want to configure the MergeObjsCmd, this is particularly important for
+    # the bundled windows toolchain.
+    if test -z "$MergeObjsCmd"; then
+      AC_MSG_NOTICE([No command for merging objects as explicitly instructed by user])
+
+    else
+      # Check first that gold works
+      CHECK_FOR_GOLD_T22266($MergeObjsCmd)
+      if test "$result" = "1"; then
+          AC_MSG_NOTICE([$MergeObjsCmd is broken due to binutils 22266, looking for another linker...])
+          MergeObjsCmd=""
+          AC_CHECK_TARGET_TOOL([MergeObjsCmd], [ld])
+          CHECK_FOR_GOLD_T22266($MergeObjsCmd)
+          if test "$result" = "1"; then
+              AC_MSG_ERROR([Linker is affected by binutils 22266 but couldn't find another unaffected linker. Please set the MergeObjsCmd variable to a functional linker.])
+          fi
+
+      fi
+
+      # Now just check that merging objects works at all
+      CHECK_MERGE_OBJECTS()
+
     fi
 
     AC_SUBST([MergeObjsCmd])


=====================================
m4/prep_target_file.m4
=====================================
@@ -160,6 +160,14 @@ AC_DEFUN([PREP_TARGET_FILE],[
     PREP_LIST([CONF_CXX_OPTS_STAGE0])
     PREP_LIST([CONF_GCC_LINKER_OPTS_STAGE0])
 
+
+    if test -z "$MergeObjsCmd"; then
+      MergeObjsCmdMaybe=Nothing
+    else
+      MergeObjsCmdMaybe="Just (MergeObjs {mergeObjsProgram = Program {prgPath = \"$MergeObjsCmd\", prgFlags = $MergeObjsArgsList}, mergeObjsSupportsResponseFiles = $MergeObjsSupportsResponseFilesBool})"
+    fi
+    AC_SUBST([MergeObjsCmdMaybe])
+
     dnl PREP_ENDIANNESS
     case "$TargetWordBigEndian" in
         YES)



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/cb8a6b44ddf336d5e76916ce785d9b00b94893ca...891ee449ad6abe9757bfc76a5a8272ba718eef39

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/cb8a6b44ddf336d5e76916ce785d9b00b94893ca...891ee449ad6abe9757bfc76a5a8272ba718eef39
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/20230808/1a6539ea/attachment-0001.html>


More information about the ghc-commits mailing list