[Git][ghc/ghc][wip/backports-9.8] 4 commits: Suppress duplicate librares linker warning of new macOS linker

Zubin (@wz1000) gitlab at gitlab.haskell.org
Fri Feb 9 10:35:41 UTC 2024



Zubin pushed to branch wip/backports-9.8 at Glasgow Haskell Compiler / GHC


Commits:
55bbea03 by Rodrigo Mesquita at 2024-02-09T16:01:30+05:30
Suppress duplicate librares linker warning of new macOS linker

Fixes #24167

XCode 15 introduced a new linker which warns on duplicate libraries being
linked. To disable this warning, we pass -Wl,-no_warn_duplicate_libraries as
suggested by Brad King in CMake issue #25297.

This flag isn't necessarily available to other linkers on darwin, so we must
only configure it into the CC linker arguments if valid.

(cherry picked from commit e98051a5e7251390799f9fdead988c61d72e82e3)

- - - - -
74d6260a by Rodrigo Mesquita at 2024-02-09T16:02:03+05:30
testsuite: Encoding test witnesses recent iconv bug is fragile

A regression in the new iconv() distributed with XCode 15 and MacOS
Sonoma causes the test 'encoding004' to fail in the CP936 roundrip.

We mark this test as fragile until this is fixed upstream (rather than
broken, since previous versions of iconv pass the test)

See #24161

(cherry picked from commit c411c431e7ae1f0effbe9f9a624c7f9171d50f0a)

- - - - -
0f6116ca by Rodrigo Mesquita at 2024-02-09T16:02:12+05:30
testsuite: Update to LC_ALL=C no longer being ignored in darwin

MacOS seems to have fixed an issue where it used to ignore the variable
`LC_ALL` in program invocations and default to using Unicode.

Since the behaviour seems to be fixed to account for the locale
variable, we mark tests that were previously broken in spite of it as
fragile (since they now pass in recent macOS distributions)

See #24161

(cherry picked from commit ce7fe5a916d50f471812f4714615e13f557fe57a)

- - - - -
b746f8a8 by Rodrigo Mesquita at 2024-02-09T16:05:28+05:30
darwin: Fix single_module is obsolete warning

In XCode 15's linker, -single_module is the default and otherwise
passing it as a flag results in a warning being raised:

    ld: warning: -single_module is obsolete

This patch fixes this warning by, at configure time, determining whether
the linker supports -single_module (which is likely false for all
non-darwin linkers, and true for darwin linkers in previous versions of
macOS), and using that information at runtime to decide to pass or not
the flag in the invocation.

Fixes #24168

(cherry picked from commit e6c803f702e8b09dfd0073b973b8afcd7071db50)
(cherry picked from commit 273f5a3fd392d528664d5661508cc0094e37ec0d)

- - - - -


14 changed files:

- compiler/GHC/Linker/Dynamic.hs
- compiler/GHC/Settings.hs
- compiler/GHC/Settings/IO.hs
- configure.ac
- distrib/configure.ac.in
- hadrian/bindist/Makefile
- hadrian/bindist/config.mk.in
- hadrian/cfg/system.config.in
- hadrian/src/Rules/Generate.hs
- libraries/base/tests/IO/all.T
- + m4/fp_ld_no_warn_duplicate_libraries.m4
- + m4/fp_prog_ld_single_module.m4
- testsuite/tests/driver/Makefile
- testsuite/tests/driver/all.T


Changes:

=====================================
compiler/GHC/Linker/Dynamic.hs
=====================================
@@ -11,6 +11,7 @@ where
 import GHC.Prelude
 import GHC.Platform
 import GHC.Platform.Ways
+import GHC.Settings (ToolSettings(toolSettings_ldSupportsSingleModule))
 
 import GHC.Driver.Config.Linker
 import GHC.Driver.Session
@@ -150,6 +151,9 @@ linkDynLib logger tmpfs dflags0 unit_env o_files dep_packages
             --   dynamic binding nonsense when referring to symbols from
             --   within the library. The NCG assumes that this option is
             --   specified (on i386, at least).
