Rodrigo Mesquita pushed to branch wip/romes/26227 at Glasgow Haskell Compiler / GHC
Commits:
-
cb228d86
by Rodrigo Mesquita at 2025-07-25T17:06:08+01:00
-
562b2551
by Rodrigo Mesquita at 2025-07-25T17:06:12+01:00
-
ea6f901b
by Rodrigo Mesquita at 2025-07-25T17:06:15+01:00
-
4754b0fd
by Rodrigo Mesquita at 2025-07-25T17:06:16+01:00
-
059c5ac3
by Rodrigo Mesquita at 2025-07-25T17:06:16+01:00
19 changed files:
- compiler/GHC/Driver/Session.hs
- compiler/GHC/Settings/IO.hs
- hadrian/bindist/Makefile
- hadrian/bindist/config.mk.in
- hadrian/cfg/default.host.target.in
- hadrian/cfg/default.target.in
- hadrian/cfg/system.config.in
- hadrian/src/Oracles/Flag.hs
- hadrian/src/Oracles/Setting.hs
- hadrian/src/Rules/Generate.hs
- hadrian/src/Settings/Packages.hs
- m4/fp_find_libdw.m4
- m4/ghc_toolchain.m4
- m4/prep_target_file.m4
- utils/ghc-toolchain/exe/Main.hs
- utils/ghc-toolchain/ghc-toolchain.cabal
- + utils/ghc-toolchain/src/GHC/Toolchain/Library.hs
- utils/ghc-toolchain/src/GHC/Toolchain/PlatformDetails.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Target.hs
Changes:
| ... | ... | @@ -3498,8 +3498,10 @@ compilerInfo dflags |
| 3498 | 3498 | ("target word size", query $ show . wordSize2Bytes . tgtWordSize),
|
| 3499 | 3499 | ("target word big endian", queryBool $ (\case BigEndian -> True; LittleEndian -> False) . tgtEndianness),
|
| 3500 | 3500 | ("target has GNU nonexec stack", queryBool tgtSupportsGnuNonexecStack),
|
| 3501 | + ("target has libm", queryBool tgtHasLibm),
|
|
| 3501 | 3502 | ("target has .ident directive", queryBool tgtSupportsIdentDirective),
|
| 3502 | 3503 | ("target has subsections via symbols", queryBool tgtSupportsSubsectionsViaSymbols),
|
| 3504 | + ("target RTS linker only supports shared libraries", queryBool tgtRTSLinkerOnlySupportsSharedLibs)
|
|
| 3503 | 3505 | ("Unregisterised", queryBool tgtUnregisterised),
|
| 3504 | 3506 | ("LLVM target", query tgtLlvmTarget),
|
| 3505 | 3507 | ("LLVM llc command", queryCmdMaybe id tgtLlc),
|
| ... | ... | @@ -3507,7 +3509,8 @@ compilerInfo dflags |
| 3507 | 3509 | ("LLVM llvm-as command", queryCmdMaybe id tgtLlvmAs),
|
| 3508 | 3510 | ("LLVM llvm-as flags", queryFlagsMaybe id tgtLlvmAs),
|
| 3509 | 3511 | ("Tables next to code", queryBool tgtTablesNextToCode),
|
| 3510 | - ("Leading underscore", queryBool tgtSymbolsHaveLeadingUnderscore)
|
|
| 3512 | + ("Leading underscore", queryBool tgtSymbolsHaveLeadingUnderscore),
|
|
| 3513 | + ("RTS expects libdw", queryBool (isJust . tgtRTSWithLibdw))
|
|
| 3511 | 3514 | ] ++
|
| 3512 | 3515 | [("Project version", projectVersion dflags),
|
| 3513 | 3516 | ("Project Git commit id", cProjectGitCommitId),
|
| ... | ... | @@ -3525,6 +3528,9 @@ compilerInfo dflags |
| 3525 | 3528 | ("target os string", stringEncodeOS (platformOS (targetPlatform dflags))),
|
| 3526 | 3529 | ("target arch string", stringEncodeArch (platformArch (targetPlatform dflags))),
|
| 3527 | 3530 | ("target word size in bits", show (platformWordSizeInBits (targetPlatform dflags))),
|
| 3531 | + -- keep "duplicate" of "Have interpreter" for backwards compatibility,
|
|
| 3532 | + -- since we used to show both...
|
|
| 3533 | + ("Use interpreter", showBool $ platformMisc_ghcWithInterpreter $ platformMisc dflags),
|
|
| 3528 | 3534 | ("Have interpreter", showBool $ platformMisc_ghcWithInterpreter $ platformMisc dflags),
|
| 3529 | 3535 | ("Object splitting supported", showBool False),
|
| 3530 | 3536 | ("Have native code generator", showBool $ platformNcgSupported platform),
|
| ... | ... | @@ -3544,6 +3550,7 @@ compilerInfo dflags |
| 3544 | 3550 | -- If true, we require that the 'id' field in installed package info
|
| 3545 | 3551 | -- match what is passed to the @-this-unit-id@ flag for modules
|
| 3546 | 3552 | -- built in it
|
| 3553 | + ("Support SMP", queryBool tgtSupportsSMP),
|
|
| 3547 | 3554 | ("Requires unified installed package IDs", "YES"),
|
| 3548 | 3555 | -- Whether or not we support the @-this-package-key@ flag. Prefer
|
| 3549 | 3556 | -- "Uses unit IDs" over it. We still say yes even if @-this-package-key@
|
| ... | ... | @@ -97,10 +97,6 @@ initSettings top_dir = do |
| 97 | 97 | getTool :: (Target -> Program) -> (String, [String])
|
| 98 | 98 | getTool key = (getToolPath key, getToolFlags key)
|
| 99 | 99 | |
| 100 | - -- See Note [Settings file] for a little more about this file. We're
|
|
| 101 | - -- just partially applying those functions and throwing 'Left's; they're
|
|
| 102 | - -- written in a very portable style to keep ghc-boot light.
|
|
| 103 | - targetHasLibm <- getBooleanSetting "target has libm"
|
|
| 104 | 100 | let
|
| 105 | 101 | (cc_prog, cc_args0) = getTool (ccProgram . tgtCCompiler)
|
| 106 | 102 | (cxx_prog, cxx_args) = getTool (cxxProgram . tgtCxxCompiler)
|
| ... | ... | @@ -109,7 +105,7 @@ initSettings top_dir = do |
| 109 | 105 | (js_cpp_prog, js_cpp_args) = getTool (maybe (Program "" []) jsCppProgram . tgtJsCPreprocessor)
|
| 110 | 106 | (cmmCpp_prog, cmmCpp_args) = getTool (cmmCppProgram . tgtCmmCPreprocessor)
|
| 111 | 107 | |
| 112 | - platform = getTargetPlatform targetHasLibm target
|
|
| 108 | + platform = getTargetPlatform target
|
|
| 113 | 109 | |
| 114 | 110 | unreg_cc_args = if platformUnregisterised platform
|
| 115 | 111 | then ["-DNO_REGS", "-DUSE_MINIINTERPRETER"]
|
| ... | ... | @@ -150,7 +146,6 @@ initSettings top_dir = do |
| 150 | 146 | pure (ld_r_path, map Option ld_r_args)
|
| 151 | 147 | iserv_prog = libexec "ghc-iserv"
|
| 152 | 148 | |
| 153 | - targetRTSLinkerOnlySupportsSharedLibs <- getBooleanSetting "target RTS linker only supports shared libraries"
|
|
| 154 | 149 | ghcWithInterpreter <- getBooleanSetting "Use interpreter"
|
| 155 | 150 | |
| 156 | 151 | baseUnitId <- getSetting_raw "base unit-id"
|
| ... | ... | @@ -235,15 +230,15 @@ initSettings top_dir = do |
| 235 | 230 | , platformMisc_ghcWithInterpreter = ghcWithInterpreter
|
| 236 | 231 | , platformMisc_libFFI = tgtUseLibffiForAdjustors target
|
| 237 | 232 | , platformMisc_llvmTarget = tgtLlvmTarget target
|
| 238 | - , platformMisc_targetRTSLinkerOnlySupportsSharedLibs = targetRTSLinkerOnlySupportsSharedLibs
|
|
| 233 | + , platformMisc_targetRTSLinkerOnlySupportsSharedLibs = tgtRTSLinkerOnlySupportsSharedLibs target
|
|
| 239 | 234 | }
|
| 240 | 235 | |
| 241 | 236 | , sRawSettings = settingsList
|
| 242 | 237 | , sRawTarget = target
|
| 243 | 238 | }
|
| 244 | 239 | |
| 245 | -getTargetPlatform :: Bool {-^ Does target have libm -} -> Target -> Platform
|
|
| 246 | -getTargetPlatform targetHasLibm Target{..} = Platform
|
|
| 240 | +getTargetPlatform :: Target -> Platform
|
|
| 241 | +getTargetPlatform Target{..} = Platform
|
|
| 247 | 242 | { platformArchOS = tgtArchOs
|
| 248 | 243 | , platformWordSize = case tgtWordSize of WS4 -> PW4
|
| 249 | 244 | WS8 -> PW8
|
| ... | ... | @@ -255,6 +250,6 @@ getTargetPlatform targetHasLibm Target{..} = Platform |
| 255 | 250 | , platformIsCrossCompiling = not tgtLocallyExecutable
|
| 256 | 251 | , platformLeadingUnderscore = tgtSymbolsHaveLeadingUnderscore
|
| 257 | 252 | , platformTablesNextToCode = tgtTablesNextToCode
|
| 258 | - , platformHasLibm = targetHasLibm
|
|
| 253 | + , platformHasLibm = tgtHasLibm
|
|
| 259 | 254 | , platform_constants = Nothing -- will be filled later when loading (or building) the RTS unit
|
| 260 | 255 | } |
| ... | ... | @@ -85,13 +85,9 @@ WrapperBinsDir=${bindir} |
| 85 | 85 | # N.B. this is duplicated from includes/ghc.mk.
|
| 86 | 86 | lib/settings : config.mk
|
| 87 | 87 | @rm -f $@
|
| 88 | - @echo '[("target has libm", "$(TargetHasLibm)")' >> $@
|
|
| 89 | - @echo ',("unlit command", "$$topdir/../bin/$(CrossCompilePrefix)unlit")' >> $@
|
|
| 90 | - @echo ',("target RTS linker only supports shared libraries", "$(TargetRTSLinkerOnlySupportsSharedLibs)")' >> $@
|
|
| 88 | + @echo '[("unlit command", "$$topdir/../bin/$(CrossCompilePrefix)unlit")' >> $@
|
|
| 91 | 89 | @echo ',("Use interpreter", "$(GhcWithInterpreter)")' >> $@
|
| 92 | - @echo ',("Support SMP", "$(GhcWithSMP)")' >> $@
|
|
| 93 | 90 | @echo ',("RTS ways", "$(GhcRTSWays)")' >> $@
|
| 94 | - @echo ',("RTS expects libdw", "$(GhcRtsWithLibdw)")' >> $@
|
|
| 95 | 91 | @echo ',("Relative Global Package DB", "package.conf.d")' >> $@
|
| 96 | 92 | @echo ',("base unit-id", "$(BaseUnitId)")' >> $@
|
| 97 | 93 | @echo "]" >> $@
|
| ... | ... | @@ -172,7 +172,7 @@ UseLibffiForAdjustors=@UseLibffiForAdjustors@ |
| 172 | 172 | |
| 173 | 173 | # GHC needs arch-specific tweak at least in
|
| 174 | 174 | # rts/Libdw.c:set_initial_registers()
|
| 175 | -GhcRtsWithLibdw=$(strip $(if $(filter $(TargetArch_CPP),i386 x86_64 s390x),@UseLibdw@,NO))
|
|
| 175 | +UseLibdw=$(strip $(if $(filter $(TargetArch_CPP),i386 x86_64 s390x),@UseLibdw@,NO))
|
|
| 176 | 176 | |
| 177 | 177 | #-----------------------------------------------------------------------------
|
| 178 | 178 | # Settings
|
| ... | ... | @@ -12,6 +12,8 @@ Target |
| 12 | 12 | , tgtUnregisterised = False
|
| 13 | 13 | , tgtTablesNextToCode = True
|
| 14 | 14 | , tgtUseLibffiForAdjustors = True
|
| 15 | +, tgtHasLibm = True
|
|
| 16 | +, tgtRTSWithLibdw = Nothing
|
|
| 15 | 17 | , tgtCCompiler = Cc {ccProgram = Program {prgPath = "@CC_STAGE0@", prgFlags = @CONF_CC_OPTS_STAGE0List@}}
|
| 16 | 18 | , tgtCxxCompiler = Cxx {cxxProgram = Program {prgPath = "@CC_STAGE0@", prgFlags = @CONF_CXX_OPTS_STAGE0List@}}
|
| 17 | 19 | , tgtCPreprocessor = Cpp {cppProgram = Program {prgPath = "@CPPCmd_STAGE0@", prgFlags = @CONF_CPP_OPTS_STAGE0List@}}
|
| ... | ... | @@ -12,6 +12,8 @@ Target |
| 12 | 12 | , tgtUnregisterised = @UnregisterisedBool@
|
| 13 | 13 | , tgtTablesNextToCode = @TablesNextToCodeBool@
|
| 14 | 14 | , tgtUseLibffiForAdjustors = @UseLibffiForAdjustorsBool@
|
| 15 | +, tgtHasLibm = @TargetHasLibmBool@
|
|
| 16 | +, tgtRTSWithLibdw = @UseLibdwMaybeLibrary@
|
|
| 15 | 17 | , tgtCCompiler = Cc {ccProgram = Program {prgPath = "@CC@", prgFlags = @CONF_CC_OPTS_STAGE2List@}}
|
| 16 | 18 | , tgtCxxCompiler = Cxx {cxxProgram = Program {prgPath = "@CXX@", prgFlags = @CONF_CXX_OPTS_STAGE2List@}}
|
| 17 | 19 | , tgtCPreprocessor = Cpp {cppProgram = Program {prgPath = "@CPPCmd@", prgFlags = @CONF_CPP_OPTS_STAGE2List@}}
|
| ... | ... | @@ -81,8 +81,6 @@ project-git-commit-id = @ProjectGitCommitId@ |
| 81 | 81 | # See Note [tooldir: How GHC finds mingw on Windows]
|
| 82 | 82 | settings-use-distro-mingw = @EnableDistroToolchain@
|
| 83 | 83 | |
| 84 | -target-has-libm = @TargetHasLibm@
|
|
| 85 | - |
|
| 86 | 84 | # Include and library directories:
|
| 87 | 85 | #=================================
|
| 88 | 86 | |
| ... | ... | @@ -101,9 +99,6 @@ use-system-ffi = @UseSystemLibFFI@ |
| 101 | 99 | ffi-include-dir = @FFIIncludeDir@
|
| 102 | 100 | ffi-lib-dir = @FFILibDir@
|
| 103 | 101 | |
| 104 | -libdw-include-dir = @LibdwIncludeDir@
|
|
| 105 | -libdw-lib-dir = @LibdwLibDir@
|
|
| 106 | - |
|
| 107 | 102 | libnuma-include-dir = @LibNumaIncludeDir@
|
| 108 | 103 | libnuma-lib-dir = @LibNumaLibDir@
|
| 109 | 104 | |
| ... | ... | @@ -113,7 +108,6 @@ libzstd-lib-dir = @LibZstdLibDir@ |
| 113 | 108 | # Optional Dependencies:
|
| 114 | 109 | #=======================
|
| 115 | 110 | |
| 116 | -use-lib-dw = @UseLibdw@
|
|
| 117 | 111 | use-lib-zstd = @UseLibZstd@
|
| 118 | 112 | static-lib-zstd = @UseStaticLibZstd@
|
| 119 | 113 | use-lib-numa = @UseLibNuma@
|
| ... | ... | @@ -7,7 +7,7 @@ module Oracles.Flag ( |
| 7 | 7 | targetRTSLinkerOnlySupportsSharedLibs,
|
| 8 | 8 | targetSupportsThreadedRts,
|
| 9 | 9 | targetSupportsSMP,
|
| 10 | - useLibffiForAdjustors,
|
|
| 10 | + useLibffiForAdjustors, useLibdw,
|
|
| 11 | 11 | arSupportsDashL,
|
| 12 | 12 | arSupportsAtFile
|
| 13 | 13 | ) where
|
| ... | ... | @@ -29,7 +29,6 @@ data Flag = CrossCompiling |
| 29 | 29 | | UseSystemFfi
|
| 30 | 30 | | BootstrapThreadedRts
|
| 31 | 31 | | BootstrapEventLoggingRts
|
| 32 | - | UseLibdw
|
|
| 33 | 32 | | UseLibnuma
|
| 34 | 33 | | UseLibzstd
|
| 35 | 34 | | StaticLibzstd
|
| ... | ... | @@ -53,7 +52,6 @@ flag f = do |
| 53 | 52 | UseSystemFfi -> "use-system-ffi"
|
| 54 | 53 | BootstrapThreadedRts -> "bootstrap-threaded-rts"
|
| 55 | 54 | BootstrapEventLoggingRts -> "bootstrap-event-logging-rts"
|
| 56 | - UseLibdw -> "use-lib-dw"
|
|
| 57 | 55 | UseLibnuma -> "use-lib-numa"
|
| 58 | 56 | UseLibzstd -> "use-lib-zstd"
|
| 59 | 57 | StaticLibzstd -> "static-lib-zstd"
|
| ... | ... | @@ -82,23 +80,8 @@ platformSupportsGhciObjects = do |
| 82 | 80 | only_shared_libs <- targetRTSLinkerOnlySupportsSharedLibs
|
| 83 | 81 | pure $ has_merge_objs && not only_shared_libs
|
| 84 | 82 | |
| 85 | --- | Does the target RTS linker only support loading shared libraries?
|
|
| 86 | --- If true, this has several implications:
|
|
| 87 | --- 1. The GHC driver must not do loadArchive/loadObj etc and must
|
|
| 88 | --- always do loadDLL, regardless of whether host GHC is dynamic or
|
|
| 89 | --- not.
|
|
| 90 | --- 2. The GHC driver will always enable -dynamic-too when compiling
|
|
| 91 | --- vanilla way with TH codegen requirement.
|
|
| 92 | --- 3. ghci will always enforce dynamic ways even if -dynamic or
|
|
| 93 | --- -dynamic-too is not explicitly passed.
|
|
| 94 | --- 4. Cabal must not build ghci objects since it's not supported by
|
|
| 95 | --- the target.
|
|
| 96 | --- 5. The testsuite driver will use dyn way for TH/ghci tests even
|
|
| 97 | --- when host GHC is static.
|
|
| 98 | --- 6. TH/ghci doesn't work if stage1 is built without shared libraries
|
|
| 99 | --- (e.g. quickest/fully_static).
|
|
| 100 | 83 | targetRTSLinkerOnlySupportsSharedLibs :: Action Bool
|
| 101 | -targetRTSLinkerOnlySupportsSharedLibs = anyTargetArch [ ArchWasm32 ]
|
|
| 84 | +targetRTSLinkerOnlySupportsSharedLibs = queryTargetTarget Toolchain.tgtRTSLinkerOnlySupportsSharedLibs
|
|
| 102 | 85 | |
| 103 | 86 | arSupportsDashL :: Stage -> Action Bool
|
| 104 | 87 | arSupportsDashL stage = Toolchain.arSupportsDashL . tgtAr <$> targetStage stage
|
| ... | ... | @@ -123,27 +106,10 @@ targetSupportsThreadedRts = do |
| 123 | 106 | |
| 124 | 107 | -- | Does the target support the -N RTS flag?
|
| 125 | 108 | targetSupportsSMP :: Action Bool
|
| 126 | -targetSupportsSMP = do
|
|
| 127 | - unreg <- queryTargetTarget tgtUnregisterised
|
|
| 128 | - armVer <- targetArmVersion
|
|
| 129 | - goodArch <- (||) <$>
|
|
| 130 | - anyTargetArch [ ArchX86
|
|
| 131 | - , ArchX86_64
|
|
| 132 | - , ArchPPC
|
|
| 133 | - , ArchPPC_64 ELF_V1
|
|
| 134 | - , ArchPPC_64 ELF_V2
|
|
| 135 | - , ArchAArch64
|
|
| 136 | - , ArchS390X
|
|
| 137 | - , ArchRISCV64
|
|
| 138 | - , ArchLoongArch64 ] <*> isArmTarget
|
|
| 139 | - if -- The THREADED_RTS requires `BaseReg` to be in a register and the
|
|
| 140 | - -- Unregisterised mode doesn't allow that.
|
|
| 141 | - | unreg -> return False
|
|
| 142 | - -- We don't support load/store barriers pre-ARMv7. See #10433.
|
|
| 143 | - | Just ver <- armVer
|
|
| 144 | - , ver < ARMv7 -> return False
|
|
| 145 | - | goodArch -> return True
|
|
| 146 | - | otherwise -> return False
|
|
| 109 | +targetSupportsSMP = queryTargetTarget Toolchain.tgtSupportsSMP
|
|
| 147 | 110 | |
| 148 | 111 | useLibffiForAdjustors :: Action Bool
|
| 149 | 112 | useLibffiForAdjustors = queryTargetTarget tgtUseLibffiForAdjustors
|
| 113 | + |
|
| 114 | +useLibdw :: Action Bool
|
|
| 115 | +useLibdw = queryTargetTarget (isJust . tgtRTSWithLibdw) |
| ... | ... | @@ -54,8 +54,6 @@ data Setting = CursesIncludeDir |
| 54 | 54 | | GmpLibDir
|
| 55 | 55 | | IconvIncludeDir
|
| 56 | 56 | | IconvLibDir
|
| 57 | - | LibdwIncludeDir
|
|
| 58 | - | LibdwLibDir
|
|
| 59 | 57 | | LibnumaIncludeDir
|
| 60 | 58 | | LibnumaLibDir
|
| 61 | 59 | | LibZstdIncludeDir
|
| ... | ... | @@ -94,8 +92,6 @@ setting key = lookupSystemConfig $ case key of |
| 94 | 92 | GmpLibDir -> "gmp-lib-dir"
|
| 95 | 93 | IconvIncludeDir -> "iconv-include-dir"
|
| 96 | 94 | IconvLibDir -> "iconv-lib-dir"
|
| 97 | - LibdwIncludeDir -> "libdw-include-dir"
|
|
| 98 | - LibdwLibDir -> "libdw-lib-dir"
|
|
| 99 | 95 | LibnumaIncludeDir -> "libnuma-include-dir"
|
| 100 | 96 | LibnumaLibDir -> "libnuma-lib-dir"
|
| 101 | 97 | LibZstdIncludeDir -> "libzstd-include-dir"
|
| ... | ... | @@ -432,7 +432,7 @@ bindistRules = do |
| 432 | 432 | , interpolateVar "TargetWordBigEndian" $ getTarget isBigEndian
|
| 433 | 433 | , interpolateVar "TargetWordSize" $ getTarget wordSize
|
| 434 | 434 | , interpolateVar "Unregisterised" $ yesNo <$> getTarget tgtUnregisterised
|
| 435 | - , interpolateVar "UseLibdw" $ fmap yesNo $ interp $ getFlag UseLibdw
|
|
| 435 | + , interpolateVar "UseLibdw" $ yesNo <$> getTarget (isJust . tgtRTSWithLibdw)
|
|
| 436 | 436 | , interpolateVar "UseLibffiForAdjustors" $ yesNo <$> getTarget tgtUseLibffiForAdjustors
|
| 437 | 437 | , interpolateVar "GhcWithSMP" $ yesNo <$> targetSupportsSMP
|
| 438 | 438 | , interpolateVar "BaseUnitId" $ pkgUnitId Stage1 base
|
| ... | ... | @@ -484,12 +484,8 @@ generateSettings settingsFile = do |
| 484 | 484 | |
| 485 | 485 | settings <- traverse sequence $
|
| 486 | 486 | [ ("unlit command", ("$topdir/../bin/" <>) <$> expr (programName (ctx { Context.package = unlit })))
|
| 487 | - , ("target has libm", expr $ lookupSystemConfig "target-has-libm")
|
|
| 488 | - , ("target RTS linker only supports shared libraries", expr $ yesNo <$> targetRTSLinkerOnlySupportsSharedLibs)
|
|
| 489 | 487 | , ("Use interpreter", expr $ yesNo <$> ghcWithInterpreter (predStage stage))
|
| 490 | - , ("Support SMP", expr $ yesNo <$> targetSupportsSMP)
|
|
| 491 | 488 | , ("RTS ways", escapeArgs . map show . Set.toList <$> getRtsWays)
|
| 492 | - , ("RTS expects libdw", yesNo <$> getFlag UseLibdw)
|
|
| 493 | 489 | , ("Relative Global Package DB", pure rel_pkg_db)
|
| 494 | 490 | , ("base unit-id", pure base_unit_id)
|
| 495 | 491 | ]
|
| ... | ... | @@ -8,6 +8,7 @@ import Packages |
| 8 | 8 | import Settings
|
| 9 | 9 | import Settings.Builders.Common (wayCcArgs)
|
| 10 | 10 | |
| 11 | +import qualified GHC.Toolchain.Library as Lib
|
|
| 11 | 12 | import GHC.Toolchain.Target
|
| 12 | 13 | import GHC.Platform.ArchOS
|
| 13 | 14 | import Data.Version.Extra
|
| ... | ... | @@ -304,8 +305,8 @@ rtsPackageArgs = package rts ? do |
| 304 | 305 | useSystemFfi <- getFlag UseSystemFfi
|
| 305 | 306 | ffiIncludeDir <- getSetting FfiIncludeDir
|
| 306 | 307 | ffiLibraryDir <- getSetting FfiLibDir
|
| 307 | - libdwIncludeDir <- getSetting LibdwIncludeDir
|
|
| 308 | - libdwLibraryDir <- getSetting LibdwLibDir
|
|
| 308 | + libdwIncludeDir <- queryTarget (Lib.includePath <=< tgtRTSWithLibdw)
|
|
| 309 | + libdwLibraryDir <- queryTarget (Lib.libraryPath <=< tgtRTSWithLibdw)
|
|
| 309 | 310 | libnumaIncludeDir <- getSetting LibnumaIncludeDir
|
| 310 | 311 | libnumaLibraryDir <- getSetting LibnumaLibDir
|
| 311 | 312 | libzstdIncludeDir <- getSetting LibZstdIncludeDir
|
| ... | ... | @@ -443,7 +444,7 @@ rtsPackageArgs = package rts ? do |
| 443 | 444 | , flag UseLibpthread `cabalFlag` "need-pthread"
|
| 444 | 445 | , flag UseLibbfd `cabalFlag` "libbfd"
|
| 445 | 446 | , flag NeedLibatomic `cabalFlag` "need-atomic"
|
| 446 | - , flag UseLibdw `cabalFlag` "libdw"
|
|
| 447 | + , useLibdw `cabalFlag` "libdw"
|
|
| 447 | 448 | , flag UseLibnuma `cabalFlag` "libnuma"
|
| 448 | 449 | , flag UseLibzstd `cabalFlag` "libzstd"
|
| 449 | 450 | , flag StaticLibzstd `cabalFlag` "static-libzstd"
|
| ... | ... | @@ -453,7 +454,7 @@ rtsPackageArgs = package rts ? do |
| 453 | 454 | , Debug `wayUnit` way `cabalFlag` "find-ptr"
|
| 454 | 455 | ]
|
| 455 | 456 | , builder (Cabal Setup) ? mconcat
|
| 456 | - [ cabalExtraDirs libdwIncludeDir libdwLibraryDir
|
|
| 457 | + [ useLibdw ? cabalExtraDirs (fromMaybe "" libdwIncludeDir) (fromMaybe "" libdwLibraryDir)
|
|
| 457 | 458 | , cabalExtraDirs libnumaIncludeDir libnumaLibraryDir
|
| 458 | 459 | , cabalExtraDirs libzstdIncludeDir libzstdLibraryDir
|
| 459 | 460 | , useSystemFfi ? cabalExtraDirs ffiIncludeDir ffiLibraryDir
|
| ... | ... | @@ -467,7 +468,7 @@ rtsPackageArgs = package rts ? do |
| 467 | 468 | , builder HsCpp ? pure
|
| 468 | 469 | [ "-DTOP=" ++ show top ]
|
| 469 | 470 | |
| 470 | - , builder HsCpp ? flag UseLibdw ? arg "-DUSE_LIBDW" ]
|
|
| 471 | + , builder HsCpp ? useLibdw ? arg "-DUSE_LIBDW" ]
|
|
| 471 | 472 | |
| 472 | 473 | -- Compile various performance-critical pieces *without* -fPIC -dynamic
|
| 473 | 474 | -- even when building a shared library. If we don't do this, then the
|
| ... | ... | @@ -29,11 +29,11 @@ AC_DEFUN([FP_FIND_LIBDW], |
| 29 | 29 | AC_ARG_ENABLE(dwarf-unwind,
|
| 30 | 30 | [AS_HELP_STRING([--enable-dwarf-unwind],
|
| 31 | 31 | [Enable DWARF unwinding support in the runtime system via elfutils' libdw [default=no]])],
|
| 32 | - [],
|
|
| 33 | - [enable_dwarf_unwind=no])
|
|
| 32 | + [FP_CAPITALIZE_YES_NO(["$enableval"], [enable_dwarf_unwind])],
|
|
| 33 | + [enable_dwarf_unwind=NO])
|
|
| 34 | 34 | |
| 35 | 35 | UseLibdw=NO
|
| 36 | - if test "$enable_dwarf_unwind" != "no" ; then
|
|
| 36 | + if test "$enable_dwarf_unwind" != "NO" ; then
|
|
| 37 | 37 | CFLAGS2="$CFLAGS"
|
| 38 | 38 | CFLAGS="$LIBDW_CFLAGS $CFLAGS"
|
| 39 | 39 | LDFLAGS2="$LDFLAGS"
|
| ... | ... | @@ -43,7 +43,7 @@ AC_DEFUN([FP_FIND_LIBDW], |
| 43 | 43 | [AC_CHECK_LIB(dw, dwfl_attach_state,
|
| 44 | 44 | [UseLibdw=YES])])
|
| 45 | 45 | |
| 46 | - if test "x:$enable_dwarf_unwind:$UseLibdw" = "x:yes:NO" ; then
|
|
| 46 | + if test "x:$enable_dwarf_unwind:$UseLibdw" = "x:YES:NO" ; then
|
|
| 47 | 47 | AC_MSG_ERROR([Cannot find system libdw (required by --enable-dwarf-unwind)])
|
| 48 | 48 | fi
|
| 49 | 49 |
| ... | ... | @@ -120,6 +120,7 @@ AC_DEFUN([FIND_GHC_TOOLCHAIN], |
| 120 | 120 | ENABLE_GHC_TOOLCHAIN_ARG([tables-next-to-code], [$TablesNextToCode])
|
| 121 | 121 | ENABLE_GHC_TOOLCHAIN_ARG([ld-override], [$enable_ld_override])
|
| 122 | 122 | ENABLE_GHC_TOOLCHAIN_ARG([libffi-adjustors], [$UseLibffiForAdjustors])
|
| 123 | + ENABLE_GHC_TOOLCHAIN_ARG([dwarf-unwind], [$enable_dwarf_unwind])
|
|
| 123 | 124 | |
| 124 | 125 | dnl We store USER_* variants of all user-specified flags to pass them over to ghc-toolchain.
|
| 125 | 126 | ADD_GHC_TOOLCHAIN_ARG_CHOOSE([cc-opt], [$USER_CONF_CC_OPTS_STAGE2], [$USER_CFLAGS])
|
| ... | ... | @@ -130,6 +131,8 @@ AC_DEFUN([FIND_GHC_TOOLCHAIN], |
| 130 | 131 | ADD_GHC_TOOLCHAIN_ARG([hs-cpp-opt], [$USER_HS_CPP_ARGS])
|
| 131 | 132 | ADD_GHC_TOOLCHAIN_ARG([js-cpp-opt], [$USER_JS_CPP_ARGS])
|
| 132 | 133 | ADD_GHC_TOOLCHAIN_ARG([cmm-cpp-opt], [$USER_CMM_CPP_ARGS])
|
| 134 | + ADD_GHC_TOOLCHAIN_ARG([libdw-includes], [$LibdwIncludeDir])
|
|
| 135 | + ADD_GHC_TOOLCHAIN_ARG([libdw-libraries], [$LibdwLibDir])
|
|
| 133 | 136 | |
| 134 | 137 | INVOKE_GHC_TOOLCHAIN()
|
| 135 | 138 |
| ... | ... | @@ -78,6 +78,22 @@ AC_DEFUN([PREP_MAYBE_PROGRAM],[ |
| 78 | 78 | AC_SUBST([$1MaybeProg])
|
| 79 | 79 | ])
|
| 80 | 80 | |
| 81 | +# PREP_MAYBE_LIBRARY
|
|
| 82 | +# =========================
|
|
| 83 | +#
|
|
| 84 | +# Introduce a substitution [$1MaybeProg] with
|
|
| 85 | +# * Nothing, if $$1 is empty or "NO"
|
|
| 86 | +# * Just the library otherwise
|
|
| 87 | +AC_DEFUN([PREP_MAYBE_LIBRARY],[
|
|
| 88 | + if test -z "$$1" || test "$$1" = "NO"; then
|
|
| 89 | + $1MaybeLibrary=Nothing
|
|
| 90 | + else
|
|
| 91 | + PREP_LIST([$2])
|
|
| 92 | + $1MaybeLibrary="Just (Library { libName = \"$2\", includePath = \"$3\", libraryPath = \"$4\" })"
|
|
| 93 | + fi
|
|
| 94 | + AC_SUBST([$1MaybeLibrary])
|
|
| 95 | +])
|
|
| 96 | + |
|
| 81 | 97 | # PREP_MAYBE_STRING
|
| 82 | 98 | # =========================
|
| 83 | 99 | #
|
| ... | ... | @@ -157,6 +173,7 @@ AC_DEFUN([PREP_TARGET_FILE],[ |
| 157 | 173 | PREP_BOOLEAN([Unregisterised])
|
| 158 | 174 | PREP_BOOLEAN([TablesNextToCode])
|
| 159 | 175 | PREP_BOOLEAN([UseLibffiForAdjustors])
|
| 176 | + PREP_BOOLEAN([TargetHasLibm])
|
|
| 160 | 177 | PREP_BOOLEAN([ArIsGNUAr])
|
| 161 | 178 | PREP_BOOLEAN([ArNeedsRanLib])
|
| 162 | 179 | PREP_NOT_BOOLEAN([CrossCompiling])
|
| ... | ... | @@ -179,6 +196,10 @@ AC_DEFUN([PREP_TARGET_FILE],[ |
| 179 | 196 | PREP_LIST([CONF_CXX_OPTS_STAGE2])
|
| 180 | 197 | PREP_LIST([CONF_CC_OPTS_STAGE2])
|
| 181 | 198 | |
| 199 | + PREP_MAYBE_STRING([LibdwIncludeDir])
|
|
| 200 | + PREP_MAYBE_STRING([LibdwLibDir])
|
|
| 201 | + PREP_MAYBE_LIBRARY([UseLibdw], [dw], [$LibdwIncludeDirMaybeStr], [$LibdwLibDirMaybeStr])
|
|
| 202 | + |
|
| 182 | 203 | dnl Host target
|
| 183 | 204 | PREP_BOOLEAN([ArSupportsAtFile_STAGE0])
|
| 184 | 205 | PREP_BOOLEAN([ArSupportsDashL_STAGE0])
|
| ... | ... | @@ -188,7 +209,6 @@ AC_DEFUN([PREP_TARGET_FILE],[ |
| 188 | 209 | PREP_LIST([CONF_CXX_OPTS_STAGE0])
|
| 189 | 210 | PREP_LIST([CONF_GCC_LINKER_OPTS_STAGE0])
|
| 190 | 211 | |
| 191 | - |
|
| 192 | 212 | if test -z "$MergeObjsCmd"; then
|
| 193 | 213 | MergeObjsCmdMaybe=Nothing
|
| 194 | 214 | else
|
| ... | ... | @@ -62,6 +62,12 @@ data Opts = Opts |
| 62 | 62 | -- see #23857 and #22550 for the very unfortunate story.
|
| 63 | 63 | , optLd :: ProgOpt
|
| 64 | 64 | , optUnregisterised :: Maybe Bool
|
| 65 | + |
|
| 66 | + -- dwarf unwinding
|
|
| 67 | + , optDwarfUnwind :: Maybe Bool
|
|
| 68 | + , optLibdwIncludes :: Maybe FilePath
|
|
| 69 | + , optLibdwLibraries :: Maybe FilePath
|
|
| 70 | + |
|
| 65 | 71 | , optTablesNextToCode :: Maybe Bool
|
| 66 | 72 | , optUseLibFFIForAdjustors :: Maybe Bool
|
| 67 | 73 | , optLdOverride :: Maybe Bool
|
| ... | ... | @@ -112,6 +118,9 @@ emptyOpts = Opts |
| 112 | 118 | , optOtool = po0
|
| 113 | 119 | , optInstallNameTool = po0
|
| 114 | 120 | , optUnregisterised = Nothing
|
| 121 | + , optDwarfUnwind = Nothing
|
|
| 122 | + , optLibdwIncludes = Nothing
|
|
| 123 | + , optLibdwLibraries = Nothing
|
|
| 115 | 124 | , optTablesNextToCode = Nothing
|
| 116 | 125 | , optUseLibFFIForAdjustors = Nothing
|
| 117 | 126 | , optLdOverride = Nothing
|
| ... | ... | @@ -157,13 +166,18 @@ _optOutput = Lens optOutput (\x o -> o {optOutput=x}) |
| 157 | 166 | _optTargetPrefix :: Lens Opts (Maybe String)
|
| 158 | 167 | _optTargetPrefix = Lens optTargetPrefix (\x o -> o {optTargetPrefix=x})
|
| 159 | 168 | |
| 160 | -_optLocallyExecutable, _optUnregisterised, _optTablesNextToCode, _optUseLibFFIForAdjustors, _optLdOvveride :: Lens Opts (Maybe Bool)
|
|
| 169 | +_optLocallyExecutable, _optUnregisterised, _optTablesNextToCode, _optUseLibFFIForAdjustors, _optLdOvveride, _optDwarfUnwind :: Lens Opts (Maybe Bool)
|
|
| 161 | 170 | _optLocallyExecutable = Lens optLocallyExecutable (\x o -> o {optLocallyExecutable=x})
|
| 162 | 171 | _optUnregisterised = Lens optUnregisterised (\x o -> o {optUnregisterised=x})
|
| 172 | +_optDwarfUnwind = Lens optDwarfUnwind (\x o -> o {optDwarfUnwind=x})
|
|
| 163 | 173 | _optTablesNextToCode = Lens optTablesNextToCode (\x o -> o {optTablesNextToCode=x})
|
| 164 | 174 | _optUseLibFFIForAdjustors = Lens optUseLibFFIForAdjustors (\x o -> o {optUseLibFFIForAdjustors=x})
|
| 165 | 175 | _optLdOvveride = Lens optLdOverride (\x o -> o {optLdOverride=x})
|
| 166 | 176 | |
| 177 | +_optLibdwIncludes, _optLibdwLibraries :: Lens Opts (Maybe FilePath)
|
|
| 178 | +_optLibdwIncludes = Lens optLibdwIncludes (\x o -> o {optLibdwIncludes=x})
|
|
| 179 | +_optLibdwLibraries = Lens optLibdwLibraries (\x o -> o {optLibdwLibraries=x})
|
|
| 180 | + |
|
| 167 | 181 | _optVerbosity :: Lens Opts Int
|
| 168 | 182 | _optVerbosity = Lens optVerbosity (\x o -> o {optVerbosity=x})
|
| 169 | 183 | |
| ... | ... | @@ -185,6 +199,7 @@ options = |
| 185 | 199 | , enableDisable "libffi-adjustors" "the use of libffi for adjustors, even on platforms which have support for more efficient, native adjustor implementations." _optUseLibFFIForAdjustors
|
| 186 | 200 | , enableDisable "ld-override" "override gcc's default linker" _optLdOvveride
|
| 187 | 201 | , enableDisable "locally-executable" "the use of a target prefix which will be added to all tool names when searching for toolchain components" _optLocallyExecutable
|
| 202 | + , enableDisable "dwarf-unwind" "Enable DWARF unwinding support in the runtime system via elfutils' libdw" _optDwarfUnwind
|
|
| 188 | 203 | ] ++
|
| 189 | 204 | concat
|
| 190 | 205 | [ progOpts "cc" "C compiler" _optCc
|
| ... | ... | @@ -206,6 +221,9 @@ options = |
| 206 | 221 | , progOpts "ld" "linker" _optLd
|
| 207 | 222 | , progOpts "otool" "otool utility" _optOtool
|
| 208 | 223 | , progOpts "install-name-tool" "install-name-tool utility" _optInstallNameTool
|
| 224 | + ] ++
|
|
| 225 | + [ Option [] ["libdw-includes"] (ReqArg (set _optLibdwIncludes . Just) "PATH") "Look for libdw headers in this extra path"
|
|
| 226 | + , Option [] ["libdw-libraries"] (ReqArg (set _optLibdwLibraries . Just) "PATH") "Look for the libdw library in this extra path"
|
|
| 209 | 227 | ]
|
| 210 | 228 | where
|
| 211 | 229 | progOpts :: String -> String -> Lens Opts ProgOpt -> [OptDescr (Opts -> Opts)]
|
| ... | ... | @@ -486,6 +504,10 @@ mkTarget opts = do |
| 486 | 504 | tgtSupportsSubsectionsViaSymbols <- checkSubsectionsViaSymbols archOs cc
|
| 487 | 505 | tgtSupportsIdentDirective <- checkIdentDirective cc
|
| 488 | 506 | tgtSupportsGnuNonexecStack <- checkGnuNonexecStack archOs cc
|
| 507 | + tgtHasLibm <- checkTargetHasLibm cc
|
|
| 508 | + tgtRTSWithLibdw <- case optDwarfUnwind opts of
|
|
| 509 | + Just True -> checkTargetHasLibdw cc (optLibdwIncludes opts) (optLibdwLibraries opts)
|
|
| 510 | + _ -> pure Nothing
|
|
| 489 | 511 | |
| 490 | 512 | -- code generator configuration
|
| 491 | 513 | tgtUnregisterised <- determineUnregisterised archOs (optUnregisterised opts)
|
| ... | ... | @@ -526,6 +548,8 @@ mkTarget opts = do |
| 526 | 548 | , tgtUnregisterised
|
| 527 | 549 | , tgtTablesNextToCode
|
| 528 | 550 | , tgtUseLibffiForAdjustors = tgtUseLibffi
|
| 551 | + , tgtHasLibm
|
|
| 552 | + , tgtRTSWithLibdw
|
|
| 529 | 553 | , tgtSymbolsHaveLeadingUnderscore
|
| 530 | 554 | , tgtSupportsSubsectionsViaSymbols
|
| 531 | 555 | , tgtSupportsIdentDirective
|
| ... | ... | @@ -12,6 +12,7 @@ library |
| 12 | 12 | exposed-modules:
|
| 13 | 13 | GHC.Toolchain,
|
| 14 | 14 | GHC.Toolchain.Lens,
|
| 15 | + GHC.Toolchain.Library,
|
|
| 15 | 16 | GHC.Toolchain.Monad,
|
| 16 | 17 | GHC.Toolchain.PlatformDetails,
|
| 17 | 18 | GHC.Toolchain.Prelude,
|
| 1 | +module GHC.Toolchain.Library
|
|
| 2 | + ( Library(..)
|
|
| 3 | + )
|
|
| 4 | + where
|
|
| 5 | + |
|
| 6 | +import System.FilePath
|
|
| 7 | +import GHC.Toolchain.Prelude
|
|
| 8 | + |
|
| 9 | +data Library = Library { libName :: String
|
|
| 10 | + , includePath :: Maybe FilePath
|
|
| 11 | + , libraryPath :: Maybe FilePath
|
|
| 12 | + }
|
|
| 13 | + deriving (Read, Eq, Ord)
|
|
| 14 | + |
|
| 15 | +instance Show Library where
|
|
| 16 | + -- Normalise filepaths before showing to aid with diffing the target files.
|
|
| 17 | + show (Library n i l) = unwords
|
|
| 18 | + [ "Library { libName = ", show n
|
|
| 19 | + , ", includePath = ", show (normalise <$> i)
|
|
| 20 | + , ", libraryPath =", show (normalise <$> l)
|
|
| 21 | + , "}"]
|
|
| 22 | + |
| ... | ... | @@ -5,6 +5,8 @@ module GHC.Toolchain.PlatformDetails |
| 5 | 5 | , checkSubsectionsViaSymbols
|
| 6 | 6 | , checkIdentDirective
|
| 7 | 7 | , checkGnuNonexecStack
|
| 8 | + , checkTargetHasLibm
|
|
| 9 | + , checkTargetHasLibdw
|
|
| 8 | 10 | ) where
|
| 9 | 11 | |
| 10 | 12 | import Data.List (isInfixOf)
|
| ... | ... | @@ -16,6 +18,7 @@ import GHC.Toolchain.Prelude |
| 16 | 18 | import GHC.Toolchain.Utils
|
| 17 | 19 | import GHC.Toolchain.Target
|
| 18 | 20 | import GHC.Toolchain.Program
|
| 21 | +import GHC.Toolchain.Library
|
|
| 19 | 22 | import GHC.Toolchain.Tools.Cc
|
| 20 | 23 | import GHC.Toolchain.Tools.Nm
|
| 21 | 24 | |
| ... | ... | @@ -112,8 +115,6 @@ checkEndianness__BYTE_ORDER__ cc = checking "endianness (__BYTE_ORDER__)" $ do |
| 112 | 115 | , "#endif"
|
| 113 | 116 | ]
|
| 114 | 117 | |
| 115 | - |
|
| 116 | - |
|
| 117 | 118 | checkLeadingUnderscore :: Cc -> Nm -> M Bool
|
| 118 | 119 | checkLeadingUnderscore cc nm = checking ctxt $ withTempDir $ \dir -> do
|
| 119 | 120 | let test_o = dir </> "test.o"
|
| ... | ... | @@ -156,12 +157,68 @@ checkGnuNonexecStack archOs = |
| 156 | 157 | , asmStmt ".section .text"
|
| 157 | 158 | ]
|
| 158 | 159 | |
| 160 | +checkTargetHasLibm :: Cc -> M Bool
|
|
| 161 | +checkTargetHasLibm cc = testLib cc "m" "atan" Nothing
|
|
| 162 | + |
|
| 163 | +checkTargetHasLibdw :: Cc -> Maybe FilePath -> Maybe FilePath -> M (Maybe Library)
|
|
| 164 | +checkTargetHasLibdw cc mincludeDir mlibDir = do
|
|
| 165 | + b1 <- testHeader cc "elfutils/libdwfl.h" mincludeDir
|
|
| 166 | + b2 <- testLib cc "dw" "dwfl_attach_state" mlibDir
|
|
| 167 | + return $
|
|
| 168 | + if b1 && b2
|
|
| 169 | + then Just
|
|
| 170 | + Library{ libName = "dw"
|
|
| 171 | + , includePath = mincludeDir, libraryPath = mlibDir}
|
|
| 172 | + else Nothing
|
|
| 173 | + |
|
| 174 | + |
|
| 175 | +--------------------------------------------------------------------------------
|
|
| 176 | +-- Utilities
|
|
| 177 | +--------------------------------------------------------------------------------
|
|
| 178 | + |
|
| 159 | 179 | asmStmt :: String -> String
|
| 160 | 180 | asmStmt s = "__asm__(\"" ++ foldMap escape s ++ "\");"
|
| 161 | 181 | where
|
| 162 | 182 | escape '"' = "\\\""
|
| 163 | 183 | escape c = [c]
|
| 164 | 184 | |
| 185 | +-- | Check whether a lib is found and can be linked against.
|
|
| 186 | +-- Like @AC_CHECK_LIB@.
|
|
| 187 | +testLib :: Cc
|
|
| 188 | + -> String -- ^ Lib name
|
|
| 189 | + -> String -- ^ Lib symbol
|
|
| 190 | + -> Maybe FilePath -- ^ Library dir (-L)
|
|
| 191 | + -> M Bool
|
|
| 192 | +testLib cc0 libname symbol mlibDir = testCompile ("whether target has lib" ++ libname) prog cc2
|
|
| 193 | + where
|
|
| 194 | + cc1 = cc0 & _ccProgram % _prgFlags %++ ("-l" ++ libname)
|
|
| 195 | + cc2 | Just libDir <- mlibDir
|
|
| 196 | + = cc1 & _ccProgram % _prgFlags %++ ("-L" ++ libDir)
|
|
| 197 | + | otherwise = cc1
|
|
| 198 | + prog = unlines
|
|
| 199 | + [ "char " ++ symbol ++ " (void);"
|
|
| 200 | + , "int"
|
|
| 201 | + , "main (void)"
|
|
| 202 | + , "{"
|
|
| 203 | + , "return " ++ symbol ++ " ();"
|
|
| 204 | + , " ;"
|
|
| 205 | + , " return 0;"
|
|
| 206 | + , "}"
|
|
| 207 | + ]
|
|
| 208 | + |
|
| 209 | +-- | Like @AC_CHECK_HEADER@
|
|
| 210 | +testHeader :: Cc
|
|
| 211 | + -> String -- ^ Header to check for
|
|
| 212 | + -> Maybe FilePath -- ^ Extra path
|
|
| 213 | + -> M Bool
|
|
| 214 | +testHeader cc0 header mincludeDir = testCompile ("whether target has <" ++ header ++ ">") prog cc1
|
|
| 215 | + where
|
|
| 216 | + cc1 | Just includeDir <- mincludeDir
|
|
| 217 | + = cc0 & _ccProgram % _prgFlags %++ ("-I" ++ includeDir)
|
|
| 218 | + | otherwise = cc0
|
|
| 219 | + prog = unlines
|
|
| 220 | + [ "#include <" ++ header ++ ">" ]
|
|
| 221 | + |
|
| 165 | 222 | -- | Try compiling a program, returning 'True' if successful.
|
| 166 | 223 | testCompile :: String -> String -> Cc -> M Bool
|
| 167 | 224 | testCompile what program cc = checking what $ withTempDir $ \dir -> do
|
| 1 | 1 | {-# LANGUAGE RecordWildCards #-}
|
| 2 | 2 | {-# LANGUAGE NamedFieldPuns #-}
|
| 3 | +{-# LANGUAGE MultiWayIf #-}
|
|
| 3 | 4 | module GHC.Toolchain.Target
|
| 4 | 5 | (
|
| 5 | 6 | -- * A Toolchain Target
|
| ... | ... | @@ -7,6 +8,9 @@ module GHC.Toolchain.Target |
| 7 | 8 | |
| 8 | 9 | , WordSize(..), wordSize2Bytes
|
| 9 | 10 | |
| 11 | + -- ** Queries
|
|
| 12 | + , tgtSupportsSMP, tgtRTSLinkerOnlySupportsSharedLibs
|
|
| 13 | + |
|
| 10 | 14 | -- ** Lenses
|
| 11 | 15 | , _tgtCC, _tgtCxx, _tgtCpp, _tgtHsCpp
|
| 12 | 16 | |
| ... | ... | @@ -19,6 +23,7 @@ import GHC.Platform.ArchOS |
| 19 | 23 | |
| 20 | 24 | import GHC.Toolchain.Prelude
|
| 21 | 25 | import GHC.Toolchain.Program
|
| 26 | +import GHC.Toolchain.Library
|
|
| 22 | 27 | |
| 23 | 28 | import GHC.Toolchain.Tools.Cc
|
| 24 | 29 | import GHC.Toolchain.Tools.Cxx
|
| ... | ... | @@ -56,6 +61,13 @@ data Target = Target |
| 56 | 61 | -- , tgtHasThreadedRts :: Bool -- We likely just need this when bootstrapping
|
| 57 | 62 | , tgtUseLibffiForAdjustors :: Bool
|
| 58 | 63 | -- ^ We need to know whether or not to include libffi headers, and generate additional code for it
|
| 64 | + , tgtHasLibm :: Bool
|
|
| 65 | + -- ^ Does this target have a libm library that should always be linked against?
|
|
| 66 | + |
|
| 67 | + -- RTS capabilities
|
|
| 68 | + , tgtRTSWithLibdw :: Maybe Library
|
|
| 69 | + -- ^ Whether this target RTS is built with libdw support (for DWARF
|
|
| 70 | + -- unwinding), and if yes, the 'Library' configuration.
|
|
| 59 | 71 | |
| 60 | 72 | -- C toolchain
|
| 61 | 73 | , tgtCCompiler :: Cc
|
| ... | ... | @@ -121,6 +133,8 @@ instance Show Target where |
| 121 | 133 | , ", tgtUnregisterised = " ++ show tgtUnregisterised
|
| 122 | 134 | , ", tgtTablesNextToCode = " ++ show tgtTablesNextToCode
|
| 123 | 135 | , ", tgtUseLibffiForAdjustors = " ++ show tgtUseLibffiForAdjustors
|
| 136 | + , ", tgtHasLibm = " ++ show tgtHasLibm
|
|
| 137 | + , ", tgtRTSWithLibdw = " ++ show tgtRTSWithLibdw
|
|
| 124 | 138 | , ", tgtCCompiler = " ++ show tgtCCompiler
|
| 125 | 139 | , ", tgtCxxCompiler = " ++ show tgtCxxCompiler
|
| 126 | 140 | , ", tgtCPreprocessor = " ++ show tgtCPreprocessor
|
| ... | ... | @@ -141,6 +155,54 @@ instance Show Target where |
| 141 | 155 | , "}"
|
| 142 | 156 | ]
|
| 143 | 157 | |
| 158 | +--------------------------------------------------------------------------------
|
|
| 159 | +-- Queries
|
|
| 160 | +--------------------------------------------------------------------------------
|
|
| 161 | + |
|
| 162 | +tgtSupportsSMP :: Target -> Bool
|
|
| 163 | +tgtSupportsSMP Target{..} = do
|
|
| 164 | + let goodArch =
|
|
| 165 | + isARM (archOS_arch tgtArchOs)
|
|
| 166 | + || archOS_arch tgtArchOs `elem`
|
|
| 167 | + [ ArchX86
|
|
| 168 | + , ArchX86_64
|
|
| 169 | + , ArchPPC
|
|
| 170 | + , ArchPPC_64 ELF_V1
|
|
| 171 | + , ArchPPC_64 ELF_V2
|
|
| 172 | + , ArchAArch64
|
|
| 173 | + , ArchS390X
|
|
| 174 | + , ArchRISCV64
|
|
| 175 | + , ArchLoongArch64 ]
|
|
| 176 | + |
|
| 177 | + if -- The THREADED_RTS requires `BaseReg` to be in a register and the
|
|
| 178 | + -- Unregisterised mode doesn't allow that.
|
|
| 179 | + | tgtUnregisterised -> False
|
|
| 180 | + -- We don't support load/store barriers pre-ARMv7. See #10433.
|
|
| 181 | + | ArchARM ver _ _ <- archOS_arch tgtArchOs
|
|
| 182 | + , ver < ARMv7 -> False
|
|
| 183 | + | goodArch -> True
|
|
| 184 | + | otherwise -> False
|
|
| 185 | + |
|
| 186 | +-- | Does the target RTS linker only support loading shared libraries?
|
|
| 187 | +-- If true, this has several implications:
|
|
| 188 | +-- 1. The GHC driver must not do loadArchive/loadObj etc and must
|
|
| 189 | +-- always do loadDLL, regardless of whether host GHC is dynamic or
|
|
| 190 | +-- not.
|
|
| 191 | +-- 2. The GHC driver will always enable -dynamic-too when compiling
|
|
| 192 | +-- vanilla way with TH codegen requirement.
|
|
| 193 | +-- 3. ghci will always enforce dynamic ways even if -dynamic or
|
|
| 194 | +-- -dynamic-too is not explicitly passed.
|
|
| 195 | +-- 4. Cabal must not build ghci objects since it's not supported by
|
|
| 196 | +-- the target.
|
|
| 197 | +-- 5. The testsuite driver will use dyn way for TH/ghci tests even
|
|
| 198 | +-- when host GHC is static.
|
|
| 199 | +-- 6. TH/ghci doesn't work if stage1 is built without shared libraries
|
|
| 200 | +-- (e.g. quickest/fully_static).
|
|
| 201 | +tgtRTSLinkerOnlySupportsSharedLibs :: Target -> Bool
|
|
| 202 | +tgtRTSLinkerOnlySupportsSharedLibs Target{tgtArchOs} =
|
|
| 203 | + archOS_arch tgtArchOs `elem`
|
|
| 204 | + [ ArchWasm32 ]
|
|
| 205 | + |
|
| 144 | 206 | --------------------------------------------------------------------------------
|
| 145 | 207 | -- Lenses
|
| 146 | 208 | --------------------------------------------------------------------------------
|