Skip to content

Commit e8c5a99

Browse files
committed
Only use relocatable linker flag if linker supports it
1 parent ef1beef commit e8c5a99

File tree

1 file changed

+16
-3
lines changed
  • Cabal/src/Distribution/Simple/Program

1 file changed

+16
-3
lines changed

Cabal/src/Distribution/Simple/Program/Ld.hs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ module Distribution.Simple.Program.Ld
1818
import Distribution.Compat.Prelude
1919
import Prelude ()
2020

21+
import qualified Data.Map as Map
22+
2123
import Distribution.Simple.Compiler (arResponseFilesSupported)
2224
import Distribution.Simple.Flag
2325
( fromFlagOrDefault
@@ -67,10 +69,14 @@ combineObjectFiles verbosity lbi ld target files = do
6769
-- have a slight problem. What we have to do is link files in batches into
6870
-- a temp object file and then include that one in the next batch.
6971

70-
let simpleArgs = ["-r", "-o", target]
72+
putStrLn "\n\n\n"
73+
print ld
74+
putStrLn "\n\n\n"
75+
76+
let simpleArgs = prependRelocatableFlag ["-o", target]
7177

72-
initialArgs = ["-r", "-o", target]
73-
middleArgs = ["-r", "-o", target, tmpfile]
78+
initialArgs = prependRelocatableFlag ["-o", target]
79+
middleArgs = prependRelocatableFlag ["-o", target, tmpfile]
7480
finalArgs = middleArgs
7581

7682
simple = programInvocation ld simpleArgs
@@ -104,3 +110,10 @@ combineObjectFiles verbosity lbi ld target files = do
104110
runProgramInvocation verbosity inv
105111
renameFile target tmpfile
106112
run invs
113+
114+
-- Prepend "-r" to the list if the linker supports relocatable outputs.
115+
prependRelocatableFlag :: [String] -> [String]
116+
prependRelocatableFlag xs =
117+
case Map.lookup "Supports relocatable output" $ programProperties ld of
118+
Just "YES" -> "-r" : xs
119+
_other -> xs

0 commit comments

Comments
 (0)