David Eichmann pushed to branch wip/davide/windows-dlls at Glasgow Haskell Compiler / GHC Commits: dc4a1a48 by David Eichmann at 2026-06-25T15:55:27+01:00 WIP explicit exports - - - - - 3 changed files: - compiler/GHC/Cmm.hs - compiler/GHC/CmmToAsm/Ppr.hs - compiler/GHC/CmmToAsm/X86/Ppr.hs Changes: ===================================== compiler/GHC/Cmm.hs ===================================== @@ -269,6 +269,7 @@ data SectionType | FiniArray -- .fini_array on ELF, .dtor on Windows | CString | IPE + | Directive -- .drectve on Windows deriving (Show) data SectionProtection @@ -289,6 +290,7 @@ sectionProtection t = case t of Data -> ReadWriteSection UninitialisedData -> ReadWriteSection IPE -> ReadWriteSection + Directive -> ReadOnlySection {- Note [Relocatable Read-Only Data] @@ -548,3 +550,4 @@ pprSectionType s = doubleQuotes $ case s of FiniArray -> text "finiarray" CString -> text "cstring" IPE -> text "ipe" + Directive -> text "drectve" ===================================== compiler/GHC/CmmToAsm/Ppr.hs ===================================== @@ -243,6 +243,7 @@ pprGNUSectionHeader config t suffix = | OSMinGW32 <- platformOS platform -> text ".rdata" | otherwise -> text ".ipe" + Directive -> text ".drectve" flags -- See -- https://github.com/llvm/llvm-project/blob/llvmorg-21.1.8/lld/COFF/Chunks.cpp... @@ -339,8 +340,9 @@ pprDarwinSectionHeader t = case t of RelocatableReadOnlyData -> text ".const_data" UninitialisedData -> text ".data" InitArray -> text ".section\t__DATA,__mod_init_func,mod_init_funcs" - FiniArray -> panic "pprDarwinSectionHeader: fini not supported" CString -> text ".section\t__TEXT,__cstring,cstring_literals" IPE -> text ".const" + FiniArray -> panic "pprDarwinSectionHeader: fini not supported" + Directive -> panic "pprDarwinSectionHeader: drectve not supported" {-# SPECIALIZE pprDarwinSectionHeader :: SectionType -> SDoc #-} {-# SPECIALIZE pprDarwinSectionHeader :: SectionType -> HLine #-} -- see Note [SPECIALIZE to HDoc] in GHC.Utils.Outputable ===================================== compiler/GHC/CmmToAsm/X86/Ppr.hs ===================================== @@ -133,6 +133,9 @@ pprNatCmmDecl config proc@(CmmProc top_info entry_lbl _ (ListGraph blocks)) = -- ELF .size directive (size of the entry code function) , pprSizeDecl platform proc_lbl + + , -- Explicite export on windows (see Note [TODO]) + pprExport config proc_lbl False ] {-# SPECIALIZE pprNatCmmDecl :: NCGConfig -> NatCmmDecl (Alignment, RawCmmStatics) Instr -> SDoc #-} {-# SPECIALIZE pprNatCmmDecl :: NCGConfig -> NatCmmDecl (Alignment, RawCmmStatics) Instr -> HDoc #-} -- see Note [SPECIALIZE to HDoc] in GHC.Utils.Outputable @@ -206,11 +209,17 @@ pprDatas config (_, CmmStaticsRaw alias [CmmStaticLit (CmmLabel lbl), CmmStaticL , not $ platformOS platform == OSMinGW32 && ncgSplitSections config = pprGloblDecl (ncgPlatform config) alias $$ line (text ".equiv" <+> pprAsmLabel (ncgPlatform config) alias <> comma <> pprAsmLabel (ncgPlatform config) ind') + $$ pprExport config lbl True where platform = ncgPlatform config pprDatas config (align, (CmmStaticsRaw lbl dats)) - = vcat (pprAlign platform align : pprLabel platform lbl : map (pprData config) dats) + = vcat $ + [ pprAlign platform align + , pprLabel platform lbl + ] + ++ (map (pprData config) dats) + ++ [pprExport config lbl True] where platform = ncgPlatform config @@ -290,6 +299,27 @@ pprLabelType' platform lbl = isInfoTableLabel lbl && not (isCmmInfoTableLabel lbl) && not (isConInfoTableLabel lbl) +-- See Note [TODO] +pprExport :: IsDoc doc => NCGConfig -> CLabel -> Bool -> doc +pprExport config lbl isCmmData = + if platformOS platform == OSMinGW32 + && platformTablesNextToCode platform + && externallyVisibleCLabel lbl + then let + asData = isCmmData || isInfoTableLabel lbl + in + pprSectionAlign config (Section Directive lbl) $$ + line (text ".ascii" <> doubleQuotes ( + text " -export:" + <> pprAsmLabel platform lbl + <> if asData then text ",data" else empty + )) + else empty + where + platform = ncgPlatform config + + + pprTypeDecl :: IsDoc doc => Platform -> CLabel -> doc pprTypeDecl platform lbl = if osElfTarget (platformOS platform) && externallyVisibleCLabel lbl View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/dc4a1a482c7727ee2693049c29c6c8fb... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/dc4a1a482c7727ee2693049c29c6c8fb... You're receiving this email because of your account on gitlab.haskell.org.