@@ -24,7 +24,7 @@ import Distribution.Compat.Prelude
24
24
import qualified Data.ByteString as BS
25
25
import qualified Data.ByteString.Char8 as BS8
26
26
import Distribution.Compat.CopyFile (filesEqual )
27
- import Distribution.Simple.Compiler (arResponseFilesSupported )
27
+ import Distribution.Simple.Compiler (arResponseFilesSupported , arDashLSupported )
28
28
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo (.. ))
29
29
import Distribution.Simple.Program
30
30
( ProgramInvocation , arProgram , requireProgram )
@@ -68,17 +68,25 @@ createArLibArchive verbosity lbi targetPath files = do
68
68
-- do that. We have duplicates because of modules like "A.M" and "B.M"
69
69
-- both make an object file "M.o" and ar does not consider the directory.
70
70
--
71
+ -- -- llvm-ar, which GHC >=9.4 uses on Windows, supports a "L" modifier
72
+ -- in "q" mode which compels the archiver to add the members of an input
73
+ -- archive to the output, rather than the archive itself. This is
74
+ -- necessary as GHC may produce .o files that are actually archives. See
75
+ -- https://gitlab.haskell.org/ghc/ghc/-/issues/21068.
76
+ --
71
77
-- Our solution is to use "ar r" in the simple case when one call is enough.
72
78
-- When we need to call ar multiple times we use "ar q" and for the last
73
79
-- call on OSX we use "ar qs" so that it'll make the index.
74
80
75
81
let simpleArgs = case hostOS of
76
82
OSX -> [" -r" , " -s" ]
83
+ _ | dashLSupported -> [" -qL" ]
77
84
_ -> [" -r" ]
78
85
79
86
initialArgs = [" -q" ]
80
87
finalArgs = case hostOS of
81
88
OSX -> [" -q" , " -s" ]
89
+ _ | dashLSupported -> [" -qL" ]
82
90
_ -> [" -q" ]
83
91
84
92
extraArgs = verbosityOpts verbosity ++ [tmpPath]
@@ -90,8 +98,10 @@ createArLibArchive verbosity lbi targetPath files = do
90
98
91
99
oldVersionManualOverride =
92
100
fromFlagOrDefault False $ configUseResponseFiles $ configFlags lbi
93
- responseArgumentsNotSupported =
101
+ responseArgumentsNotSupported =
94
102
not (arResponseFilesSupported (compiler lbi))
103
+ dashLSupported =
104
+ arDashLSupported (compiler lbi)
95
105
96
106
invokeWithResponesFile :: FilePath -> ProgramInvocation
97
107
invokeWithResponesFile atFile =
0 commit comments