From b7810b9e5375ba6ffd0bf5370cac8717cc171739 Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Wed, 15 Nov 2023 12:43:17 +1100 Subject: [PATCH] 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. --- Cabal/src/Distribution/Simple/Configure.hs | 32 +++++++++------------ Cabal/src/Distribution/Simple/Program/Db.hs | 7 ++++- changelog.d/pr-9443 | 12 ++++++++ 3 files changed, 31 insertions(+), 20 deletions(-) create mode 100644 changelog.d/pr-9443 diff --git a/Cabal/src/Distribution/Simple/Configure.hs b/Cabal/src/Distribution/Simple/Configure.hs index 1c9188a2a6b..2311c1b6e0f 100644 --- a/Cabal/src/Distribution/Simple/Configure.hs +++ b/Cabal/src/Distribution/Simple/Configure.hs @@ -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 @@ -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 _ -> @@ -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 diff --git a/Cabal/src/Distribution/Simple/Program/Db.hs b/Cabal/src/Distribution/Simple/Program/Db.hs index 5bef94e4b5f..1407230b93b 100644 --- a/Cabal/src/Distribution/Simple/Program/Db.hs +++ b/Cabal/src/Distribution/Simple/Program/Db.hs @@ -46,6 +46,7 @@ module Distribution.Simple.Program.Db , userSpecifyArgss , userSpecifiedArgs , lookupProgram + , lookupProgramByName , updateProgram , configuredPrograms @@ -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 diff --git a/changelog.d/pr-9443 b/changelog.d/pr-9443 new file mode 100644 index 00000000000..9a43d9e87e1 --- /dev/null +++ b/changelog.d/pr-9443 @@ -0,0 +1,12 @@ +synopsis: Use linker capability detection to improve linker use +packages: Cabal +prs: #9443 +significance: subtle + +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. + +}