Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only use relocatable linker flag if linker supports it #9236

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 1 addition & 26 deletions Cabal/src/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
@@ -767,22 +767,6 @@ configure (pkg_descr0, pbi) cfg = do
)
return False

let compilerSupportsGhciLibs :: Bool
compilerSupportsGhciLibs =
case compilerId comp of
CompilerId GHC version
| version > mkVersion [9, 3] && windows ->
False
CompilerId GHC _ ->
True
CompilerId GHCJS _ ->
True
_ -> False
where
windows = case compPlatform of
Platform _ Windows -> True
Platform _ _ -> False

let ghciLibByDefault =
case compilerId comp of
CompilerId GHC _ ->
@@ -799,15 +783,6 @@ configure (pkg_descr0, pbi) cfg = do
not (GHCJS.isDynamic comp)
_ -> False

withGHCiLib_ <-
case fromFlagOrDefault ghciLibByDefault (configGHCiLib cfg) of
True | not compilerSupportsGhciLibs -> do
warn verbosity $
"--enable-library-for-ghci is no longer supported on Windows with"
++ " GHC 9.4 and later; ignoring..."
return False
v -> return v

let sharedLibsByDefault
| fromFlag (configDynExe cfg) =
-- build a shared library if dynamically-linked
@@ -912,7 +887,7 @@ configure (pkg_descr0, pbi) cfg = do
, withProfExeDetail = ProfDetailNone
, withOptimization = fromFlag $ configOptimization cfg
, withDebugInfo = fromFlag $ configDebugInfo cfg
, withGHCiLib = withGHCiLib_
, withGHCiLib = fromFlagOrDefault ghciLibByDefault $ configGHCiLib cfg
, splitSections = split_sections
, splitObjs = split_objs
, stripExes = strip_exe
3 changes: 2 additions & 1 deletion Cabal/src/Distribution/Simple/Program/Builtin.hs
Original file line number Diff line number Diff line change
@@ -362,7 +362,8 @@ ldProgram =
-- choice for windows linking does not support this feature. However
-- if using binutils ld or another linker that supports --relocatable,
-- we should still be good to generate pre-linked objects.
ldHelpOutput <-
ldHelpOutput <- do
_ <- error "Distribution.Simple.Program.Builtin.ldProgram"
getProgramInvocationOutput
verbosity
(programInvocation ldProg ["--help"])
19 changes: 16 additions & 3 deletions Cabal/src/Distribution/Simple/Program/Ld.hs
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion Cabal/src/Distribution/Simple/Setup/Common.hs
Original file line number Diff line number Diff line change
@@ -327,7 +327,9 @@ configureCCompiler
configureCCompiler verbosity progdb = configureProg verbosity progdb gccProgram

configureLinker :: Verbosity -> ProgramDb -> IO (FilePath, [String])
configureLinker verbosity progdb = configureProg verbosity progdb ldProgram
configureLinker verbosity progdb = do
_ <- error $ show ldProgram
configureProg verbosity progdb ldProgram

configureProg
:: Verbosity
7 changes: 1 addition & 6 deletions Cabal/src/Distribution/Simple/Setup/Config.hs
Original file line number Diff line number Diff line change
@@ -322,12 +322,7 @@ defaultConfigFlags progDb =
, configCabalFilePath = NoFlag
, configVerbosity = Flag normal
, configUserInstall = Flag False -- TODO: reverse this
#if defined(mingw32_HOST_OS)
-- See #8062 and GHC #21019.
, configGHCiLib = Flag False
#else
, configGHCiLib = NoFlag
#endif
, configGHCiLib = Flag True
, configSplitSections = Flag False
, configSplitObjs = Flag False -- takes longer, so turn off by default
, configStripExes = NoFlag