David Eichmann pushed to branch wip/davide/windows-dlls at Glasgow Haskell Compiler / GHC
Commits:
-
4456f207
by David Eichmann at 2026-06-15T16:18:24+01:00
-
96c59586
by David Eichmann at 2026-06-15T16:18:45+01:00
-
3432392f
by David Eichmann at 2026-06-19T14:33:31+01:00
6 changed files:
- compiler/GHC/Cmm/CLabel.hs
- compiler/GHC/CmmToAsm/X86/Ppr.hs
- hadrian/src/Rules/Generate.hs
- hadrian/src/Rules/Library.hs
- hadrian/src/Rules/Rts.hs
- rts/win32/libHSghc-internal.def.in
Changes:
| ... | ... | @@ -106,6 +106,7 @@ module GHC.Cmm.CLabel ( |
| 106 | 106 | labelDynamic,
|
| 107 | 107 | isLocalCLabel,
|
| 108 | 108 | mayRedirectTo,
|
| 109 | + isSRTInfoLabel,
|
|
| 109 | 110 | isInfoTableLabel,
|
| 110 | 111 | isCmmInfoTableLabel,
|
| 111 | 112 | isConInfoTableLabel,
|
| ... | ... | @@ -730,6 +731,27 @@ mkOutOfBoundsAccessLabel = mkForeignLabel (fsLit "rtsOutOfBoundsAccess") |
| 730 | 731 | mkMemcpyRangeOverlapLabel = mkForeignLabel (fsLit "rtsMemcpyRangeOverlap") ForeignLabelInExternalPackage ForeignLabelIsFunction
|
| 731 | 732 | mkMUT_VAR_CLEAN_infoLabel = CmmLabel rtsUnitId (NeedExternDecl False) (fsLit "stg_MUT_VAR_CLEAN") CmmInfo
|
| 732 | 733 | |
| 734 | +isSRTInfoLabel :: CLabel -> Bool
|
|
| 735 | +isSRTInfoLabel clbl = case clbl of
|
|
| 736 | + CmmLabel _ _ lbl CmmInfo ->
|
|
| 737 | + lbl == fsLit "stg_SRT_1"
|
|
| 738 | + || lbl == fsLit "stg_SRT_2"
|
|
| 739 | + || lbl == fsLit "stg_SRT_3"
|
|
| 740 | + || lbl == fsLit "stg_SRT_4"
|
|
| 741 | + || lbl == fsLit "stg_SRT_5"
|
|
| 742 | + || lbl == fsLit "stg_SRT_6"
|
|
| 743 | + || lbl == fsLit "stg_SRT_7"
|
|
| 744 | + || lbl == fsLit "stg_SRT_8"
|
|
| 745 | + || lbl == fsLit "stg_SRT_9"
|
|
| 746 | + || lbl == fsLit "stg_SRT_10"
|
|
| 747 | + || lbl == fsLit "stg_SRT_11"
|
|
| 748 | + || lbl == fsLit "stg_SRT_12"
|
|
| 749 | + || lbl == fsLit "stg_SRT_13"
|
|
| 750 | + || lbl == fsLit "stg_SRT_14"
|
|
| 751 | + || lbl == fsLit "stg_SRT_15"
|
|
| 752 | + || lbl == fsLit "stg_SRT_16"
|
|
| 753 | + _ -> False
|
|
| 754 | + |
|
| 733 | 755 | mkSRTInfoLabel :: Int -> CLabel
|
| 734 | 756 | mkSRTInfoLabel n = CmmLabel rtsUnitId (NeedExternDecl False) lbl CmmInfo
|
| 735 | 757 | where
|
| ... | ... | @@ -33,7 +33,7 @@ import GHC.CmmToAsm.Ppr |
| 33 | 33 | import GHC.Cmm hiding (topInfoTable)
|
| 34 | 34 | import GHC.Cmm.Dataflow.Label
|
| 35 | 35 | import GHC.Cmm.BlockId
|
| 36 | -import GHC.Cmm.CLabel
|
|
| 36 | +import GHC.Cmm.CLabel as CLabel
|
|
| 37 | 37 | import GHC.Cmm.InitFini
|
| 38 | 38 | import GHC.Cmm.DebugBlock (pprUnwindTable)
|
| 39 | 39 | |
| ... | ... | @@ -96,10 +96,16 @@ pprNatCmmDecl config proc@(CmmProc top_info entry_lbl _ (ListGraph blocks)) = |
| 96 | 96 | )
|
| 97 | 97 | | otherwise = (empty,empty)
|
| 98 | 98 | |
| 99 | + section = if platformOS platform == OSMinGW32
|
|
| 100 | + && externallyVisibleCLabel proc_lbl
|
|
| 101 | + && isSRTInfoLabel proc_lbl
|
|
| 102 | + then ReadOnlyData
|
|
| 103 | + else Text
|
|
| 104 | + |
|
| 99 | 105 | in vcat
|
| 100 | 106 | [ -- section directive. Requires proc_lbl when split-section is enabled to
|
| 101 | 107 | -- use as a subsection name.
|
| 102 | - pprSectionAlign config (Section Text proc_lbl)
|
|
| 108 | + pprSectionAlign config (Section section proc_lbl)
|
|
| 103 | 109 | |
| 104 | 110 | -- section alignment. Note that when there is an info table, we align the
|
| 105 | 111 | -- info table and not the entry code!
|
| ... | ... | @@ -377,7 +377,6 @@ templateRules = do |
| 377 | 377 | , interpolateSetting "ProjectPatchLevel1" ProjectPatchLevel1
|
| 378 | 378 | , interpolateSetting "ProjectPatchLevel2" ProjectPatchLevel2
|
| 379 | 379 | ]
|
| 380 | - templateRule "rts/win32/libHSghc-internal.def" projectVersion
|
|
| 381 | 380 | templateRule "docs/index.html" $ packageUnitIds Stage1
|
| 382 | 381 | templateRule "docs/users_guide/ghc_config.py" $ mconcat
|
| 383 | 382 | [ projectVersion
|
| ... | ... | @@ -9,6 +9,7 @@ import GHC.Toolchain.Target (Target(tgtArchOs)) |
| 9 | 9 | |
| 10 | 10 | import Base
|
| 11 | 11 | import Context
|
| 12 | +import qualified Data.List as List
|
|
| 12 | 13 | import Expression hiding (way, package, stage)
|
| 13 | 14 | import Oracles.ModuleFiles
|
| 14 | 15 | import Packages
|
| ... | ... | @@ -20,6 +21,7 @@ import Utilities |
| 20 | 21 | import Data.Time.Clock
|
| 21 | 22 | import Rules.Generate (generatedDependencies)
|
| 22 | 23 | import Oracles.Flag
|
| 24 | +import Way.Type (wayToUnits)
|
|
| 23 | 25 | |
| 24 | 26 | |
| 25 | 27 | -- * Library 'Rules'
|
| ... | ... | @@ -203,13 +205,32 @@ extraObjects context |
| 203 | 205 | |
| 204 | 206 | | package context == rts = do
|
| 205 | 207 | target <- interpretInContext context getStagedTarget
|
| 206 | - builddir <- buildPath context
|
|
| 207 | - return [ builddir -/- "libHSghc-internal.dll.a"
|
|
| 208 | - | archOS_OS (tgtArchOs target) == OSMinGW32
|
|
| 209 | - , Dynamic `wayUnit` way context ]
|
|
| 208 | + if not (archOS_OS (tgtArchOs target) == OSMinGW32
|
|
| 209 | + && Dynamic `wayUnit` way context)
|
|
| 210 | + then return []
|
|
| 211 | + else do
|
|
| 212 | + -- Find the ghc-internal library file name. Note that the
|
|
| 213 | + -- ghc-internal's .dll.a file is placed in the RTS build dir and not
|
|
| 214 | + -- the ghc-internal build dir as we only use it when building the
|
|
| 215 | + -- RTS and not other libraries.
|
|
| 216 | + ghcInternalDllName <- takeFileName <$> pkgLibraryFile Context {
|
|
| 217 | + stage = stage context,
|
|
| 218 | + way = rtsWayToLibraryWay (way context),
|
|
| 219 | + iplace = iplace context,
|
|
| 220 | + package = ghcInternal
|
|
| 221 | + }
|
|
| 222 | + |
|
| 223 | + builddir <- buildPath context
|
|
| 224 | + return [ builddir -/- ghcInternalDllName <> ".a"]
|
|
| 210 | 225 | |
| 211 | 226 | | otherwise = return []
|
| 212 | 227 | |
| 228 | +-- | The rts is compiled in many different ways, but libraries are only built in
|
|
| 229 | +-- (non)Dynamic and (non)Profiled ways. This function converts the rts way into
|
|
| 230 | +-- compatible library way.
|
|
| 231 | +rtsWayToLibraryWay :: Way -> Way
|
|
| 232 | +rtsWayToLibraryWay = wayFromUnits . List.intersect [Dynamic, Profiling] . wayToUnits
|
|
| 233 | + |
|
| 213 | 234 | -- | Return all the object files to be put into the library we're building for
|
| 214 | 235 | -- the given 'Context'.
|
| 215 | 236 | libraryObjects :: Context -> Action [FilePath]
|
| ... | ... | @@ -13,11 +13,19 @@ rtsRules = priority 3 $ do |
| 13 | 13 | -- to be linked into the rts dll.
|
| 14 | 14 | forM_ [Stage1, Stage2, Stage3 ] $ \ stage -> do
|
| 15 | 15 | let buildPath = root -/- buildDir (rtsContext stage)
|
| 16 | - buildPath -/- "libHSghc-internal.dll.a" %> buildGhcInternalImportLib
|
|
| 16 | + buildPath -/- "libHSghc-internal-*.def" %> buildGhcInternalImportDef
|
|
| 17 | + buildPath -/- "libHSghc-internal-*.dll.a" %> buildGhcInternalImportLib
|
|
| 18 | + |
|
| 19 | +buildGhcInternalImportDef :: FilePath -> Action ()
|
|
| 20 | +buildGhcInternalImportDef target = do
|
|
| 21 | + templateIn <- readFile' "rts/win32/libHSghc-internal.def.in"
|
|
| 22 | + let dllName = takeFileName target -<.> "dll"
|
|
| 23 | + templateOut = replace "@GhcInternalDll@" dllName templateIn
|
|
| 24 | + writeFile' target templateOut
|
|
| 17 | 25 | |
| 18 | 26 | buildGhcInternalImportLib :: FilePath -> Action ()
|
| 19 | 27 | buildGhcInternalImportLib target = do
|
| 20 | - let input = "rts/win32/libHSghc-internal.def"
|
|
| 28 | + let input = dropExtension (dropExtension target) <.> "def" -- the .def file
|
|
| 21 | 29 | output = target -- the .dll.a import lib
|
| 22 | 30 | need [input]
|
| 23 | 31 | runBuilder Dlltool ["-d", input, "-l", output] [input] [output] |
| 1 | -LIBRARY libHSghc-internal-@ProjectVersionForLib@.0-ghc@ProjectVersion@.dll
|
|
| 1 | +LIBRARY @GhcInternalDll@
|
|
| 2 | 2 | |
| 3 | 3 | EXPORTS
|
| 4 | 4 | init_ghc_hs_iface |