diff options
author | Ben Gamari <ben@smart-cactus.org> | 2022-02-08 19:04:41 -0500 |
---|---|---|
committer | Matthew Pickering <matthewtpickering@gmail.com> | 2022-04-01 10:34:39 +0100 |
commit | 5beeff46972b8b52e9f2572fff8b1ad9ace38cd8 (patch) | |
tree | f3fb4084554f8de4b2f9d8b0b6144cbc9ad1f342 /compiler/GHC/CmmToAsm/Ppr.hs | |
parent | 6793a20fe0cd1f04dabad46b87e86018abf73e54 (diff) | |
download | haskell-5beeff46972b8b52e9f2572fff8b1ad9ace38cd8.tar.gz |
Refactor handling of global initializers
GHC uses global initializers for a number of things including
cost-center registration, info-table provenance registration, and setup
of foreign exports. Previously, the global initializer arrays which
referenced these initializers would live in the object file of the C
stub, which would then be merged into the main object file of the
module.
Unfortunately, this approach is no longer tenable with the move to
Clang/LLVM on Windows (see #21019). Specifically, lld's PE backend does
not support object merging (that is, the -r flag). Instead we are now
rather packaging a module's object files into a static library. However,
this is problematic in the case of initializers as there are no
references to the C stub object in the archive, meaning that the linker
may drop the object from the final link.
This patch refactors our handling of global initializers to instead
place initializer arrays within the object file of the module to which
they belong. We do this by introducing a Cmm data declaration containing
the initializer array in the module's Cmm stream. While the initializer
functions themselves remain in separate C stub objects, the reference
from the module's object ensures that they are not dropped from the
final link.
In service of #21068.
Diffstat (limited to 'compiler/GHC/CmmToAsm/Ppr.hs')
-rw-r--r-- | compiler/GHC/CmmToAsm/Ppr.hs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/compiler/GHC/CmmToAsm/Ppr.hs b/compiler/GHC/CmmToAsm/Ppr.hs index 441ee75348..0379ed6464 100644 --- a/compiler/GHC/CmmToAsm/Ppr.hs +++ b/compiler/GHC/CmmToAsm/Ppr.hs @@ -227,6 +227,14 @@ pprGNUSectionHeader config t suffix = ReadOnlyData16 | OSMinGW32 <- platformOS platform -> text ".rdata$cst16" | otherwise -> text ".rodata.cst16" + InitArray + | OSMinGW32 <- platformOS platform + -> text ".ctors" + | otherwise -> text ".init_array" + FiniArray + | OSMinGW32 <- platformOS platform + -> text ".dtors" + | otherwise -> text ".fini_array" CString | OSMinGW32 <- platformOS platform -> text ".rdata" @@ -251,7 +259,7 @@ pprXcoffSectionHeader t = case t of ReadOnlyData16 -> text ".csect .text[PR] # ReadOnlyData16" CString -> text ".csect .text[PR] # CString" UninitialisedData -> text ".csect .data[BS]" - OtherSection _ -> panic "pprXcoffSectionHeader: unknown section type" + _ -> panic "pprXcoffSectionHeader: unknown section type" pprDarwinSectionHeader :: SectionType -> SDoc pprDarwinSectionHeader t = case t of @@ -261,5 +269,7 @@ pprDarwinSectionHeader t = case t of RelocatableReadOnlyData -> text ".const_data" UninitialisedData -> text ".data" ReadOnlyData16 -> text ".const" + 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" OtherSection _ -> panic "pprDarwinSectionHeader: unknown section type" |