summaryrefslogtreecommitdiff
path: root/compiler/GHC/Llvm
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2022-02-08 19:04:41 -0500
committerMatthew Pickering <matthewtpickering@gmail.com>2022-04-01 10:34:39 +0100
commit5beeff46972b8b52e9f2572fff8b1ad9ace38cd8 (patch)
treef3fb4084554f8de4b2f9d8b0b6144cbc9ad1f342 /compiler/GHC/Llvm
parent6793a20fe0cd1f04dabad46b87e86018abf73e54 (diff)
downloadhaskell-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/Llvm')
-rw-r--r--compiler/GHC/Llvm/Ppr.hs1
-rw-r--r--compiler/GHC/Llvm/Types.hs2
2 files changed, 3 insertions, 0 deletions
diff --git a/compiler/GHC/Llvm/Ppr.hs b/compiler/GHC/Llvm/Ppr.hs
index f02d2e1024..f48e7aa034 100644
--- a/compiler/GHC/Llvm/Ppr.hs
+++ b/compiler/GHC/Llvm/Ppr.hs
@@ -569,6 +569,7 @@ ppStatic opts st = case st of
LMStaticStr s t -> ppr t <> text " c\"" <> ftext s <> text "\\00\""
LMStaticArray d t -> ppr t <> text " [" <> ppCommaJoin (map (ppStatic opts) d) <> char ']'
LMStaticStruc d t -> ppr t <> text "<{" <> ppCommaJoin (map (ppStatic opts) d) <> text "}>"
+ LMStaticStrucU d t -> ppr t <> text "{" <> ppCommaJoin (map (ppStatic opts) d) <> text "}"
LMStaticPointer v -> ppVar opts v
LMTrunc v t -> ppr t <> text " trunc (" <> ppStatic opts v <> text " to " <> ppr t <> char ')'
LMBitc v t -> ppr t <> text " bitcast (" <> ppStatic opts v <> text " to " <> ppr t <> char ')'
diff --git a/compiler/GHC/Llvm/Types.hs b/compiler/GHC/Llvm/Types.hs
index f5db5a96aa..79dccfac88 100644
--- a/compiler/GHC/Llvm/Types.hs
+++ b/compiler/GHC/Llvm/Types.hs
@@ -140,6 +140,7 @@ data LlvmStatic
| LMStaticStr LMString LlvmType -- ^ Defines a static 'LMString'
| LMStaticArray [LlvmStatic] LlvmType -- ^ A static array
| LMStaticStruc [LlvmStatic] LlvmType -- ^ A static structure type
+ | LMStaticStrucU [LlvmStatic] LlvmType -- ^ A static structure type
| LMStaticPointer LlvmVar -- ^ A pointer to other data
-- static expressions, could split out but leave
@@ -191,6 +192,7 @@ getStatType (LMUninitType t) = t
getStatType (LMStaticStr _ t) = t
getStatType (LMStaticArray _ t) = t
getStatType (LMStaticStruc _ t) = t
+getStatType (LMStaticStrucU _ t) = t
getStatType (LMStaticPointer v) = getVarType v
getStatType (LMTrunc _ t) = t
getStatType (LMBitc _ t) = t