Skip to content

Commit

Permalink
Use linker capability detection to improve linker use
Browse files Browse the repository at this point in the history
The function `comperSupportsGhciLibs` has been renamed to
`linkerSupportsGhciLibs` because its about the linker not the compiler.

The function `comperSupportsGhciLibs` was using the compiler version
as a proxy for whether the linker supports relocatable objects. Now
support for relocatable objects is detected by running the linker.
  • Loading branch information
erikd committed Nov 15, 2023
1 parent 268a85a commit 609049b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
32 changes: 13 additions & 19 deletions Cabal/src/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import Distribution.Simple.PackageIndex (InstalledPackageIndex)
import qualified Distribution.Simple.PackageIndex as PackageIndex
import Distribution.Simple.PreProcess
import Distribution.Simple.Program
import Distribution.Simple.Program.Db (lookupProgramByName)
import Distribution.Simple.Setup.Common as Setup
import Distribution.Simple.Setup.Config as Setup
import Distribution.Simple.Utils
Expand Down Expand Up @@ -767,22 +768,15 @@ 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 linkerSupportsGhciLibs :: Bool
linkerSupportsGhciLibs =
case lookupProgramByName "ld" programDb'' of
Nothing -> True -- NOTE: This may still fail if the linker does not support -r.
Just ld ->
case Map.lookup "Supports relocatable output" $ programProperties ld of
Just "YES" -> True
Just "NO" -> False
_other -> True -- NOTE: This may still fail if the linker does not support -r.
let ghciLibByDefault =
case compilerId comp of
CompilerId GHC _ ->
Expand All @@ -801,10 +795,10 @@ configure (pkg_descr0, pbi) cfg = do

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

Expand Down
7 changes: 6 additions & 1 deletion Cabal/src/Distribution/Simple/Program/Db.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module Distribution.Simple.Program.Db
, userSpecifyArgss
, userSpecifiedArgs
, lookupProgram
, lookupProgramByName
, updateProgram
, configuredPrograms

Expand Down Expand Up @@ -299,7 +300,11 @@ userSpecifiedArgs prog =

-- | Try to find a configured program
lookupProgram :: Program -> ProgramDb -> Maybe ConfiguredProgram
lookupProgram prog = Map.lookup (programName prog) . configuredProgs
lookupProgram = lookupProgramByName . programName

-- | Try to find a configured program
lookupProgramByName :: String -> ProgramDb -> Maybe ConfiguredProgram
lookupProgramByName name = Map.lookup name . configuredProgs

-- | Update a configured program in the database.
updateProgram
Expand Down
12 changes: 12 additions & 0 deletions changelog.d/pr-9443
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
synopsis: Use linker capability detection to improve linker use
packages: Cabal
prs: #9443
significance: suble

description: {

- Previously the GHC version number and platform we used as a proxy for whether
the linker can generate relocatable objects.
- Now, the ability of the linker to create relocatable objects is detected.

}

0 comments on commit 609049b

Please sign in to comment.