[Git][ghc/ghc][wip/toolchain-selection] Configure CLink supports response files
Rodrigo Mesquita (@alt-romes)
gitlab at gitlab.haskell.org
Fri May 12 15:25:17 UTC 2023
Rodrigo Mesquita pushed to branch wip/toolchain-selection at Glasgow Haskell Compiler / GHC
Commits:
5295cbf8 by Rodrigo Mesquita at 2023-05-12T16:25:09+01:00
Configure CLink supports response files
- - - - -
3 changed files:
- hadrian/src/Rules/Generate.hs
- − m4/fp_ld_supports_response_files.m4
- utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs
Changes:
=====================================
hadrian/src/Rules/Generate.hs
=====================================
@@ -427,7 +427,7 @@ generateSettings = do
, ("ld flags", expr $ settingsFileSetting ToolchainSetting_LdFlags)
, ("ld supports compact unwind", expr $ queryTargetTargetConfig linkSupportsCompactUnwind)
, ("ld supports filelist", expr $ queryTargetTargetConfig ldSupportsFilelist)
- , ("ld supports response files", expr $ lookupSystemConfig "ld-supports-response-files")
+ , ("ld supports response files", expr $ queryTargetTargetConfig ldSupportsResponseFiles)
, ("ld is GNU ld", expr $ lookupSystemConfig "ld-is-gnu-ld")
, ("Merge objects command", expr $ settingsFileSetting ToolchainSetting_MergeObjectsCommand)
, ("Merge objects flags", expr $ settingsFileSetting ToolchainSetting_MergeObjectsFlags)
@@ -475,6 +475,7 @@ generateSettings = do
: ((\s' -> "," ++ showTuple s') <$> ss)
++ ["]"]
where
+ ldSupportsResponseFiles = yesNo . Toolchain.ccLinkSupportsResponseFiles . Toolchain.tgtCCompilerLink
ldSupportsFilelist = yesNo . Toolchain.ccLinkSupportsFilelist . Toolchain.tgtCCompilerLink
linkSupportsCompactUnwind = yesNo . Toolchain.ccLinkSupportsCompactUnwind . Toolchain.tgtCCompilerLink
arFlags = unwords . prgFlags . Toolchain.arMkArchive . Toolchain.tgtAr
=====================================
m4/fp_ld_supports_response_files.m4 deleted
=====================================
@@ -1,19 +0,0 @@
-# FP_LD_SUPPORTS_RESPONSE_FILES
-# --------------------
-# See if whether we are using a version of ld which supports response files.
-AC_DEFUN([FP_LD_SUPPORTS_RESPONSE_FILES], [
- AC_MSG_CHECKING([whether $LD supports response files])
- echo 'int main(void) {return 0;}' > conftest.c
- "$CC" -c -o conftest.o conftest.c > /dev/null 2>&1
- printf '%q\n' -o conftest conftest.o > args.txt
- if "$LD" -shared @args.txt > /dev/null 2>&1 || "$LD" -dylib @args.txt > /dev/null 2>&1
- then
- LdSupportsResponseFiles=YES
- AC_MSG_RESULT([yes])
- else
- LdSupportsResponseFiles=NO
- AC_MSG_RESULT([no])
- fi
- rm -f conftest.c conftest args.txt
- AC_SUBST(LdSupportsResponseFiles)
-])
=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs
=====================================
@@ -21,6 +21,7 @@ data CcLink = CcLink { ccLinkProgram :: Program
, ccLinkSupportsNoPie :: Bool -- Does have to be a separate settings. Sometimes we do want to use PIE
, ccLinkSupportsCompactUnwind :: Bool -- Argument to be made about this being part of the cclink flags
, ccLinkSupportsFilelist :: Bool -- This too
+ , ccLinkSupportsResponseFiles :: Bool
}
deriving (Show, Read, Eq, Ord)
@@ -37,9 +38,10 @@ findCcLink progOpt ldOverride archOs cc readelf = checking "for C compiler for l
ccLinkSupportsNoPie <- checkSupportsNoPie ccLinkProgram
ccLinkSupportsCompactUnwind <- checkSupportsCompactUnwind cc ccLinkProgram
ccLinkSupportsFilelist <- checkSupportsFilelist cc ccLinkProgram
+ ccLinkSupportsResponseFiles <- checkSupportsResponseFiles cc ccLinkProgram
checkBfdCopyBug archOs cc readelf ccLinkProgram
ccLinkProgram <- addPlatformDepLinkFlags archOs cc ccLinkProgram
- return $ CcLink {ccLinkProgram, ccLinkSupportsNoPie, ccLinkSupportsCompactUnwind, ccLinkSupportsFilelist}
+ return $ CcLink {ccLinkProgram, ccLinkSupportsNoPie, ccLinkSupportsCompactUnwind, ccLinkSupportsFilelist, ccLinkSupportsResponseFiles}
-- | Try to convince @cc@ to use a more efficient linker than @bfd.ld@
findLinkFlags :: Maybe Bool -> Cc -> Program -> M Program
@@ -81,7 +83,7 @@ doLinkerSearch = False
#endif
checkSupportsNoPie :: Program -> M Bool
-checkSupportsNoPie ccLink = checking "whether CC supports -no-pie" $
+checkSupportsNoPie ccLink = checking "whether the cc linker supports -no-pie" $
withTempDir $ \dir -> do
let test_c = dir </> "test.c"
writeFile test_c "int main() { return 0; }"
@@ -95,32 +97,26 @@ checkSupportsNoPie ccLink = checking "whether CC supports -no-pie" $
else return True
checkSupportsCompactUnwind :: Cc -> Program -> M Bool
-checkSupportsCompactUnwind cc ccLink = checking "whether ld understands -no_compact_unwind" $
+checkSupportsCompactUnwind cc ccLink = checking "whether the cc linker understands -no_compact_unwind" $
withTempDir $ \dir -> do
- let test_c = dir </> "test.c"
- test_o = dir </> "test.o"
+ let test_o = dir </> "o"
test2_o = dir </> "test2.o"
- writeFile test_c "int foo() { return 0; }"
- callProgram (ccProgram cc) ["-c", test_c]
+
+ compileC cc test_o "int foo() { return 0; }"
+
exitCode <- runProgram ccLink ["-r", "-no_compact_unwind", "-o", test2_o, test_o]
pure $ isSuccess exitCode
-
checkSupportsFilelist :: Cc -> Program -> M Bool
-checkSupportsFilelist cc ccLink = checking "whether ld understands -filelist" $
+checkSupportsFilelist cc ccLink = checking "whether the cc linker understands -filelist" $
withTempDir $ \dir -> do
let test_o = dir </> "test.o"
- test1_c = dir </> "test1.c"
- test2_c = dir </> "test2.c"
test1_o = dir </> "test1.o"
test2_o = dir </> "test2.o"
test_ofiles = dir </> "test.o-files"
- writeFile test1_c "int foo() { return 0; }"
- writeFile test2_c "int bar() { return 0; }"
-
- callProgram (ccProgram cc) ["-c", test1_c]
- callProgram (ccProgram cc) ["-c", test2_c]
+ compileC cc test1_o "int foo() { return 0; }"
+ compileC cc test2_o "int bar() { return 0; }"
writeFile test_ofiles test1_o -- write the filename test1_o to the test_ofiles file
appendFile test_ofiles test2_o -- append the filename test2_o to the test_ofiles file
@@ -129,6 +125,21 @@ checkSupportsFilelist cc ccLink = checking "whether ld understands -filelist" $
pure $ isSuccess exitCode
+checkSupportsResponseFiles :: Cc -> Program -> M Bool
+checkSupportsResponseFiles cc ccLink = checking "whether the cc linker supports response files" $
+ withTempDir $ \dir -> do
+ let test_o = dir </> "test.o"
+ compileC cc test_o "int main(void) {return 0;}"
+
+ let args_txt = dir </> "args.txt"
+ out = dir </> "test"
+ writeFile args_txt (unlines ["-o", out, test_o])
+
+ -- TODO: It'd be good to shortcircuit this logical `or`
+ exitCode1 <- runProgram ccLink ["-shared", "@"++args_txt]
+ exitCode2 <- runProgram ccLink ["-dylib", "@"++args_txt]
+ pure (isSuccess exitCode1 || isSuccess exitCode2)
+
-- | Check whether linking works.
checkLinkWorks :: Cc -> Program -> M ()
checkLinkWorks cc ccLink = withTempDir $ \dir -> do
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5295cbf8b4188f7d8f3b66fecea8cb5394c675b0
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5295cbf8b4188f7d8f3b66fecea8cb5394c675b0
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/20230512/dbebe81f/attachment-0001.html>
More information about the ghc-commits
mailing list