Commit 0dc7b36c authored by olsner's avatar olsner Committed by Ben Gamari
Browse files

Restore original alignment for info tables

This was broken in 4a32bf92, 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
parent 1c6130d9
......@@ -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
......@@ -304,10 +304,17 @@ 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
......
......@@ -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"
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment