diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2021-09-16 16:17:44 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-09-22 08:24:23 -0400 |
commit | 92257abd4b64f0496204adb19462d05c1d6475e3 (patch) | |
tree | 906a64d411ff4116482742fdaeebd64fb24df570 /compiler | |
parent | bb37026e3547af569db6dce021b59f4d0ac70910 (diff) | |
download | haskell-92257abd4b64f0496204adb19462d05c1d6475e3.tar.gz |
Link with libm dynamically (#19877)
The compiler should be independent of the target.
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/GHC/Linker/Dynamic.hs | 16 | ||||
-rw-r--r-- | compiler/GHC/Linker/Static.hs | 2 | ||||
-rw-r--r-- | compiler/GHC/Platform.hs | 6 | ||||
-rw-r--r-- | compiler/GHC/Settings/IO.hs | 2 |
4 files changed, 16 insertions, 10 deletions
diff --git a/compiler/GHC/Linker/Dynamic.hs b/compiler/GHC/Linker/Dynamic.hs index e8c31a1f20..3eca65c6cc 100644 --- a/compiler/GHC/Linker/Dynamic.hs +++ b/compiler/GHC/Linker/Dynamic.hs @@ -197,7 +197,8 @@ linkDynLib logger tmpfs dflags0 unit_env o_files dep_packages ------------------------------------------------------------------- let output_fn = case o_file of { Just s -> s; Nothing -> "a.out"; } - unregisterised = platformUnregisterised (targetPlatform dflags) + platform = targetPlatform dflags + unregisterised = platformUnregisterised platform let bsymbolicFlag = -- we need symbolic linking to resolve -- non-PIC intra-package-relocations for -- performance (where symbolic linking works) @@ -206,7 +207,7 @@ linkDynLib logger tmpfs dflags0 unit_env o_files dep_packages runLink logger tmpfs dflags ( map Option verbFlags - ++ libmLinkOpts + ++ libmLinkOpts platform ++ [ Option "-o" , FileOption "" output_fn ] @@ -224,13 +225,10 @@ linkDynLib logger tmpfs dflags0 unit_env o_files dep_packages -- | Some platforms require that we explicitly link against @libm@ if any -- math-y things are used (which we assume to include all programs). See #14022. -libmLinkOpts :: [Option] -libmLinkOpts = -#if defined(HAVE_LIBM) - [Option "-lm"] -#else - [] -#endif +libmLinkOpts :: Platform -> [Option] +libmLinkOpts platform + | platformHasLibm platform = [Option "-lm"] + | otherwise = [] {- Note [-Bsymbolic assumptions by GHC] diff --git a/compiler/GHC/Linker/Static.hs b/compiler/GHC/Linker/Static.hs index c4549d5274..ed67daa347 100644 --- a/compiler/GHC/Linker/Static.hs +++ b/compiler/GHC/Linker/Static.hs @@ -197,7 +197,7 @@ linkBinary' staticLink logger tmpfs dflags unit_env o_files dep_units = do ++ [ GHC.SysTools.Option "-o" , GHC.SysTools.FileOption "" output_fn ] - ++ libmLinkOpts + ++ libmLinkOpts platform ++ map GHC.SysTools.Option ( [] diff --git a/compiler/GHC/Platform.hs b/compiler/GHC/Platform.hs index b3f5bf830c..9bebcc5990 100644 --- a/compiler/GHC/Platform.hs +++ b/compiler/GHC/Platform.hs @@ -74,6 +74,11 @@ data Platform = Platform -- ^ Determines whether we will be compiling info tables that reside just -- before the entry code, or with an indirection to the entry code. See -- TABLES_NEXT_TO_CODE in rts/include/rts/storage/InfoTables.h. + , platformHasLibm :: !Bool + -- ^ Some platforms require that we explicitly link against @libm@ if any + -- math-y things are used (which we assume to include all programs). See + -- #14022. + , platform_constants :: !(Maybe PlatformConstants) -- ^ Constants such as structure offsets, type sizes, etc. } @@ -93,6 +98,7 @@ genericPlatform = Platform , platformHasGnuNonexecStack = False , platformHasIdentDirective = False , platformHasSubsectionsViaSymbols= False + , platformHasLibm = False , platformIsCrossCompiling = False , platformLeadingUnderscore = False , platformTablesNextToCode = True diff --git a/compiler/GHC/Settings/IO.hs b/compiler/GHC/Settings/IO.hs index 3c4e012675..49dd910d43 100644 --- a/compiler/GHC/Settings/IO.hs +++ b/compiler/GHC/Settings/IO.hs @@ -235,6 +235,7 @@ getTargetPlatform settingsFile settings = do targetHasGnuNonexecStack <- getBooleanSetting "target has GNU nonexec stack" targetHasIdentDirective <- getBooleanSetting "target has .ident directive" targetHasSubsectionsViaSymbols <- getBooleanSetting "target has subsections via symbols" + targetHasLibm <- getBooleanSetting "target has libm" crossCompiling <- getBooleanSetting "cross compiling" tablesNextToCode <- getBooleanSetting "Tables next to code" @@ -249,5 +250,6 @@ getTargetPlatform settingsFile settings = do , platformIsCrossCompiling = crossCompiling , platformLeadingUnderscore = targetLeadingUnderscore , platformTablesNextToCode = tablesNextToCode + , platformHasLibm = targetHasLibm , platform_constants = Nothing -- will be filled later when loading (or building) the RTS unit } |