[Git][ghc/ghc][wip/toolchain-selection] Link is GNU linkerg

Rodrigo Mesquita (@alt-romes) gitlab at gitlab.haskell.org
Mon May 22 15:50:34 UTC 2023



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


Commits:
7a054eac by Rodrigo Mesquita at 2023-05-22T16:50:27+01:00
Link is GNU linkerg

- - - - -


4 changed files:

- hadrian/cfg/system.config.in
- hadrian/src/Rules/Generate.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Target.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs


Changes:

=====================================
hadrian/cfg/system.config.in
=====================================
@@ -93,7 +93,6 @@ project-git-commit-id  = @ProjectGitCommitId@
 # See Note [tooldir: How GHC finds mingw on Windows]
 
 gcc-extra-via-c-opts = @GccExtraViaCOpts@
-ld-is-gnu-ld = @LdIsGNULd@
 
 # ROMES:TODO: Drop almost every of these from settings.
 settings-c-compiler-command = @SettingsCCompilerCommand@


=====================================
hadrian/src/Rules/Generate.hs
=====================================
@@ -432,8 +432,8 @@ 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 $ queryTargetTargetConfig ldSupportsResponseFiles)
-        , ("ld is GNU ld", expr $ lookupSystemConfig "ld-is-gnu-ld")
+        , ("ld supports response files", expr $ queryTargetTargetConfig linkSupportsResponseFiles)
+        , ("ld is GNU ld", expr $ queryTargetTargetConfig linkIsGnu)
         , ("Merge objects command", expr $ settingsFileSetting ToolchainSetting_MergeObjectsCommand)
         , ("Merge objects flags", expr $ settingsFileSetting ToolchainSetting_MergeObjectsFlags)
         , ("ar command", expr $ settingsFileSetting ToolchainSetting_ArCommand)
@@ -480,9 +480,10 @@ 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
+    linkSupportsResponseFiles   = yesNo . Toolchain.ccLinkSupportsResponseFiles . Toolchain.tgtCCompilerLink
+    linkSupportsFilelist        = yesNo . Toolchain.ccLinkSupportsFilelist . Toolchain.tgtCCompilerLink
+    linkSupportsCompactUnwind   = yesNo . Toolchain.ccLinkSupportsCompactUnwind . Toolchain.tgtCCompilerLink
+    linkIsGnu                   = yesNo . Toolchain.ccLinkIsGnu . Toolchain.tgtCCompilerLink
     arFlags = unwords . prgFlags . Toolchain.arMkArchive . Toolchain.tgtAr
 
 


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Target.hs
=====================================
@@ -52,7 +52,6 @@ data Target = Target
     , tgtHsCPreprocessor :: HsCpp
     , tgtCCompilerLink :: CcLink
     -- , tgtLd :: Program -- needed? probably not, we link always through the c compiler
-    -- , tgtLdIsGnuLd :: Bool -- After rebase on LdHasGcSections (and renamed)
     , tgtAr :: Ar
     , tgtRanlib :: Maybe Ranlib -- Most ar implementations do good things by default without ranlib so don't need it
     , tgtNm :: Nm


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs
=====================================
@@ -22,6 +22,7 @@ data CcLink = CcLink { ccLinkProgram :: Program
                      , ccLinkSupportsCompactUnwind :: Bool -- Argument to be made about this being part of the cclink flags
                      , ccLinkSupportsFilelist :: Bool      -- This too
                      , ccLinkSupportsResponseFiles :: Bool
+                     , ccLinkIsGnu :: Bool -- We once thought this could instead be LdSupportsGcSections, but then realized it couldn't IIRC
                      }
     deriving (Show, Read, Eq, Ord)
 
@@ -40,9 +41,10 @@ findCcLink progOpt ldOverride archOs cc readelf = checking "for C compiler for l
   ccLinkSupportsCompactUnwind <- checkSupportsCompactUnwind cc ccLinkProgram
   ccLinkSupportsFilelist      <- checkSupportsFilelist      cc ccLinkProgram
   ccLinkSupportsResponseFiles <- checkSupportsResponseFiles cc ccLinkProgram
+  ccLinkIsGnu                 <- checkLinkIsGnu                ccLinkProgram
   checkBfdCopyBug archOs cc readelf ccLinkProgram
   ccLinkProgram <- addPlatformDepLinkFlags archOs cc ccLinkProgram
-  return $ CcLink {ccLinkProgram, ccLinkSupportsNoPie, ccLinkSupportsCompactUnwind, ccLinkSupportsFilelist, ccLinkSupportsResponseFiles}
+  return $ CcLink {ccLinkProgram, ccLinkSupportsNoPie, ccLinkSupportsCompactUnwind, ccLinkSupportsFilelist, ccLinkSupportsResponseFiles, ccLinkIsGnu}
 
 -- | Try to convince @cc@ to use a more efficient linker than @bfd.ld@
 findLinkFlags :: Maybe Bool -> Cc -> Program -> M Program
@@ -153,6 +155,11 @@ checkLinkWorks cc ccLink = withTempDir $ \dir -> do
     callProgram ccLink ["-o", out, test_o, main_o]
     expectFileExists out "linker didn't produce any output"
 
+checkLinkIsGnu :: Program -> M Bool
+checkLinkIsGnu ccLink = do
+  out <- readProgramStdout ccLink ["--version"]
+  return ("GNU" `isInfixOf` out)
+
 -- | Check for binutils bug #16177 present in some versions of the bfd ld
 -- implementation affecting ARM relocations.
 -- https://sourceware.org/bugzilla/show_bug.cgi?id=16177



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/7a054eac8761501d04432f0bc445068480a5bcce
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/20230522/36c5d7a1/attachment-0001.html>


More information about the ghc-commits mailing list