[Git][ghc/ghc][wip/ghc-toolchain-fixes] 4 commits: ghc-toolchain: Parse javascript and ghcjs as a Arch and OS

Matthew Pickering (@mpickering) gitlab at gitlab.haskell.org
Thu Jul 27 10:04:32 UTC 2023



Matthew Pickering pushed to branch wip/ghc-toolchain-fixes at Glasgow Haskell Compiler / GHC


Commits:
08158c62 by Rodrigo Mesquita at 2023-07-26T17:08:14+01:00
ghc-toolchain: Parse javascript and ghcjs as a Arch and OS

- - - - -
f57983f0 by Rodrigo Mesquita at 2023-07-26T17:08:31+01:00
ghc-toolchain: Fix ranlib option

- - - - -
aba57719 by Rodrigo Mesquita at 2023-07-26T17:09:40+01:00
Check Link Works with -Werror

- - - - -
ac8584b4 by Matthew Pickering at 2023-07-27T11:02:06+01:00
Only check for no_compact_unwind support on darwin

While writing ghc-toolchain we noticed that the
FP_PROG_LD_NO_COMPACT_UNWIND check is subtly wrong. Specifically, we
pass -Wl,-no_compact_unwind to cc. However, ld.gold interprets this as
-n o_compact_unwind, which is a valid argument.

Fixes #23676

- - - - -


4 changed files:

- m4/fp_prog_ld_no_compact_unwind.m4
- utils/ghc-toolchain/exe/Main.hs
- utils/ghc-toolchain/src/GHC/Toolchain/ParseTriple.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs


Changes:

=====================================
m4/fp_prog_ld_no_compact_unwind.m4
=====================================
@@ -5,14 +5,21 @@
 AC_DEFUN([FP_PROG_LD_NO_COMPACT_UNWIND],
 [
 AC_CACHE_CHECK([whether ld understands -no_compact_unwind], [fp_cv_ld_no_compact_unwind],
-[echo 'int foo() { return 0; }' > conftest.c
-${CC-cc} -c conftest.c
-if $LD -r -no_compact_unwind -o conftest2.o conftest.o > /dev/null 2>&1; then
-   fp_cv_ld_no_compact_unwind=yes
-else
-   fp_cv_ld_no_compact_unwind=no
-fi
-rm -rf conftest*])
+[
+case $build in
+  *-darwin)
+  echo 'int foo() { return 0; }' > conftest.c
+  ${CC-cc} -c conftest.c
+  if $LD -r -no_compact_unwind -o conftest2.o conftest.o > /dev/null 2>&1; then
+     fp_cv_ld_no_compact_unwind=yes
+  else
+     fp_cv_ld_no_compact_unwind=no
+  fi
+  rm -rf conftest* ;;
+  *)
+  fp_cv_ld_no_compact_unwind=no ;;
+esac
+])
 FP_CAPITALIZE_YES_NO(["$fp_cv_ld_no_compact_unwind"], [LdHasNoCompactUnwind])
 AC_SUBST([LdHasNoCompactUnwind])
 ])# FP_PROG_LD_NO_COMPACT_UNWIND


=====================================
utils/ghc-toolchain/exe/Main.hs
=====================================
@@ -146,7 +146,7 @@ options =
     , progOpts "cxx" "C++ compiler" _optCxx
     , progOpts "cc-link" "C compiler for linking" _optCcLink
     , progOpts "ar" "ar archiver" _optAr
-    , progOpts "ranlib" "ranlib utility" _optAr
+    , progOpts "ranlib" "ranlib utility" _optRanlib
     , progOpts "nm" "nm archiver" _optNm
     , progOpts "readelf" "readelf utility" _optReadelf
     , progOpts "merge-objs" "linker for merging objects" _optMergeObjs


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/ParseTriple.hs
=====================================
@@ -53,6 +53,7 @@ parseArch cc arch =
       "riscv64" -> pure ArchRISCV64
       "hppa" -> pure ArchUnknown
       "wasm32" -> pure ArchWasm32
