[commit: ghc] master: Dwarf: Use .short instead of .hword on Darwin (3640ae9)

git at git.haskell.org git at git.haskell.org
Sat Dec 12 17:38:51 UTC 2015


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/3640ae92fc1ffa283425203bba3dbf231fcb3e52/ghc

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

commit 3640ae92fc1ffa283425203bba3dbf231fcb3e52
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Sat Dec 12 17:00:10 2015 +0100

    Dwarf: Use .short instead of .hword on Darwin
    
    Apparently gnu as uses `.short` as a synonym for `.word`. To emit a
    16-bit value one would use `.hword`. However, Darwin doesn't support
    `.hword`, instead taking `.short` to mean a 16-bit value. The
    insanity is nearly unbearable!
    
    OS X reference:
    https://developer.apple.com/library/mac/documentation/DeveloperTools/Ref
    erence/Assembler/040-Assembler_Directives/asm_directives.html#//apple_re
    f/doc/uid/TP30000823-TPXREF101
    
    gnu as reference:
    https://sourceware.org/binutils/docs/as/hword.html#hword
    
    Test Plan: Validate
    
    Reviewers: austin
    
    Reviewed By: austin
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D1602
    
    GHC Trac Issues: #11202


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

3640ae92fc1ffa283425203bba3dbf231fcb3e52
 compiler/nativeGen/Dwarf/Types.hs | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/compiler/nativeGen/Dwarf/Types.hs b/compiler/nativeGen/Dwarf/Types.hs
index 91a5e41..e80f2a1 100644
--- a/compiler/nativeGen/Dwarf/Types.hs
+++ b/compiler/nativeGen/Dwarf/Types.hs
@@ -477,7 +477,14 @@ pprByte x = ptext (sLit "\t.byte ") <> ppr (fromIntegral x :: Word)
 
 -- | Assembly for a two-byte constant integer
 pprHalf :: Word16 -> SDoc
-pprHalf x = ptext (sLit "\t.hword ") <> ppr (fromIntegral x :: Word)
+pprHalf x = sdocWithPlatform $ \plat ->
+  -- Naturally Darwin doesn't support `.hword` and binutils uses `.short`
+  -- as a synonym for `.word` (but only some of the time!). The madness
+  -- is nearly too much to bear.
+  let dir = case platformOS plat of
+        OSDarwin -> text ".short"
+        _        -> text ".hword"
+  in text "\t" <> dir <+> ppr (fromIntegral x :: Word)
 
 -- | Assembly for a constant DWARF flag
 pprFlag :: Bool -> SDoc



More information about the ghc-commits mailing list