Skip to content

Commit 609049b

Browse files
committed
Use linker capability detection to improve linker use
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.
1 parent 268a85a commit 609049b

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

Cabal/src/Distribution/Simple/Configure.hs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import Distribution.Simple.PackageIndex (InstalledPackageIndex)
8282
import qualified Distribution.Simple.PackageIndex as PackageIndex
8383
import Distribution.Simple.PreProcess
8484
import Distribution.Simple.Program
85+
import Distribution.Simple.Program.Db (lookupProgramByName)
8586
import Distribution.Simple.Setup.Common as Setup
8687
import Distribution.Simple.Setup.Config as Setup
8788
import Distribution.Simple.Utils
@@ -767,22 +768,15 @@ configure (pkg_descr0, pbi) cfg = do
767768
)
768769
return False
769770

770-
let compilerSupportsGhciLibs :: Bool
771-
compilerSupportsGhciLibs =
772-
case compilerId comp of
773-
CompilerId GHC version
774-
| version > mkVersion [9, 3] && windows ->
775-
False
776-
CompilerId GHC _ ->
777-
True
778-
CompilerId GHCJS _ ->
779-
True
780-
_ -> False
781-
where
782-
windows = case compPlatform of
783-
Platform _ Windows -> True
784-
Platform _ _ -> False
785-
771+
let linkerSupportsGhciLibs :: Bool
772+
linkerSupportsGhciLibs =
773+
case lookupProgramByName "ld" programDb'' of
774+
Nothing -> True -- NOTE: This may still fail if the linker does not support -r.
775+
Just ld ->
776+
case Map.lookup "Supports relocatable output" $ programProperties ld of
777+
Just "YES" -> True
778+
Just "NO" -> False
779+
_other -> True -- NOTE: This may still fail if the linker does not support -r.
786780
let ghciLibByDefault =
787781
case compilerId comp of
788782
CompilerId GHC _ ->
@@ -801,10 +795,10 @@ configure (pkg_descr0, pbi) cfg = do
801795

802796
withGHCiLib_ <-
803797
case fromFlagOrDefault ghciLibByDefault (configGHCiLib cfg) of
804-
True | not compilerSupportsGhciLibs -> do
798+
True | not linkerSupportsGhciLibs -> do
805799
warn verbosity $
806-
"--enable-library-for-ghci is no longer supported on Windows with"
807-
++ " GHC 9.4 and later; ignoring..."
800+
"--enable-library-for-ghci is not supported with the current"
801+
++ " linker; ignoring..."
808802
return False
809803
v -> return v
810804

Cabal/src/Distribution/Simple/Program/Db.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ module Distribution.Simple.Program.Db
4646
, userSpecifyArgss
4747
, userSpecifiedArgs
4848
, lookupProgram
49+
, lookupProgramByName
4950
, updateProgram
5051
, configuredPrograms
5152

@@ -299,7 +300,11 @@ userSpecifiedArgs prog =
299300

300301
-- | Try to find a configured program
301302
lookupProgram :: Program -> ProgramDb -> Maybe ConfiguredProgram
302-
lookupProgram prog = Map.lookup (programName prog) . configuredProgs
303+
lookupProgram = lookupProgramByName . programName
304+
305+
-- | Try to find a configured program
306+
lookupProgramByName :: String -> ProgramDb -> Maybe ConfiguredProgram
307+
lookupProgramByName name = Map.lookup name . configuredProgs
303308

304309
-- | Update a configured program in the database.
305310
updateProgram

changelog.d/pr-9443

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
synopsis: Use linker capability detection to improve linker use
2+
packages: Cabal
3+
prs: #9443
4+
significance: suble
5+
6+
description: {
7+
8+
- Previously the GHC version number and platform we used as a proxy for whether
9+
the linker can generate relocatable objects.
10+
- Now, the ability of the linker to create relocatable objects is detected.
11+
12+
}

0 commit comments

Comments
 (0)