+      "javascript" -> pure ArchJavaScript
       _ -> throwE $ "Unknown architecture " ++ arch
 
 parseOs :: String -> M OS
@@ -76,6 +77,7 @@ parseOs os =
       "aix" -> pure OSAIX
       "gnu" -> pure OSHurd
       "wasi" -> pure OSWasi
+      "ghcjs" -> pure OSGhcjs
       _ -> throwE $ "Unknown operating system " ++ os
 
 splitOn :: Char -> String -> [String]


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs
=====================================
@@ -57,7 +57,7 @@ findCcLink target progOpt ldOverride archOs cc readelf = checking "for C compile
                          findLinkFlags ldOverride cc rawCcLink <|> pure rawCcLink
   ccLinkProgram <- linkSupportsTarget cc target ccLinkProgram
   ccLinkSupportsNoPie         <- checkSupportsNoPie            ccLinkProgram
-  ccLinkSupportsCompactUnwind <- checkSupportsCompactUnwind cc ccLinkProgram
+  ccLinkSupportsCompactUnwind <- checkSupportsCompactUnwind archOs cc ccLinkProgram
   ccLinkSupportsFilelist      <- checkSupportsFilelist      cc ccLinkProgram
   ccLinkIsGnu                 <- checkLinkIsGnu                ccLinkProgram
   checkBfdCopyBug archOs cc readelf ccLinkProgram
@@ -124,16 +124,18 @@ checkSupportsNoPie ccLink = checking "whether the cc linker supports -no-pie" $
 -- * Check if compiling for darwin
 -- * Then do the check
 -- * Otherwise say its just not supported
-checkSupportsCompactUnwind :: Cc -> Program -> M Bool
-checkSupportsCompactUnwind cc ccLink = checking "whether the cc linker understands -no_compact_unwind" $
-  withTempDir $ \dir -> do
-    let test_o  = dir </> "test.o"
-        test2_o = dir </> "test2.o"
+checkSupportsCompactUnwind :: ArchOS -> Cc -> Program -> M Bool
+checkSupportsCompactUnwind archOs cc ccLink
+  | OSDarwin <- archOS_OS archOs = checking "whether the cc linker understands -no_compact_unwind" $
+      withTempDir $ \dir -> do
+        let test_o  = dir </> "test.o"
+            test2_o = dir </> "test2.o"
 
-    compileC cc test_o "int foo() { return 0; }"
+        compileC cc test_o "int foo() { return 0; }"
 
-    exitCode <- runProgram ccLink ["-r", "-Wl,-no_compact_unwind", "-o", test2_o, test_o]
-    return $ isSuccess exitCode
+        exitCode <- runProgram ccLink ["-r", "-Wl,-no_compact_unwind", "-o", test2_o, test_o]
+        return $ isSuccess exitCode
+  | otherwise = return False
 
 checkSupportsFilelist :: Cc -> Program -> M Bool
 checkSupportsFilelist cc ccLink = checking "whether the cc linker understands -filelist" $
@@ -163,7 +165,7 @@ checkLinkWorks cc ccLink = withTempDir $ \dir -> do
 
     let out = dir </> "test"
         err = "linker didn't produce any output"
-    callProgram ccLink ["-o", out, test_o, main_o]
+    callProgram ccLink ["-Werror", "-o", out, test_o, main_o]
     expectFileExists out err
       -- Linking in windows might produce an executable with an ".exe" extension
       <|> expectFileExists (out <.> "exe") err



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0c2ba60da2991a08bdd01af9d3d267da1c9f5086...ac8584b429184fb6f10fa3d6ee7068239b3a8a0c

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0c2ba60da2991a08bdd01af9d3d267da1c9f5086...ac8584b429184fb6f10fa3d6ee7068239b3a8a0c
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/20230727/67594551/attachment-0001.html>


More information about the ghc-commits mailing list