[commit: ghc] ghc-7.10: Fix DWARF generation for MinGW (#10468) (800888b)

git at git.haskell.org git at git.haskell.org
Fri Jun 12 18:56:39 UTC 2015


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

On branch  : ghc-7.10
Link       : http://ghc.haskell.org/trac/ghc/changeset/800888b0f56206038fe0b6276f6849fd24e3292b/ghc

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

commit 800888b0f56206038fe0b6276f6849fd24e3292b
Author: Peter Wortmann <scpmw at leeds.ac.uk>
Date:   Thu Jun 11 12:09:55 2015 -0500

    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.
    
    (cherry picked from commit a66ef3567ea29c93a9c010befc672602dc1c644c)


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

800888b0f56206038fe0b6276f6849fd24e3292b
 compiler/nativeGen/Dwarf.hs           |  2 +-
 compiler/nativeGen/Dwarf/Constants.hs | 12 +++++++-----
 compiler/nativeGen/Dwarf/Types.hs     | 14 ++++++++------
 3 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/compiler/nativeGen/Dwarf.hs b/compiler/nativeGen/Dwarf.hs
index ff86fd8..34f1ed6 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 2cd54a7..4b334fc 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 ++ ",\"\", at progbits"
+    os | osElfTarget os
+       -> "\t.section .debug_" ++ name ++ ",\"\", at 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 520b5ae..00d0535 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)



More information about the ghc-commits mailing list