[commit: ghc] master: Use correct section types syntax for architecture (9b9f978)

git at git.haskell.org git at git.haskell.org
Tue Jul 11 20:41:43 UTC 2017


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/9b9f978fdcd13ff7b2a9b7391e02dff06da622a0/ghc

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

commit 9b9f978fdcd13ff7b2a9b7391e02dff06da622a0
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Tue Jul 11 15:41:55 2017 -0400

    Use correct section types syntax for architecture
    
    Previously GHC would always assume that section types began with `@` while
    producing assembly, which is not true. For instance, in ARM assembly syntax
    section types begin with `%`. This abstracts out section type pretty-printing
    and adjusts it to correctly account for the target architectures assembly
    flavor.
    
    Reviewers: austin, hvr, Phyx
    
    Reviewed By: Phyx
    
    Subscribers: Phyx, rwbarton, thomie, erikd
    
    GHC Trac Issues: #13937
    
    Differential Revision: https://phabricator.haskell.org/D3712


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

9b9f978fdcd13ff7b2a9b7391e02dff06da622a0
 aclocal.m4                            | 11 ++++++++++-
 compiler/ghc.cabal.in                 |  1 +
 compiler/main/DriverPipeline.hs       |  6 ++++--
 compiler/main/Elf.hs                  | 14 ++++----------
 compiler/nativeGen/AsmCodeGen.hs      |  3 ++-
 compiler/nativeGen/Dwarf/Constants.hs | 10 ++++++----
 compiler/nativeGen/PprBase.hs         |  3 ++-
 compiler/utils/AsmUtils.hs            | 18 ++++++++++++++++++
 8 files changed, 47 insertions(+), 19 deletions(-)

diff --git a/aclocal.m4 b/aclocal.m4
index c31c881..71a874f 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -321,9 +321,18 @@ AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS],
     dnl so we empty CFLAGS while running this test
     CFLAGS2="$CFLAGS"
     CFLAGS=
+    case $TargetArch in
+      arm)
+        dnl See #13937.
+        progbits="%progbits"
+        ;;
+      *)
+        progbits="@progbits"
+        ;;
+    esac
     AC_MSG_CHECKING(for GNU non-executable stack support)
     AC_COMPILE_IFELSE(
-        [AC_LANG_PROGRAM([__asm__ (".section .note.GNU-stack,\"\", at progbits");], [0])],
+        [AC_LANG_PROGRAM([__asm__ (".section .note.GNU-stack,\"\",$progbits");], [0])],
         [AC_MSG_RESULT(yes)
          HaskellHaveGnuNonexecStack=True],
         [AC_MSG_RESULT(no)
diff --git a/compiler/ghc.cabal.in b/compiler/ghc.cabal.in
index 1427a51..f40c8ba 100644
--- a/compiler/ghc.cabal.in
+++ b/compiler/ghc.cabal.in
@@ -170,6 +170,7 @@ Library
         NameShape
         RnModIface
         Avail
+        AsmUtils
         BasicTypes
         ConLike
         DataCon
diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
index ad0e0c8..a6873fb 100644
--- a/compiler/main/DriverPipeline.hs
+++ b/compiler/main/DriverPipeline.hs
@@ -35,6 +35,7 @@ module DriverPipeline (
 
 #include "HsVersions.h"
 
+import AsmUtils
 import PipelineMonad
 import Packages
 import HeaderInfo
@@ -1714,14 +1715,15 @@ mkNoteObjsToLinkIntoBinary dflags dep_packages = do
   where
     link_opts info = hcat [
       -- "link info" section (see Note [LinkInfo section])
-      makeElfNote dflags ghcLinkInfoSectionName ghcLinkInfoNoteName 0 info,
+      makeElfNote ghcLinkInfoSectionName ghcLinkInfoNoteName 0 info,
 
       -- ALL generated assembly must have this section to disable
       -- executable stacks.  See also
       -- compiler/nativeGen/AsmCodeGen.hs for another instance
       -- where we need to do this.
       if platformHasGnuNonexecStack (targetPlatform dflags)
-        then text ".section .note.GNU-stack,\"\", at progbits\n"
+        then text ".section .note.GNU-stack,\"\","
+             <> sectionType "progbits" <> char '\n'
         else Outputable.empty
       ]
 
diff --git a/compiler/main/Elf.hs b/compiler/main/Elf.hs
index 50f11a7..599d4d9 100644
--- a/compiler/main/Elf.hs
+++ b/compiler/main/Elf.hs
@@ -14,9 +14,9 @@ module Elf (
     makeElfNote
   ) where
 
+import AsmUtils
 import Exception
 import DynFlags
-import Platform
 import ErrUtils
 import Maybes     (MaybeT(..),runMaybeT)
 import Util       (charToC)
@@ -415,12 +415,12 @@ readElfNoteAsString dflags path sectionName noteId = action `catchIO`  \_ -> do
 -- If we add new target platforms, we need to check that the generated words
 -- are 32-bit long, otherwise we need to use platform specific directives to
 -- force 32-bit .int in asWord32.
-makeElfNote :: DynFlags -> String -> String -> Word32 -> String -> SDoc
-makeElfNote dflags sectionName noteName typ contents = hcat [
+makeElfNote :: String -> String -> Word32 -> String -> SDoc
+makeElfNote sectionName noteName typ contents = hcat [
     text "\t.section ",
     text sectionName,
     text ",\"\",",
-    text elfSectionNote,
+    sectionType "note",
     text "\n",
 
     -- note name length (+ 1 for ending \0)
@@ -453,12 +453,6 @@ makeElfNote dflags sectionName noteName typ contents = hcat [
       text (show x),
       text "\n"]
 
-    elfSectionNote :: String
-    elfSectionNote = case platformArch (targetPlatform dflags) of
-                             ArchARM _ _ _ -> "%note"
-                             _             -> "@note"
-
-
 
 ------------------
 -- Helpers
diff --git a/compiler/nativeGen/AsmCodeGen.hs b/compiler/nativeGen/AsmCodeGen.hs
index e7a3efd..45d170e 100644
--- a/compiler/nativeGen/AsmCodeGen.hs
+++ b/compiler/nativeGen/AsmCodeGen.hs
@@ -51,6 +51,7 @@ import qualified RegAlloc.Graph.Main            as Color
 import qualified RegAlloc.Graph.Stats           as Color
 import qualified RegAlloc.Graph.TrivColorable   as Color
 
+import AsmUtils
 import TargetReg
 import Platform
 import Config
@@ -770,7 +771,7 @@ makeImportsDoc dflags imports
                 -- security. GHC generated code does not need an executable
                 -- stack so add the note in:
             (if platformHasGnuNonexecStack platform
-             then text ".section .note.GNU-stack,\"\", at progbits"
+             then text ".section .note.GNU-stack,\"\"," <> sectionType "progbits"
              else Outputable.empty)
             $$
                 -- And just because every other compiler does, let's stick in
diff --git a/compiler/nativeGen/Dwarf/Constants.hs b/compiler/nativeGen/Dwarf/Constants.hs
index 880c7d7..a8034ef 100644
--- a/compiler/nativeGen/Dwarf/Constants.hs
+++ b/compiler/nativeGen/Dwarf/Constants.hs
@@ -3,6 +3,7 @@
 
 module Dwarf.Constants where
 
+import AsmUtils
 import FastString
 import Platform
 import Outputable
@@ -150,14 +151,15 @@ dwarfGhcSection     = dwarfSection "ghc"
 dwarfARangesSection = dwarfSection "aranges"
 
 dwarfSection :: String -> SDoc
-dwarfSection name = sdocWithPlatform $ \plat -> ftext $ mkFastString $
+dwarfSection name = sdocWithPlatform $ \plat ->
   case platformOS plat of
     os | osElfTarget os
-       -> "\t.section .debug_" ++ name ++ ",\"\", at progbits"
+       -> text "\t.section .debug_" <> text name <> text ",\"\","
+          <> sectionType "progbits"
        | osMachOTarget os
-       -> "\t.section __DWARF,__debug_" ++ name ++ ",regular,debug"
+       -> text "\t.section __DWARF,__debug_" <> text name <> text ",regular,debug"
        | otherwise
-       -> "\t.section .debug_" ++ name ++ ",\"dr\""
+       -> text "\t.section .debug_" <> text name <> text ",\"dr\""
 
 -- * Dwarf section labels
 dwarfInfoLabel, dwarfAbbrevLabel, dwarfLineLabel, dwarfFrameLabel :: LitString
diff --git a/compiler/nativeGen/PprBase.hs b/compiler/nativeGen/PprBase.hs
index 76ac13e..aca4274 100644
--- a/compiler/nativeGen/PprBase.hs
+++ b/compiler/nativeGen/PprBase.hs
@@ -16,6 +16,7 @@ module PprBase (
 
 where
 
+import AsmUtils
 import CLabel
 import Cmm
 import DynFlags
@@ -131,7 +132,7 @@ pprGNUSectionHeader sep t suffix = sdocWithDynFlags $ \dflags ->
       CString
         | OSMinGW32 <- platformOS (targetPlatform dflags)
                     -> empty
-        | otherwise -> text ",\"aMS\", at progbits,1"
+        | otherwise -> text ",\"aMS\"," <> sectionType "progbits" <> text ",1"
       _ -> empty
 
 -- XCOFF doesn't support relocating label-differences, so we place all
diff --git a/compiler/utils/AsmUtils.hs b/compiler/utils/AsmUtils.hs
new file mode 100644
index 0000000..55f9d6d
--- /dev/null
+++ b/compiler/utils/AsmUtils.hs
@@ -0,0 +1,18 @@
+-- | Various utilities used in generating assembler.
+--
+-- These are used not only by the native code generator, but also by the
+-- "DriverPipeline".
+module AsmUtils
+    ( sectionType
+    ) where
+
+import Platform
+import Outputable
+
+-- | Generate a section type (e.g. @\@progbits@). See #13937.
+sectionType :: String -- ^ section type
+            -> SDoc   -- ^ pretty assembler fragment
+sectionType ty = sdocWithPlatform $ \platform ->
+    case platformArch platform of
+      ArchARM{} -> char '%' <> text ty
+      _         -> char '@' <> text ty



More information about the ghc-commits mailing list