[Git][ghc/ghc][wip/toolchain-selection] ghc-toolchain: Check Cc supports extra-via-c-flags

Rodrigo Mesquita (@alt-romes) gitlab at gitlab.haskell.org
Mon May 29 14:24:40 UTC 2023



Rodrigo Mesquita pushed to branch wip/toolchain-selection at Glasgow Haskell Compiler / GHC


Commits:
e78dd2e1 by Rodrigo Mesquita at 2023-05-29T15:24:32+01:00
ghc-toolchain: Check Cc supports extra-via-c-flags

- - - - -


4 changed files:

- configure.ac
- distrib/configure.ac.in
- − m4/fp_gcc_supports_via_c_flags.m4
- utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cc.hs


Changes:

=====================================
configure.ac
=====================================
@@ -588,10 +588,6 @@ dnl --------------------------------------------------------------
 dnl ** does #! work?
 AC_SYS_INTERPRETER()
 
-dnl ROMES:TODO: Make this check in ghc-toolchain
-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


=====================================
distrib/configure.ac.in
=====================================
@@ -143,9 +143,6 @@ FIND_LLVM_PROG([OPT], [opt], [$LlvmMinVersion], [$LlvmMaxVersion])
 OptCmd="$OPT"
 AC_SUBST([OptCmd])
 
-# ROMES:TODO: Move this to ghc-toolchain
-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])
 FPTOOLS_SET_C_LD_FLAGS([target],[CONF_CC_OPTS_STAGE1],[CONF_GCC_LINKER_OPTS_STAGE1],[CONF_LD_LINKER_OPTS_STAGE1],[CONF_CPP_OPTS_STAGE1])


=====================================
m4/fp_gcc_supports_via_c_flags.m4 deleted
=====================================
@@ -1,17 +0,0 @@
-# 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
-])
-


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cc.hs
=====================================
@@ -11,6 +11,8 @@ module GHC.Toolchain.Tools.Cc
     , addPlatformDepCcFlags
     ) where
 
+import Control.Monad
+import Data.List (isInfixOf) -- Wouldn't it be better to use bytestring?
 import System.FilePath
 
 import GHC.Platform.ArchOS
@@ -32,6 +34,7 @@ findCc progOpt = checking "for C compiler" $ do
     cc <- ignoreUnusedArgs $ Cc {ccProgram}
     checkCcWorks cc
     checkC99Support cc
+    checkCcSupportsExtraViaCFlags cc
     return cc
 
 checkCcWorks :: Cc -> M ()
@@ -63,6 +66,23 @@ checkC99Support cc = checking "for C99 support" $ withTempDir $ \dir -> do
         , "#endif"
         ]
 
+checkCcSupportsExtraViaCFlags :: Cc -> M ()
+checkCcSupportsExtraViaCFlags cc = checking "whether cc supports extra via-c flags" $ withTempDir $ \dir -> do
+  let test_o = dir </> "test.o"
+      test_c = test_o -<.> "c"
+  writeFile test_c "int main() { return 0; }"
+  (code, out, err) <- readProgram (ccProgram cc)
+                                  [ "-fwrapv", "-fno-builtin"
+                                  , "-Werror", "-x", "c"
+                                  , "-o", test_o, test_c]
+  when (not (isSuccess code)
+        || "unrecognized" `isInfixOf` out
+        || "unrecognized" `isInfixOf` err
+        ) $
+    throwE "Your C compiler must support the -fwrapv and -fno-builtin flags"
+  
+    
+
 -- | Preprocess the given program.
 preprocess
     :: Cc



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e78dd2e19a1b556d77ba1ee4e79e964e2002dac3
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/20230529/ffb40395/attachment-0001.html>


More information about the ghc-commits mailing list