Skip to content

Commit

Permalink
Only use relocatable linker flag if linker supports it
Browse files Browse the repository at this point in the history
  • Loading branch information
erikd committed Sep 28, 2023
1 parent 80a8dc6 commit dc337d7
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Cabal/src/Distribution/Simple/Program/Ld.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -67,10 +69,10 @@ 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]
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
Expand Down Expand Up @@ -104,3 +106,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 comments on commit dc337d7

Please sign in to comment.