Commit 7dd60ddd authored by Ian Lynagh's avatar Ian Lynagh

Convert the HAVE_GNU_NONEXEC_STACK conditional into Haskell

parent 723929bc
......@@ -239,6 +239,23 @@ AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS],
[HaskellHaveSubsectionsViaSymbols=False
AC_MSG_RESULT(no)])
dnl *** check for GNU non-executable stack note support (ELF only)
dnl (.section .note.GNU-stack,"",@progbits)
dnl This test doesn't work with "gcc -g" in gcc 4.4 (GHC trac #3889:
dnl Error: can't resolve `.note.GNU-stack' {.note.GNU-stack section} - `.Ltext0' {.text section}
dnl so we empty CFLAGS while running this test
CFLAGS2="$CFLAGS"
CFLAGS=
AC_MSG_CHECKING(for GNU non-executable stack support)
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([__asm__ (".section .note.GNU-stack,\"\",@progbits");], [0])],
[AC_MSG_RESULT(yes)
HaskellHaveGnuNonexecStack=True],
[AC_MSG_RESULT(no)
HaskellHaveGnuNonexecStack=False])
CFLAGS="$CFLAGS2"
checkArch "$BuildArch" ""
checkVendor "$BuildVendor"
checkOS "$BuildOS" ""
......@@ -254,6 +271,7 @@ AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS],
AC_SUBST(HaskellTargetArch)
AC_SUBST(HaskellTargetOs)
AC_SUBST(HaskellHaveSubsectionsViaSymbols)
AC_SUBST(HaskellHaveGnuNonexecStack)
])
......
......@@ -191,6 +191,7 @@ initSysTools mbMinusB
Nothing -> pgmError ("No entry for " ++ show key ++ " in " ++ show settingsFile)
; targetArch <- readSetting "target arch"
; targetOS <- readSetting "target os"
; targetHasGnuNonexecStack <- readSetting "target has GNU nonexec stack"
; targetHasSubsectionsViaSymbols <- readSetting "target has subsections via symbols"
; myExtraGccViaCFlags <- getSetting "GCC extra via C opts"
-- On Windows, mingw is distributed with GHC,
......@@ -254,6 +255,7 @@ initSysTools mbMinusB
sTargetPlatform = Platform {
platformArch = targetArch,
platformOS = targetOS,
platformHasGnuNonexecStack = targetHasGnuNonexecStack,
platformHasSubsectionsViaSymbols = targetHasSubsectionsViaSymbols
},
sTmpDir = normalise tmpdir,
......
......@@ -507,17 +507,18 @@ makeImportsDoc dflags imports
(if platformHasSubsectionsViaSymbols (targetPlatform dflags)
then Pretty.text ".subsections_via_symbols"
else Pretty.empty)
#if HAVE_GNU_NONEXEC_STACK
Pretty.$$
-- On recent GNU ELF systems one can mark an object file
-- as not requiring an executable stack. If all objects
-- linked into a program have this note then the program
-- will not use an executable stack, which is good for
-- security. GHC generated code does not need an executable
-- stack so add the note in:
Pretty.$$ Pretty.text ".section .note.GNU-stack,\"\",@progbits"
#endif
(if platformHasGnuNonexecStack (targetPlatform dflags)
then Pretty.text ".section .note.GNU-stack,\"\",@progbits"
else Pretty.empty)
-- And just because every other compiler does, lets stick in
-- an identifier directive: .ident "GHC x.y.z"
-- an identifier directive: .ident "GHC x.y.z"
Pretty.$$ let compilerIdent = Pretty.text "GHC" Pretty.<+>
Pretty.text cProjectVersion
in Pretty.text ".ident" Pretty.<+>
......
......@@ -22,6 +22,7 @@ data Platform
= Platform {
platformArch :: Arch,
platformOS :: OS,
platformHasGnuNonexecStack :: Bool,
platformHasSubsectionsViaSymbols :: Bool
}
deriving (Read, Show, Eq)
......
......@@ -703,24 +703,6 @@ FP_PROG_LD_X
FP_PROG_LD_IS_GNU
FP_PROG_LD_BUILD_ID
dnl *** check for GNU non-executable stack note support (ELF only)
dnl (.section .note.GNU-stack,"",@progbits)
dnl This test doesn't work with "gcc -g" in gcc 4.4 (GHC trac #3889:
dnl Error: can't resolve `.note.GNU-stack' {.note.GNU-stack section} - `.Ltext0' {.text section}
dnl so we empty CFLAGS while running this test
CFLAGS2="$CFLAGS"
CFLAGS=
AC_MSG_CHECKING(for GNU non-executable stack support)
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([__asm__ (".section .note.GNU-stack,\"\",@progbits");], [0])],
[AC_MSG_RESULT(yes)
AC_DEFINE([HAVE_GNU_NONEXEC_STACK],[1],
[Define to 1 if GNU non-executable stack notes are supported.])
],
[AC_MSG_RESULT(no)])
CFLAGS="$CFLAGS2"
FP_VISIBILITY_HIDDEN
dnl ** check for librt
......
......@@ -10,6 +10,7 @@
("perl command", "@SettingsPerlCommand@"),
("target os", "@HaskellTargetOs@"),
("target arch", "@HaskellTargetArch@"),
("target has GNU nonexec stack", "@HaskellHaveGnuNonexecStack@"),
("target has subsections via symbols", "@HaskellHaveSubsectionsViaSymbols@")
]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment