[commit: ghc] master: Restore original alignment for info tables (0dc7b36)

git at git.haskell.org git at git.haskell.org
Wed Jan 27 10:31:06 UTC 2016


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/0dc7b36c3c261b3eccf8460581fcd3d71f6e6ff6/ghc

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

commit 0dc7b36c3c261b3eccf8460581fcd3d71f6e6ff6
Author: Simon Brenner <olsner at gmail.com>
Date:   Wed Jan 27 11:05:35 2016 +0100

    Restore original alignment for info tables
    
    This was broken in 4a32bf925b8aba7885d9c745769fe84a10979a53, meaning
    that info tables and subsequent code are no longer guaranteed to have
    the recommended alignment.  Split up the section header and section
    alignment printers, and print an appropriate alignment directive before
    each info table.
    
    Fixes Trac #11486
    
    Reviewers: austin, bgamari, rwbarton
    
    Reviewed By: bgamari, rwbarton
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D1847
    
    GHC Trac Issues: #11486


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

0dc7b36c3c261b3eccf8460581fcd3d71f6e6ff6
 compiler/nativeGen/PPC/Ppr.hs   | 12 +++++++++---
 compiler/nativeGen/SPARC/Ppr.hs |  7 ++++++-
 compiler/nativeGen/X86/Ppr.hs   |  9 +++++++++
 3 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/compiler/nativeGen/PPC/Ppr.hs b/compiler/nativeGen/PPC/Ppr.hs
index 8d89a19..08c02f0 100644
--- a/compiler/nativeGen/PPC/Ppr.hs
+++ b/compiler/nativeGen/PPC/Ppr.hs
@@ -112,7 +112,7 @@ pprBasicBlock info_env (BasicBlock blockid instrs)
     maybe_infotable = case mapLookup blockid info_env of
        Nothing   -> empty
        Just (Statics info_lbl info) ->
-           pprSectionAlign (Section Text info_lbl) $$
+           pprAlignForSection Text $$
            vcat (map pprData info) $$
            pprLabel info_lbl
 
@@ -305,9 +305,16 @@ pprAddr (AddrRegImm r1 imm) = hcat [ pprImm imm, char '(', pprReg r1, char ')' ]
 pprSectionAlign :: Section -> SDoc
 pprSectionAlign sec@(Section seg _) =
  sdocWithPlatform $ \platform ->
+   pprSectionHeader platform sec $$
+   pprAlignForSection seg
+
+-- | Print appropriate alignment for the given section type.
+pprAlignForSection :: SectionType -> SDoc
+pprAlignForSection seg =
+ sdocWithPlatform $ \platform ->
  let osDarwin = platformOS platform == OSDarwin
      ppc64    = not $ target32Bit platform
-     align    = ptext $ case seg of
+ in ptext $ case seg of
        Text              -> sLit ".align 2"
        Data
         | ppc64          -> sLit ".align 3"
@@ -328,7 +335,6 @@ pprSectionAlign sec@(Section seg _) =
         | osDarwin       -> sLit ".align 4"
         | otherwise      -> sLit ".align 4"
        OtherSection _    -> panic "PprMach.pprSectionAlign: unknown section"
- in pprSectionHeader platform sec $$ align
 
 pprDataItem :: CmmLit -> SDoc
 pprDataItem lit
diff --git a/compiler/nativeGen/SPARC/Ppr.hs b/compiler/nativeGen/SPARC/Ppr.hs
index 8c7871e..eb41f23 100644
--- a/compiler/nativeGen/SPARC/Ppr.hs
+++ b/compiler/nativeGen/SPARC/Ppr.hs
@@ -96,7 +96,7 @@ pprBasicBlock info_env (BasicBlock blockid instrs)
     maybe_infotable = case mapLookup blockid info_env of
        Nothing   -> empty
        Just (Statics info_lbl info) ->
-           pprSectionAlign (Section Text info_lbl) $$
+           pprAlignForSection Text $$
            vcat (map pprData info) $$
            pprLabel info_lbl
 
@@ -326,6 +326,11 @@ pprSectionAlign :: Section -> SDoc
 pprSectionAlign sec@(Section seg _) =
   sdocWithPlatform $ \platform ->
     pprSectionHeader platform sec $$
+    pprAlignForSection seg
+
+-- | Print appropriate alignment for the given section type.
+pprAlignForSection :: SectionType -> SDoc
+pprAlignForSection seg =
     ptext (case seg of
       Text              -> sLit ".align 4"
       Data              -> sLit ".align 8"
diff --git a/compiler/nativeGen/X86/Ppr.hs b/compiler/nativeGen/X86/Ppr.hs
index f2fc884..7809ae1 100644
--- a/compiler/nativeGen/X86/Ppr.hs
+++ b/compiler/nativeGen/X86/Ppr.hs
@@ -109,6 +109,7 @@ pprBasicBlock info_env (BasicBlock blockid instrs)
     maybe_infotable = case mapLookup blockid info_env of
        Nothing   -> empty
        Just (Statics info_lbl info) ->
+           pprAlignForSection Text $$
            infoTableLoc $$
            vcat (map pprData info) $$
            pprLabel info_lbl
@@ -386,8 +387,15 @@ pprSectionAlign (Section (OtherSection _) _) =
 pprSectionAlign sec@(Section seg _) =
   sdocWithPlatform $ \platform ->
     pprSectionHeader platform sec $$
+    pprAlignForSection seg
+
+-- | Print appropriate alignment for the given section type.
+pprAlignForSection :: SectionType -> SDoc
+pprAlignForSection seg =
+  sdocWithPlatform $ \platform ->
     text ".align " <>
     case platformOS platform of
+      -- Darwin: alignments are given as shifts.
       OSDarwin
        | target32Bit platform ->
           case seg of
@@ -397,6 +405,7 @@ pprSectionAlign sec@(Section seg _) =
           case seg of
            ReadOnlyData16    -> int 4
            _                 -> int 3
+      -- Other: alignments are given as bytes.
       _
        | target32Bit platform ->
           case seg of



More information about the ghc-commits mailing list