[Git][ghc/ghc][wip/move-via-c-flags-into-ghc] Move via-C flags into GHC

Rodrigo Mesquita (@alt-romes) gitlab at gitlab.haskell.org
Tue May 23 18:45:39 UTC 2023



Rodrigo Mesquita pushed to branch wip/move-via-c-flags-into-ghc at Glasgow Haskell Compiler / GHC


Commits:
99a4c996 by Ben Gamari at 2023-05-23T19:45:30+01:00
Move via-C flags into GHC

These were previously hardcoded in configure (with no option for
overriding them) and simply passed onto ghc through the settings file.

Since configure already guarantees gcc supports those flags, we simply
move them into GHC.

- - - - -


8 changed files:

- compiler/GHC/Settings/IO.hs
- configure.ac
- hadrian/bindist/Makefile
- hadrian/bindist/config.mk.in
- hadrian/cfg/system.config.in
- hadrian/src/Rules/Generate.hs
- − m4/fp_gcc_extra_flags.m4
- + m4/fp_gcc_supports_via_c_flags.m4


Changes:

=====================================
compiler/GHC/Settings/IO.hs
=====================================
@@ -76,7 +76,6 @@ initSettings top_dir = do
       getToolSetting :: String -> ExceptT SettingsError m String
       getToolSetting key = expandToolDir useInplaceMinGW mtool_dir <$> getSetting key
   targetPlatformString <- getSetting "target platform string"
-  myExtraGccViaCFlags <- getSetting "GCC extra via C opts"
   cc_prog <- getToolSetting "C compiler command"
   cxx_prog <- getToolSetting "C++ compiler command"
   cc_args_str <- getToolSetting "C compiler flags"
@@ -93,6 +92,16 @@ initSettings top_dir = do
       cpp_args = map Option (words cpp_args_str)
       cc_args  = words cc_args_str ++ unreg_cc_args
       cxx_args = words cxx_args_str
+
+      -- The extra flags we need to pass gcc when we invoke it to compile .hc code.
+      --
+      -- -fwrapv is needed for gcc to emit well-behaved code in the presence of
+      -- integer wrap around (#952).
+      extraGccViaCFlags = if platformUnregisterised platform
+                            -- configure guarantees cc support these flags
+                            then ["-fwrapv", "-fno-builtin"]
+                            else []
+
   ldSupportsCompactUnwind <- getBooleanSetting "ld supports compact unwind"
   ldSupportsFilelist      <- getBooleanSetting "ld supports filelist"
   ldSupportsResponseFiles <- getBooleanSetting "ld supports response files"
@@ -204,7 +213,7 @@ initSettings top_dir = do
       , toolSettings_opt_lc      = []
       , toolSettings_opt_i       = []
 
-      , toolSettings_extraGccViaCFlags = words myExtraGccViaCFlags
+      , toolSettings_extraGccViaCFlags = extraGccViaCFlags
       }
 
     , sTargetPlatform = platform


=====================================
configure.ac
=====================================
@@ -622,6 +622,9 @@ FP_GCC_VERSION
 dnl ** See whether cc supports -no-pie
 FP_GCC_SUPPORTS_NO_PIE
 
+dnl ** Check support for the extra flags passed by GHC when compiling via C
+FP_GCC_SUPPORTS_VIA_C_FLAGS
+
 dnl ** Used to determine how to compile ghc-prim's atomics.c, used by
 dnl    unregisterised, Sparc, and PPC backends. Also determines whether
 dnl    linking to libatomic is required for atomic operations, e.g. on


=====================================
hadrian/bindist/Makefile
=====================================
@@ -79,7 +79,6 @@ WrapperBinsDir=${bindir}
 # N.B. this is duplicated from includes/ghc.mk.
 lib/settings : config.mk
 	@rm -f $@
-	@echo '[("GCC extra via C opts", "$(GccExtraViaCOpts)")' >> $@
 	@echo ',("C compiler command", "$(SettingsCCompilerCommand)")' >> $@
 	@echo ',("C compiler flags", "$(SettingsCCompilerFlags)")' >> $@
 	@echo ',("C++ compiler command", "$(SettingsCxxCompilerCommand)")' >> $@


