[commit: ghc] master: Fix string merging with -split-sections (4026b45)

git at git.haskell.org git at git.haskell.org
Sat Dec 17 01:58:10 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/4026b452817e9d4241691c58d131904bd0eb1fec/ghc

>---------------------------------------------------------------

commit 4026b452817e9d4241691c58d131904bd0eb1fec
Author: Simon Brenner <olsner at gmail.com>
Date:   Fri Dec 16 12:14:36 2016 -0500

    Fix string merging with -split-sections
    
    The added flags for string literal merging ended up printed in the
    middle of the section name when -split-sections was enabled. Break it up
    to put the flags after the name.
    
    Test Plan: validate with SplitSections=YES
    
    Reviewers: austin, bgamari
    
    Reviewed By: bgamari
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D2865
    
    GHC Trac Issues: #9577


>---------------------------------------------------------------

4026b452817e9d4241691c58d131904bd0eb1fec
 compiler/nativeGen/PprBase.hs | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/compiler/nativeGen/PprBase.hs b/compiler/nativeGen/PprBase.hs
index 10ed2fb..e05b2b5 100644
--- a/compiler/nativeGen/PprBase.hs
+++ b/compiler/nativeGen/PprBase.hs
@@ -85,6 +85,10 @@ doubleToBytes d
 -- If -split-section was specified, include the suffix label, otherwise just
 -- print the section type. For Darwin, where subsections-for-symbols are
 -- used instead, only print section type.
+--
+-- For string literals, additional flags are specified to enable merging of
+-- identical strings in the linker. With -split-sections each string also gets
+-- a unique section to allow strings from unused code to be GC'd.
 
 pprSectionHeader :: Platform -> Section -> SDoc
 pprSectionHeader platform (Section t suffix) =
@@ -98,7 +102,8 @@ pprGNUSectionHeader t suffix = sdocWithDynFlags $ \dflags ->
   let splitSections = gopt Opt_SplitSections dflags
       subsection | splitSections = char '.' <> ppr suffix
                  | otherwise     = empty
-  in  text ".section " <> ptext (header dflags) <> subsection
+  in  text ".section " <> ptext (header dflags) <> subsection <>
+      flags dflags
   where
     header dflags = case t of
       Text -> sLit ".text"
@@ -109,10 +114,16 @@ pprGNUSectionHeader t suffix = sdocWithDynFlags $ \dflags ->
       ReadOnlyData16 -> sLit ".rodata.cst16"
       CString
         | OSMinGW32 <- platformOS (targetPlatform dflags)
-          -> sLit ".rdata,\"dr\""
-        | otherwise -> sLit ".rodata.str1.1,\"aMS\", at progbits,1"
+          -> sLit ".rdata"
+        | otherwise -> sLit ".rodata.str"
       OtherSection _ ->
         panic "PprBase.pprGNUSectionHeader: unknown section type"
+    flags dflags = case t of
+      CString
+        | OSMinGW32 <- platformOS (targetPlatform dflags)
+          -> text ",\"dr\""
+        | otherwise -> text ",\"aMS\", at progbits,1"
+      _ -> empty
 
 -- XCOFF doesn't support relocating label-differences, so we place all
 -- RO sections into .text[PR] sections



More information about the ghc-commits mailing list