diff options
author | Reid Barton <rwbarton@gmail.com> | 2017-03-09 10:42:49 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-03-09 10:42:58 -0500 |
commit | 90009cf62bcebf875e68af625dbdbfc3c2f71717 (patch) | |
tree | e1eeb7fbca85ae9d940393240beab65087a76152 | |
parent | 7b087aeba45a7a70a5553ef4c116ee67660423e8 (diff) | |
download | haskell-90009cf62bcebf875e68af625dbdbfc3c2f71717.tar.gz |
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
-rw-r--r-- | compiler/llvmGen/LlvmCodeGen/Data.hs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/compiler/llvmGen/LlvmCodeGen/Data.hs b/compiler/llvmGen/LlvmCodeGen/Data.hs index 0f0ca6eeaf..9bb5a75bda 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 |