diff options
author | Ben Gamari <ben@smart-cactus.org> | 2022-03-24 21:00:44 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-04-06 13:01:28 -0400 |
commit | 3ac80a8609418f9f1e9aa025b182fb3445f14428 (patch) | |
tree | 207223dc28b689120628585b3fa0fd3554d1ae5c | |
parent | 41fcb5cd756f52cd313d90a73f556fa5f3890818 (diff) | |
download | haskell-3ac80a8609418f9f1e9aa025b182fb3445f14428.tar.gz |
hadrian: Produce ar archives with L modifier on Windows
Since object files may in fact be archive files, we must ensure that
their contents are merged rather than constructing an
archive-of-an-archive.
See #21068.
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | hadrian/cfg/system.config.in | 1 | ||||
-rw-r--r-- | hadrian/src/Oracles/Flag.hs | 2 | ||||
-rw-r--r-- | hadrian/src/Settings/Builders/Ar.hs | 8 | ||||
-rw-r--r-- | m4/fp_prog_ar_supports_dash_l.m4 | 30 |
5 files changed, 41 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index 71879adeb0..95d0043f59 100644 --- a/configure.ac +++ b/configure.ac @@ -848,6 +848,7 @@ AC_PROG_INSTALL dnl ** how to invoke `ar' and `ranlib' FP_PROG_AR_SUPPORTS_ATFILE +FP_PROG_AR_SUPPORTS_DASH_L FP_PROG_AR_NEEDS_RANLIB dnl ** Check to see whether ln -s works diff --git a/hadrian/cfg/system.config.in b/hadrian/cfg/system.config.in index 0c2a76b7ac..6544261cd3 100644 --- a/hadrian/cfg/system.config.in +++ b/hadrian/cfg/system.config.in @@ -40,6 +40,7 @@ python = @PythonCmd@ #============================ ar-supports-at-file = @ArSupportsAtFile@ +ar-supports-dash-l = @ArSupportsDashL@ cc-llvm-backend = @CcLlvmBackend@ hs-cpp-args = @HaskellCPPArgs@ diff --git a/hadrian/src/Oracles/Flag.hs b/hadrian/src/Oracles/Flag.hs index 7da72546e3..40ae3e8f9b 100644 --- a/hadrian/src/Oracles/Flag.hs +++ b/hadrian/src/Oracles/Flag.hs @@ -12,6 +12,7 @@ import Base import Oracles.Setting data Flag = ArSupportsAtFile + | ArSupportsDashL | CrossCompiling | CcLlvmBackend | GhcUnregisterised @@ -34,6 +35,7 @@ flag :: Flag -> Action Bool flag f = do let key = case f of ArSupportsAtFile -> "ar-supports-at-file" + ArSupportsDashL -> "ar-supports-dash-l" CrossCompiling -> "cross-compiling" CcLlvmBackend -> "cc-llvm-backend" GhcUnregisterised -> "ghc-unregisterised" diff --git a/hadrian/src/Settings/Builders/Ar.hs b/hadrian/src/Settings/Builders/Ar.hs index a4b08d6358..08379f07f8 100644 --- a/hadrian/src/Settings/Builders/Ar.hs +++ b/hadrian/src/Settings/Builders/Ar.hs @@ -8,7 +8,13 @@ import Settings.Builders.Common arBuilderArgs :: Args arBuilderArgs = mconcat [ builder (Ar Pack) ? mconcat - [ arg "q" + [ -- When building on platforms which don't support object merging + -- we must use the -L flag supported by llvm-ar, which ensures that + -- .a files added to the archive are merged into the resulting archive, + -- not added as a single file. This requires that we are using llvm-ar + -- + -- See Note [Object merging] in GHC.Driver.Pipeline.Execute for details. + ifM ((&&) <$> notStage0 <*> expr (flag ArSupportsDashL)) (arg "qL") (arg "q") , arg =<< getOutput ] , builder (Ar Unpack) ? mconcat diff --git a/m4/fp_prog_ar_supports_dash_l.m4 b/m4/fp_prog_ar_supports_dash_l.m4 new file mode 100644 index 0000000000..3ec26db548 --- /dev/null +++ b/m4/fp_prog_ar_supports_dash_l.m4 @@ -0,0 +1,30 @@ +# FP_PROG_AR_SUPPORTS_DASH_L +# ----------------- +# Sets fp_prog_ar_supports_dash_l to yes or no, depending on whether +# or not it supports the llvm-ar's -L flag to merge archives. +AC_DEFUN([FP_PROG_AR_SUPPORTS_DASH_L], +[ + AC_REQUIRE([FP_PROG_AR]) + AC_REQUIRE([FP_PROG_AR_ARGS]) + AC_CACHE_CHECK([whether $fp_prog_ar supports -L], [fp_cv_prog_ar_supports_dash_l], + [ + rm -f conftest* + touch conftest.file + touch conftest.a0 conftest.a1 conftest.b0 conftest.b1 + dnl Build two archives, merge them, and check that the result contains the + dnl original files not the two archives. + "$fp_prog_ar" qc conftest-a.a conftest.a0 conftest.a1 + "$fp_prog_ar" qc conftest-b.a conftest.b0 conftest.b1 + "$fp_prog_ar" qcL conftest.a conftest-a.a conftest-b.a 2>/dev/null + if "$fp_prog_ar" t conftest.a | grep -s "conftest.a1" > /dev/null + then + fp_cv_prog_ar_supports_dash_l=yes + else + fp_cv_prog_ar_supports_dash_l=no + fi + rm -f conftest* + ]) + fp_prog_ar_supports_dash_l=$fp_cv_prog_ar_supports_dash_l + AC_SUBST([ArSupportsDashL], [`echo $fp_prog_ar_supports_dash_l | tr 'a-z' 'A-Z'`]) +])# FP_PROG_AR_SUPPORTS_DASH_L + |