diff --git a/aclocal.m4 b/aclocal.m4 index c31c881466fffdb0e8eb78a54f01eac1273a8104..71a874fa78e9c58d0335a013c35bf99663d485ca 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,\"\",@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 1427a51baced31524d72708b84cd3806cbce4212..f40c8baed6dcabfe50f235883c4e277784e1adbf 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 ad0e0c8c8abd827ec2f0045617f32759392bc2cc..a6873fb640f409b313a155dcbffa179873120922 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,\"\",@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 50f11a72a8856b5e35e49da9ed14eadec7bbfa90..599d4d9160ed5ca673a917c85d9883d64d7c0422 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 e7a3efdfbe37bc0a428bb5d4a549b21216822de2..45d170e28d23b2eaea772fe5eeb2b281c53b36ba 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,\"\",@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 880c7d77a0de7dc3679896bca4bd01b6182c3d85..a8034ef295a299bd738f4e3fea09339ef403bff4 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 ++ ",\"\",@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 76ac13ef4ba99047b600c459a1766f6f1c708aac..aca427449d65ae3235eb0ad580fcbc432f4e1464 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\",@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 0000000000000000000000000000000000000000..55f9d6d551e650de56659286dd0951770f5feccf --- /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