=====================================
hadrian/bindist/config.mk.in
=====================================
@@ -234,7 +234,6 @@ GhcRtsWithLibdw=$(strip $(if $(filter $(TargetArch_CPP),i386 x86_64 s390x), at UseL
 # might become redundant.
 # See Note [tooldir: How GHC finds mingw on Windows]
 
-GccExtraViaCOpts = @GccExtraViaCOpts@
 LdHasFilelist = @LdHasFilelist@
 LdSupportsResponseFiles = @LdSupportsResponseFiles@
 LdHasBuildId = @LdHasBuildId@


=====================================
hadrian/cfg/system.config.in
=====================================
@@ -137,7 +137,6 @@ conf-merge-objects-args-stage3  = @MergeObjsArgs@
 # might become redundant.
 # See Note [tooldir: How GHC finds mingw on Windows]
 
-gcc-extra-via-c-opts = @GccExtraViaCOpts@
 ld-has-no-compact-unwind = @LdHasNoCompactUnwind@
 ld-has-filelist = @LdHasFilelist@
 ld-supports-response-files = @LdSupportsResponseFiles@


=====================================
hadrian/src/Rules/Generate.hs
=====================================
@@ -411,8 +411,7 @@ generateSettings :: Expr String
 generateSettings = do
     ctx <- getContext
     settings <- traverse sequence $
-        [ ("GCC extra via C opts", expr $ lookupSystemConfig "gcc-extra-via-c-opts")
-        , ("C compiler command", expr $ settingsFileSetting SettingsFileSetting_CCompilerCommand)
+        [ ("C compiler command", expr $ settingsFileSetting SettingsFileSetting_CCompilerCommand)
         , ("C compiler flags", expr $ settingsFileSetting SettingsFileSetting_CCompilerFlags)
         , ("C++ compiler command", expr $ settingsFileSetting SettingsFileSetting_CxxCompilerCommand)
         , ("C++ compiler flags", expr $ settingsFileSetting SettingsFileSetting_CxxCompilerFlags)


=====================================
m4/fp_gcc_extra_flags.m4 deleted
=====================================
@@ -1,20 +0,0 @@
-# FP_GCC_EXTRA_FLAGS
-# ------------------
-# Determine which extra flags we need to pass gcc when we invoke it
-# to compile .hc code.
-#
-# -fwrapv is needed for gcc to emit well-behaved code in the presence of
-# integer wrap around. (#952)
-#
-AC_DEFUN([FP_GCC_EXTRA_FLAGS],
-[AC_REQUIRE([FP_GCC_VERSION])
-AC_CACHE_CHECK([for extra options to pass gcc when compiling via C], [fp_cv_gcc_extra_opts],
-[
- if test "$Unregisterised" = "YES"; then
-   # These used to be conditioned on gcc version but we no longer support
-   # GCC versions which lack support for these flags
-   fp_cv_gcc_extra_opts="-fwrapv -fno-builtin"
- fi
-])
-AC_SUBST([GccExtraViaCOpts],$fp_cv_gcc_extra_opts)
-])


=====================================
m4/fp_gcc_supports_via_c_flags.m4
=====================================
@@ -0,0 +1,17 @@
+# FP_GCC_SUPPORTS_VIA_C_FLAGS
+# ---------------------------
+# Make sure GCC supports the flags passed by GHC when compiling via C
+AC_DEFUN([FP_GCC_SUPPORTS_VIA_C_FLAGS],
+[
+   AC_REQUIRE([AC_PROG_CC])
+   AC_MSG_CHECKING([whether CC supports flags passed by GHC when compiling via C])
+   echo 'int main() { return 0; }' > conftest.c
+   if $CC -fwrapv -fno-builtin -Werror -x c conftest.c -o conftest > conftest.txt 2>&1 && ! grep -i unrecognized conftest.txt > /dev/null 2>&1; then
+       AC_MSG_RESULT([yes])
+   else
+       AC_MSG_RESULT([no])
+       AC_MSG_ERROR([gcc must support the flags -fwrapv and/or -fno-builtin])
+   fi
+   rm -f conftest.c conftest.o conftest
+])
+



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/99a4c996c926d4146e137fbf262a0f65283284c0

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/99a4c996c926d4146e137fbf262a0f65283284c0
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230523/1956e577/attachment-0001.html>


More information about the ghc-commits mailing list