[commit: ghc] master: llvm backend: Put string constants in .rodata.str.* sections (#13265) (90009cf)
git at git.haskell.org
git at git.haskell.org
Thu Mar 9 16:13:30 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/90009cf62bcebf875e68af625dbdbfc3c2f71717/ghc
>---------------------------------------------------------------
commit 90009cf62bcebf875e68af625dbdbfc3c2f71717
Author: Reid Barton <rwbarton at gmail.com>
Date: Thu Mar 9 10:42:49 2017 -0500
llvm backend: Put string constants in .rodata.str.* sections (#13265)
The .cstring.* sections don't get merged by the linker (bfd or gold).
That's bad, and especially bad in #13265 where it caused the number of
sections to exceed what is apparently an internal limit in ld.bfd.
Test Plan:
I can only test this on Linux, and I am guessing at what
the correct behavior is on Mac OS and Windows (and AIX I suppose).
Testers on other platforms would be much appreciated, though I
understand that the LLVM backend is broken on Mac OS currently for
other reasons (#13378).
Reviewers: olsner, austin, xnyhps, bgamari
Reviewed By: bgamari
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D3282
>---------------------------------------------------------------
90009cf62bcebf875e68af625dbdbfc3c2f71717
compiler/llvmGen/LlvmCodeGen/Data.hs | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/compiler/llvmGen/LlvmCodeGen/Data.hs b/compiler/llvmGen/LlvmCodeGen/Data.hs
index 0f0ca6e..9bb5a75 100644
--- a/compiler/llvmGen/LlvmCodeGen/Data.hs
+++ b/compiler/llvmGen/LlvmCodeGen/Data.hs
@@ -16,6 +16,7 @@ import BlockId
import CLabel
import Cmm
import DynFlags
+import Platform
import FastString
import Outputable
@@ -46,8 +47,11 @@ genLlvmData (sec, Statics lbl xs) = do
struct = Just $ LMStaticStruc static tyAlias
link = if (externallyVisibleCLabel lbl)
then ExternallyVisible else Internal
+ align = case sec of
+ Section CString _ -> Just 1
+ _ -> Nothing
const = if isSecConstant sec then Constant else Global
- varDef = LMGlobalVar label tyAlias link lmsec Nothing const
+ varDef = LMGlobalVar label tyAlias link lmsec align const
globDef = LMGlobal varDef struct
return ([globDef], [tyAlias])
@@ -65,15 +69,17 @@ isSecConstant (Section t _) = case t of
(OtherSection _) -> False
-- | Format the section type part of a Cmm Section
-llvmSectionType :: SectionType -> FastString
-llvmSectionType t = case t of
+llvmSectionType :: Platform -> SectionType -> FastString
+llvmSectionType p t = case t of
Text -> fsLit ".text"
ReadOnlyData -> fsLit ".rodata"
RelocatableReadOnlyData -> fsLit ".data.rel.ro"
ReadOnlyData16 -> fsLit ".rodata.cst16"
Data -> fsLit ".data"
UninitialisedData -> fsLit ".bss"
- CString -> fsLit ".cstring"
+ CString -> case platformOS p of
+ OSMinGW32 -> fsLit ".rdata"
+ _ -> fsLit ".rodata.str"
(OtherSection _) -> panic "llvmSectionType: unknown section type"
-- | Format a Cmm Section into a LLVM section name
@@ -81,11 +87,12 @@ llvmSection :: Section -> LlvmM LMSection
llvmSection (Section t suffix) = do
dflags <- getDynFlags
let splitSect = gopt Opt_SplitSections dflags
+ platform = targetPlatform dflags
if not splitSect
then return Nothing
else do
lmsuffix <- strCLabel_llvm suffix
- return (Just (concatFS [llvmSectionType t, fsLit ".", lmsuffix]))
+ return (Just (concatFS [llvmSectionType platform t, fsLit ".", lmsuffix]))
-- ----------------------------------------------------------------------------
-- * Generate static data
More information about the ghc-commits
mailing list