diff --git a/Cabal/src/Distribution/Simple/Errors.hs b/Cabal/src/Distribution/Simple/Errors.hs index dc3e30ab9b6..7d2d2ddd22e 100644 --- a/Cabal/src/Distribution/Simple/Errors.hs +++ b/Cabal/src/Distribution/Simple/Errors.hs @@ -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 @@ -301,6 +302,7 @@ exceptionCode e = case e of NoProgramFound{} -> 7620 BadVersionDb{} -> 8038 UnknownVersionDb{} -> 1008 + CombineObjectFilesRelocatableUnsupported -> 4346 versionRequirement :: VersionRange -> String versionRequirement range @@ -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." diff --git a/Cabal/src/Distribution/Simple/Program/Ld.hs b/Cabal/src/Distribution/Simple/Program/Ld.hs index d7449b93964..c7521c0f198 100644 --- a/Cabal/src/Distribution/Simple/Program/Ld.hs +++ b/Cabal/src/Distribution/Simple/Program/Ld.hs @@ -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 ) @@ -40,11 +45,11 @@ import Distribution.Simple.Setup.Config ) import Distribution.Simple.Utils ( defaultTempFileOptions + , dieWithException ) import Distribution.Verbosity ( Verbosity ) - import System.Directory ( renameFile ) @@ -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 () -- NOTE: This may still fail if the compiler does not support -r. let simpleArgs = ["-r", "-o", target] initialArgs = ["-r", "-o", target]