summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wortmann <scpmw@leeds.ac.uk>2015-06-11 12:09:55 -0500
committerAustin Seipp <austin@well-typed.com>2015-06-11 12:10:49 -0500
commita66ef3567ea29c93a9c010befc672602dc1c644c (patch)
tree1ee717044da8f07f3cd8a6c0e5eeff487a699957
parentc0dc79fbef90bf26e771d24a102044060ac001fb (diff)
downloadhaskell-a66ef3567ea29c93a9c010befc672602dc1c644c.tar.gz
Fix DWARF generation for MinGW (#10468)
Fortunately this is relatively straightforward - all we need to do is switch to a non-ELF-specific way of specifying object file sections and make sure that section-relative addresses work correctly. This is enough to make "gdb" work on MinGW builds.
-rw-r--r--compiler/nativeGen/Dwarf.hs2
-rw-r--r--compiler/nativeGen/Dwarf/Constants.hs12
-rw-r--r--compiler/nativeGen/Dwarf/Types.hs14
3 files changed, 16 insertions, 12 deletions
diff --git a/compiler/nativeGen/Dwarf.hs b/compiler/nativeGen/Dwarf.hs
index ff86fd8200..34f1ed694b 100644
--- a/compiler/nativeGen/Dwarf.hs
+++ b/compiler/nativeGen/Dwarf.hs
@@ -86,7 +86,7 @@ compileUnitHeader unitU = sdocWithPlatform $ \plat ->
in vcat [ ptext (sLit "\t.long ") <> length -- compilation unit size
, ppr cuLabel <> colon
, ptext (sLit "\t.word 3") -- DWARF version
- , pprDwWord (sectionOffset dwarfAbbrevLabel dwarfAbbrevLabel)
+ , sectionOffset dwarfAbbrevLabel dwarfAbbrevLabel
-- abbrevs offset
, ptext (sLit "\t.byte ") <> ppr (platformWordSize plat) -- word size
]
diff --git a/compiler/nativeGen/Dwarf/Constants.hs b/compiler/nativeGen/Dwarf/Constants.hs
index 2cd54a7ceb..4b334fca3d 100644
--- a/compiler/nativeGen/Dwarf/Constants.hs
+++ b/compiler/nativeGen/Dwarf/Constants.hs
@@ -122,12 +122,14 @@ dwarfFrameSection = dwarfSection "frame"
dwarfGhcSection = dwarfSection "ghc"
dwarfSection :: String -> SDoc
-dwarfSection name = sdocWithPlatform $ \plat ->
+dwarfSection name = sdocWithPlatform $ \plat -> ftext $ mkFastString $
case platformOS plat of
- OSDarwin -> ftext $ mkFastString $
- ".section __DWARF,__debug_" ++ name ++ ",regular,debug"
- _other -> ftext $ mkFastString $
- ".section .debug_" ++ name ++ ",\"\",@progbits"
+ os | osElfTarget os
+ -> "\t.section .debug_" ++ name ++ ",\"\",@progbits"
+ | osMachOTarget os
+ -> "\t.section __DWARF,__debug_" ++ name ++ ",regular,debug"
+ | otherwise
+ -> "\t.section .debug_" ++ name ++ ",\"dr\""
-- | Dwarf section labels
dwarfInfoLabel, dwarfAbbrevLabel, dwarfLineLabel, dwarfFrameLabel :: LitString
diff --git a/compiler/nativeGen/Dwarf/Types.hs b/compiler/nativeGen/Dwarf/Types.hs
index 520b5ae027..00d0535a07 100644
--- a/compiler/nativeGen/Dwarf/Types.hs
+++ b/compiler/nativeGen/Dwarf/Types.hs
@@ -119,7 +119,7 @@ pprDwarfInfoOpen haveSrc (DwarfCompileUnit _ name producer compDir lineLbl) =
$$ pprString compDir
$$ pprFlag True -- use UTF8
$$ if haveSrc
- then pprData4' (sectionOffset lineLbl dwarfLineLabel)
+ then sectionOffset lineLbl dwarfLineLabel
else empty
pprDwarfInfoOpen _ (DwarfSubprogram _ name label) = sdocWithDynFlags $ \df ->
pprAbbrev DwAbbrSubprogram
@@ -431,11 +431,13 @@ escapeChar c
-- | Generate an offset into another section. This is tricky because
-- this is handled differently depending on platform: Mac Os expects
--- us to calculate the offset using assembler arithmetic. Meanwhile,
--- GNU tools expect us to just reference the target directly, and will
--- figure out on their own that we actually need an offset.
+-- us to calculate the offset using assembler arithmetic. Linux expects
+-- us to just reference the target directly, and will figure out on
+-- their own that we actually need an offset. Finally, Windows has
+-- a special directive to refer to relative offsets. Fun.
sectionOffset :: LitString -> LitString -> SDoc
sectionOffset target section = sdocWithPlatform $ \plat ->
case platformOS plat of
- OSDarwin -> ptext target <> char '-' <> ptext section
- _other -> ptext target
+ OSDarwin -> pprDwWord (ptext target <> char '-' <> ptext section)
+ OSMinGW32 -> text "\t.secrel32 " <> ptext target
+ _other -> pprDwWord (ptext target)