Convert the HAVE_GNU_NONEXEC_STACK conditional into Haskell
authorIan Lynagh <igloo@earth.li>
Wed, 19 Oct 2011 16:33:25 +0000 (17:33 +0100)
committerIan Lynagh <igloo@earth.li>
Wed, 19 Oct 2011 16:33:25 +0000 (17:33 +0100)
aclocal.m4
compiler/main/SysTools.lhs
compiler/nativeGen/AsmCodeGen.lhs
compiler/utils/Platform.hs
configure.ac
settings.in

index 674ba16..f18e17f 100644 (file)
@@ -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)
 ])
 
 
index 0384179..1ce34bc 100644 (file)
@@ -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,
index 5b133d0..2df259f 100644 (file)
@@ -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.<+>
index 89d98e6..e99d706 100644 (file)
@@ -22,6 +22,7 @@ data Platform
         = Platform {
               platformArch                     :: Arch,
               platformOS                       :: OS,
+              platformHasGnuNonexecStack       :: Bool,
               platformHasSubsectionsViaSymbols :: Bool
           }
         deriving (Read, Show, Eq)
index f10b31f..5f62083 100644 (file)
@@ -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
index ef65651..c54fcfb 100644 (file)
@@ -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@")
  ]