Skip to content

Commit

Permalink
combineObjectFiles: Error if the linker does not support -r
Browse files Browse the repository at this point in the history
The `lld` linker (commonly used on Windows) does not support
relocatable output.
  • Loading branch information
erikd committed Oct 6, 2023
1 parent 7a7d8ce commit 5252c89
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Cabal/src/Distribution/Simple/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ data CabalException
| NoProgramFound String VersionRange
| BadVersionDb String Version VersionRange FilePath
| UnknownVersionDb String VersionRange FilePath
| CombineObjectFilesRelocatableUnsupported
deriving (Show, Typeable)

exceptionCode :: CabalException -> Int
Expand Down Expand Up @@ -301,6 +302,7 @@ exceptionCode e = case e of
NoProgramFound{} -> 7620
BadVersionDb{} -> 8038
UnknownVersionDb{} -> 1008
CombineObjectFilesRelocatableUnsupported -> 4346

versionRequirement :: VersionRange -> String
versionRequirement range
Expand Down Expand Up @@ -791,3 +793,6 @@ exceptionMessage e = case e of
++ " is required but the version of "
++ locationPath
++ " could not be determined."
CombineObjectFilesRelocatableUnsupported ->
"combineObjectFiles: Have been asked to combine object "
++ "files but the configured linker does not support relocations."
12 changes: 11 additions & 1 deletion Cabal/src/Distribution/Simple/Program/Ld.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ module Distribution.Simple.Program.Ld
( combineObjectFiles
) where

import qualified Data.Map.Strict as Map

import Distribution.Compat.Prelude
import Prelude ()

import Distribution.Simple.Compiler (arResponseFilesSupported)
import Distribution.Simple.Errors
( CabalException (CombineObjectFilesRelocatableUnsupported)
)
import Distribution.Simple.Flag
( fromFlagOrDefault
)
Expand All @@ -40,11 +45,11 @@ import Distribution.Simple.Setup.Config
)
import Distribution.Simple.Utils
( defaultTempFileOptions
, dieWithException
)
import Distribution.Verbosity
( Verbosity
)

import System.Directory
( renameFile
)
Expand All @@ -67,6 +72,11 @@ 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.

case Map.lookup "Supports relocatable output" $ programProperties ld of
Just "YES" -> pure ()
Just "NO" ->
dieWithException verbosity $ CombineObjectFilesRelocatableUnsupported
_other -> pure () -- This may still fail if the compiler does not support -r.
let simpleArgs = ["-r", "-o", target]

initialArgs = ["-r", "-o", target]
Expand Down

0 comments on commit 5252c89

Please sign in to comment.