+            --   In XCode 15, -single_module is the default and passing the
+            --   flag is now obsolete and raises a warning (#24168). We encode
+            --   this information into the toolchain field ...SupportsSingleModule.
             -- -install_name
             --   Mac OS/X stores the path where a dynamic library is (to
             --   be) installed in the library itself.  It's called the
@@ -175,8 +179,11 @@ linkDynLib logger tmpfs dflags0 unit_env o_files dep_packages
                     ]
                  ++ map Option o_files
                  ++ [ Option "-undefined",
-                      Option "dynamic_lookup",
-                      Option "-single_module" ]
+                      Option "dynamic_lookup"
+                    ]
+                 ++ (if toolSettings_ldSupportsSingleModule (toolSettings dflags)
+                        then [ Option "-single_module" ]
+                        else [ ])
                  ++ (if platformArch platform `elem` [ ArchX86_64, ArchAArch64 ]
                      then [ ]
                      else [ Option "-Wl,-read_only_relocs,suppress" ])


=====================================
compiler/GHC/Settings.hs
=====================================
@@ -89,6 +89,7 @@ data ToolSettings = ToolSettings
   { toolSettings_ldSupportsCompactUnwind :: Bool
   , toolSettings_ldSupportsFilelist      :: Bool
   , toolSettings_ldSupportsResponseFiles :: Bool
+  , toolSettings_ldSupportsSingleModule  :: Bool
   , toolSettings_ldIsGnuLd               :: Bool
   , toolSettings_ccSupportsNoPie         :: Bool
   , toolSettings_useInplaceMinGW         :: Bool


=====================================
compiler/GHC/Settings/IO.hs
=====================================
@@ -105,6 +105,7 @@ initSettings top_dir = do
   ldSupportsCompactUnwind <- getBooleanSetting "ld supports compact unwind"
   ldSupportsFilelist      <- getBooleanSetting "ld supports filelist"
   ldSupportsResponseFiles <- getBooleanSetting "ld supports response files"
+  ldSupportsSingleModule  <- getBooleanSetting "ld supports single module"
   ldIsGnuLd               <- getBooleanSetting "ld is GNU ld"
   arSupportsDashL         <- getBooleanSetting "ar supports -L"
 
@@ -174,6 +175,7 @@ initSettings top_dir = do
       { toolSettings_ldSupportsCompactUnwind = ldSupportsCompactUnwind
       , toolSettings_ldSupportsFilelist      = ldSupportsFilelist
       , toolSettings_ldSupportsResponseFiles = ldSupportsResponseFiles
+      , toolSettings_ldSupportsSingleModule  = ldSupportsSingleModule
       , toolSettings_ldIsGnuLd               = ldIsGnuLd
       , toolSettings_ccSupportsNoPie         = gccSupportsNoPie
       , toolSettings_useInplaceMinGW         = useInplaceMinGW


=====================================
configure.ac
=====================================
@@ -493,6 +493,7 @@ AC_SUBST([LdCmd])
 FP_PROG_LD_IS_GNU
 FP_PROG_LD_NO_COMPACT_UNWIND
 FP_PROG_LD_FILELIST
+FP_PROG_LD_SINGLE_MODULE
 
 dnl ** Which nm to use?
 dnl --------------------------------------------------------------
@@ -650,11 +651,18 @@ FPTOOLS_SET_C_LD_FLAGS([target],[CONF_CC_OPTS_STAGE1],[CONF_GCC_LINKER_OPTS_STAG
 FPTOOLS_SET_C_LD_FLAGS([target],[CONF_CC_OPTS_STAGE2],[CONF_GCC_LINKER_OPTS_STAGE2],[CONF_LD_LINKER_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2])
 # Stage 3 won't be supported by cross-compilation
 
+#-no_fixup_chains
 FP_LD_NO_FIXUP_CHAINS([target], [LDFLAGS])
 FP_LD_NO_FIXUP_CHAINS([build], [CONF_GCC_LINKER_OPTS_STAGE0])
 FP_LD_NO_FIXUP_CHAINS([target], [CONF_GCC_LINKER_OPTS_STAGE1])
 FP_LD_NO_FIXUP_CHAINS([target], [CONF_GCC_LINKER_OPTS_STAGE2])
 
+
+#-no_warn_duplicate_libraries
+FP_LD_NO_WARN_DUPLICATE_LIBRARIES([build], [CONF_GCC_LINKER_OPTS_STAGE0])
+FP_LD_NO_WARN_DUPLICATE_LIBRARIES([target], [CONF_GCC_LINKER_OPTS_STAGE1])
+FP_LD_NO_WARN_DUPLICATE_LIBRARIES([target], [CONF_GCC_LINKER_OPTS_STAGE2])
+
 FP_LD_SUPPORTS_RESPONSE_FILES
 
 GHC_LLVM_TARGET_SET_VAR


=====================================
distrib/configure.ac.in
=====================================
@@ -130,6 +130,7 @@ AC_SUBST([LdCmd])
 FP_PROG_LD_IS_GNU
 FP_PROG_LD_NO_COMPACT_UNWIND
 FP_PROG_LD_FILELIST
+FP_PROG_LD_SINGLE_MODULE
 
 dnl ** which strip to use?
 dnl --------------------------------------------------------------
@@ -169,11 +170,17 @@ FPTOOLS_SET_C_LD_FLAGS([target],[CONF_CC_OPTS_STAGE1],[CONF_GCC_LINKER_OPTS_STAG
 # Stage 3 won't be supported by cross-compilation
 FPTOOLS_SET_C_LD_FLAGS([target],[CONF_CC_OPTS_STAGE2],[CONF_GCC_LINKER_OPTS_STAGE2],[CONF_LD_LINKER_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2])
 
+#-no_fixup_chains
 FP_LD_NO_FIXUP_CHAINS([target], [LDFLAGS])
 FP_LD_NO_FIXUP_CHAINS([build], [CONF_GCC_LINKER_OPTS_STAGE0])
 FP_LD_NO_FIXUP_CHAINS([target], [CONF_GCC_LINKER_OPTS_STAGE1])
 FP_LD_NO_FIXUP_CHAINS([target], [CONF_GCC_LINKER_OPTS_STAGE2])
 
+#-no_warn_duplicate_libraries
+FP_LD_NO_WARN_DUPLICATE_LIBRARIES([build], [CONF_GCC_LINKER_OPTS_STAGE0])
+FP_LD_NO_WARN_DUPLICATE_LIBRARIES([target], [CONF_GCC_LINKER_OPTS_STAGE1])
+FP_LD_NO_WARN_DUPLICATE_LIBRARIES([target], [CONF_GCC_LINKER_OPTS_STAGE2])
+
 FP_LD_SUPPORTS_RESPONSE_FILES
 
 AC_SUBST(CONF_CC_OPTS_STAGE0)


=====================================
hadrian/bindist/Makefile
=====================================
@@ -93,6 +93,7 @@ lib/settings : config.mk
 	@echo ',("ld supports compact unwind", "$(LdHasNoCompactUnwind)")' >> $@
 	@echo ',("ld supports filelist", "$(LdHasFilelist)")' >> $@
 	@echo ',("ld supports response files", "$(LdSupportsResponseFiles)")' >> $@
+	@echo ',("ld supports single module", "$(LdHasSingleModule)")' >> $@
 	@echo ',("ld is GNU ld", "$(LdIsGNULd)")' >> $@
 	@echo ',("Merge objects command", "$(SettingsMergeObjectsCommand)")' >> $@
 	@echo ',("Merge objects flags", "$(SettingsMergeObjectsFlags)")' >> $@


=====================================
hadrian/bindist/config.mk.in
=====================================
@@ -240,6 +240,7 @@ LdHasBuildId = @LdHasBuildId@
 LdHasFilelist = @LdHasFilelist@
 LdIsGNULd = @LdIsGNULd@
 LdHasNoCompactUnwind = @LdHasNoCompactUnwind@
+LdHasSingleModule = @LdHasSingleModule@
 ArArgs = @ArArgs@
 ArSupportsAtFile = @ArSupportsAtFile@
 ArSupportsDashL  = @ArSupportsDashL@


=====================================
hadrian/cfg/system.config.in
=====================================
@@ -141,6 +141,7 @@ ld-has-no-compact-unwind = @LdHasNoCompactUnwind@
 ld-has-filelist = @LdHasFilelist@
 ld-supports-response-files = @LdSupportsResponseFiles@
 ld-is-gnu-ld = @LdIsGNULd@
+ld-supports-single-module = @LdHasSingleModule@
 ar-args = @ArArgs@
 
 settings-c-compiler-command = @SettingsCCompilerCommand@


=====================================
hadrian/src/Rules/Generate.hs
=====================================
@@ -440,6 +440,7 @@ generateSettings = do
         , ("ld supports filelist", expr $ lookupSystemConfig "ld-has-filelist")
         , ("ld supports response files", expr $ lookupSystemConfig "ld-supports-response-files")
         , ("ld is GNU ld", expr $ lookupSystemConfig "ld-is-gnu-ld")
+        , ("ld supports single module", expr $ lookupSystemConfig "ld-supports-single-module")
         , ("Merge objects command", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsCommand)
         , ("Merge objects flags", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsFlags)
         , ("ar command", expr $ settingsFileSetting SettingsFileSetting_ArCommand)


=====================================
libraries/base/tests/IO/all.T
=====================================
@@ -136,7 +136,11 @@ test('encoding004', [extra_files(['encoded-data/']), js_broken(22374),
 # and
 # https://gitlab.haskell.org/ghc/wasi-libc/-/blob/main/libc-top-half/musl/src/locale/codepages.h
 # for locales supported by wasi-libc's iconv implementation
-when(arch('wasm32'), skip)], compile_and_run, [''])
+when(arch('wasm32'), skip),
+# MacOS Sonoma iconv() has a regression that causes this test to fail on the
+# CP936 roundtrip. See the ticket for related issues in other projects.
+when(opsys('darwin'), fragile(24161))
+], compile_and_run, [''])
 test('encoding005', normal, compile_and_run, [''])
 
 test('environment001', [], makefile_test, ['environment001-test'])


=====================================
m4/fp_ld_no_warn_duplicate_libraries.m4
=====================================
@@ -0,0 +1,29 @@
+# FP_LD_NO_WARN_DUPLICATE_LIBRARIES
+# ---------------------------------
+# XCode 15 introduced a new linker which warns on duplicate libraries being
+# linked. To disable this warning, we pass -Wl,-no_warn_duplicate_libraries as
+# suggested by Brad King in CMake issue #25297.
+#
+# This flag isn't necessarily available to other linkers on darwin, so we must
+# only configure it into the CC linker arguments if valid.
+#
+# $1 = the platform
+# $2 = the name of the linker flags variable when linking with $CC
+AC_DEFUN([FP_LD_NO_WARN_DUPLICATE_LIBRARIES], [
+    case $$1 in
+      *-darwin)
+      AC_MSG_CHECKING([whether the linker requires -no_warn_duplicate_libraries])
+      echo 'int main(void) {return 0;}' > conftest.c
+      if $CC -o conftest -Wl,-no_warn_duplicate_libraries conftest.c > /dev/null 2>&1
+      then
+          $2="$$2 -Wl,-no_warn_duplicate_libraries"
+          AC_MSG_RESULT([yes])
+      else
+          AC_MSG_RESULT([no])
+      fi
+      rm -f conftest.c conftest.o conftest
+      ;;
+
+    esac
+])
+


=====================================
m4/fp_prog_ld_single_module.m4
=====================================
@@ -0,0 +1,30 @@
+# FP_PROG_LD_SINGLE_MODULE
+# ----------------------------
+# Sets the output variable LdHasSingleModule to YES if the darwin ld supports
+# -single_module, or NO otherwise.
+#
+# In XCode 15, -single_module is a default and passing it as a flag raises a
+# warning.
+AC_DEFUN([FP_PROG_LD_SINGLE_MODULE],
+[
+AC_CACHE_CHECK([whether ld supports -single_module], [fp_cv_ld_single_module],
+[
+case $target in
+  *-darwin)
+    echo 'int foo(int x) { return x*x; }' > conftest.c
+    echo 'extern int foo(int); int main() { return foo(5); }' > conftestmain.c
+    "$CC" -c -o conftestmain.o conftestmain.c
+    "$CC" -shared -o conftest.dylib conftest.c
+    if "$CC" -Wl,-single_module -o conftest conftestmain.o conftest.dylib 2>&1 | grep obsolete > /dev/null; then
+      fp_cv_ld_single_module=no
+    else
+      fp_cv_ld_single_module=yes
+    fi
+    rm -rf conftest* ;;
+  *)
+    fp_cv_ld_single_module=no ;;
+esac
+])
+FP_CAPITALIZE_YES_NO(["$fp_cv_ld_single_module"], [LdHasSingleModule])
+AC_SUBST([LdHasSingleModule])
+])# FP_PROG_LD_SINGLE_MODULE


=====================================
testsuite/tests/driver/Makefile
=====================================
@@ -552,8 +552,8 @@ T7563:
 	-"$(TEST_HC)" $(TEST_HC_OPTS) -C T7563.hs
 
 # Below we set LC_ALL=C to request standard ASCII output in the resulting error
-# messages. Unfortunately, Mac OS X and Windows still use a Unicode encoding
-# even with LC_ALL=C, so we expect these tests to fail there.
+# messages. Unfortunately, versions of MacOS prior to Sonoma and Windows still
+# use a Unicode encoding even with LC_ALL=C, so we expect these tests to fail there.
 
 .PHONY: T6037
 T6037:


=====================================
testsuite/tests/driver/all.T
=====================================
@@ -178,16 +178,25 @@ test('T7060', [], makefile_test, [])
 test('T7130', normal, compile_fail, ['-fflul-laziness'])
 test('T7563', when(unregisterised(), skip), makefile_test, [])
 test('T6037',
-     # The testsuite doesn't know how to set a non-Unicode locale on Windows or Mac OS X
-     [when(opsys('mingw32'), expect_fail), when(opsys('darwin'), expect_fail)],
+     # The testsuite doesn't know how to set a non-Unicode locale on Windows or MacOS < Sonoma.
+     # Because in previous version of MacOS the test is still broken, we mark it as fragile.
+     [when(opsys('mingw32'), expect_fail),
+      when(opsys('darwin'), fragile(24161))
+     ],
      makefile_test, [])
 test('T2507',
-     # The testsuite doesn't know how to set a non-Unicode locale on Windows or Mac OS X
-     [when(opsys('mingw32'), expect_fail), when(opsys('darwin'), expect_fail)],
+     # The testsuite doesn't know how to set a non-Unicode locale on Windows or MacOS < Sonoma
+     # Because in previous version of MacOS the test is still broken, we mark it as fragile.
+     [when(opsys('mingw32'), expect_fail),
+      when(opsys('darwin'), fragile(24161))
+     ],
      makefile_test, [])
 test('T8959a',
-     # The testsuite doesn't know how to set a non-Unicode locale on Windows or Mac OS X
-     [when(opsys('mingw32'), expect_fail), when(opsys('darwin'), expect_fail)],
+     # The testsuite doesn't know how to set a non-Unicode locale on Windows or MacOS < Sonoma
+     # Because in previous version of MacOS the test is still broken, we mark it as fragile.
+     [when(opsys('mingw32'), expect_fail),
+      when(opsys('darwin'), fragile(24161))
+     ],
      makefile_test, [])
 
 # Requires readelf



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/042d45ddf838f2443c228a1773c14c8ca5dcca20...b746f8a86d48f1c379228039a87e220dfb81fba6

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/042d45ddf838f2443c228a1773c14c8ca5dcca20...b746f8a86d48f1c379228039a87e220dfb81fba6
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/20240209/a13ff99b/attachment-0001.html>


More information about the ghc-commits mailing list