[Git][ghc/ghc][master] Move via-C flags into GHC

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Tue May 30 21:08:39 UTC 2023



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
6629f1c5 by Ben Gamari at 2023-05-30T17:08:20-04: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.

- - - - -


9 changed files:

- compiler/GHC/Settings/IO.hs
- configure.ac
- distrib/configure.ac.in
- 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,14 +622,15 @@ 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
 dnl    RISCV64 GCC.
 FP_CC_SUPPORTS__ATOMICS
 
-FP_GCC_EXTRA_FLAGS
-
 dnl ** look to see if we have a C compiler using an llvm back end.
 dnl
 FP_CC_LLVM_BACKEND


=====================================
distrib/configure.ac.in
=====================================
@@ -164,7 +164,7 @@ AC_SUBST([OptCmd])
 dnl ** Check gcc version and flags we need to pass it **
 FP_GCC_VERSION
 FP_GCC_SUPPORTS_NO_PIE
-FP_GCC_EXTRA_FLAGS
+FP_GCC_SUPPORTS_VIA_C_FLAGS
 
 FPTOOLS_SET_C_LD_FLAGS([target],[CFLAGS],[LDFLAGS],[IGNORE_LINKER_LD_FLAGS],[CPPFLAGS])
 FPTOOLS_SET_C_LD_FLAGS([build],[CONF_CC_OPTS_STAGE0],[CONF_GCC_LINKER_OPTS_STAGE0],[CONF_LD_LINKER_OPTS_STAGE0],[CONF_CPP_OPTS_STAGE0])


=====================================
hadrian/bindist/Makefile
=====================================
@@ -79,8 +79,7 @@ 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 command", "$(SettingsCCompilerCommand)")' >> $@
 	@echo ',("C compiler flags", "$(SettingsCCompilerFlags)")' >> $@
 	@echo ',("C++ compiler command", "$(SettingsCxxCompilerCommand)")' >> $@
 	@echo ',("C++ compiler flags", "$(SettingsCxxCompilerFlags)")' >> $@


=====================================
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 -fno-builtin])
+   fi
+   rm -f conftest.c conftest.o conftest
+])
+



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6629f1c58a714405ba94e93d54a9c471f6f62914

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6629f1c58a714405ba94e93d54a9c471f6f62914
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/20230530/d7a9d5a6/attachment-0001.html>


More information about the ghc-commits mailing list