Skip to content
Snippets Groups Projects
Commit 745c720e authored by Erik de Castro Lopo's avatar Erik de Castro Lopo
Browse files

Only use relocatable linker flag if linker supports it

parent 7f0c5b24
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,8 @@ module Distribution.Simple.Program.Ld
import Distribution.Compat.Prelude
import Prelude ()
import qualified Data.Map as Map
import Distribution.Simple.Compiler (arResponseFilesSupported)
import Distribution.Simple.Flag
( fromFlagOrDefault
......@@ -67,10 +69,14 @@ combineObjectFiles verbosity lbi ld target files = do
-- have a slight problem. What we have to do is link files in batches into
-- a temp object file and then include that one in the next batch.
let simpleArgs = ["-r", "-o", target]
putStrLn "\n\n\n"
print ld
putStrLn "\n\n\n"
let simpleArgs = prependRelocatableFlag ["-o", target]
initialArgs = ["-r", "-o", target]
middleArgs = ["-r", "-o", target, tmpfile]
initialArgs = prependRelocatableFlag ["-o", target]
middleArgs = prependRelocatableFlag ["-o", target, tmpfile]
finalArgs = middleArgs
simple = programInvocation ld simpleArgs
......@@ -104,3 +110,10 @@ combineObjectFiles verbosity lbi ld target files = do
runProgramInvocation verbosity inv
renameFile target tmpfile
run invs
-- Prepend "-r" to the list if the linker supports relocatable outputs.
prependRelocatableFlag :: [String] -> [String]
prependRelocatableFlag xs =
case Map.lookup "Supports relocatable output" $ programProperties ld of
Just "YES" -> "-r" : xs
_other -> xs
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment