[Git][ghc/ghc][master] 4 commits: Push DynFlags out of runInstallNameTool

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Tue Dec 6 20:46:58 UTC 2022



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


Commits:
21d66db1 by mrkun at 2022-12-06T15:46:38-05:00
Push DynFlags out of runInstallNameTool

- - - - -
aaaaa79b by mrkun at 2022-12-06T15:46:38-05:00
Push DynFlags out of askOtool

- - - - -
4e28f49e by mrkun at 2022-12-06T15:46:38-05:00
Push DynFlags out of runInjectRPaths

- - - - -
a7422580 by mrkun at 2022-12-06T15:46:38-05:00
Push DynFlags out of Linker.MacOS

- - - - -


8 changed files:

- + compiler/GHC/Driver/Config/Linker.hs
- compiler/GHC/Driver/Session.hs
- + compiler/GHC/Linker/Config.hs
- compiler/GHC/Linker/Dynamic.hs
- compiler/GHC/Linker/MacOS.hs
- compiler/GHC/Linker/Static.hs
- compiler/GHC/SysTools/Tasks.hs
- compiler/ghc.cabal.in


Changes:

=====================================
compiler/GHC/Driver/Config/Linker.hs
=====================================
@@ -0,0 +1,13 @@
+module GHC.Driver.Config.Linker
+  ( initFrameworkOpts
+  ) where
+
+import GHC.Linker.Config
+
+import GHC.Driver.Session
+
+initFrameworkOpts :: DynFlags -> FrameworkOpts
+initFrameworkOpts dflags = FrameworkOpts
+  { foFrameworkPaths    = frameworkPaths    dflags
+  , foCmdlineFrameworks = cmdlineFrameworks dflags
+  }


=====================================
compiler/GHC/Driver/Session.hs
=====================================
@@ -130,7 +130,7 @@ module GHC.Driver.Session (
         versionedAppDir, versionedFilePath,
         extraGccViaCFlags, globalPackageDatabasePath,
         pgm_L, pgm_P, pgm_F, pgm_c, pgm_cxx, pgm_a, pgm_l, pgm_lm, pgm_dll, pgm_T,
-        pgm_windres, pgm_ar, pgm_otool, pgm_install_name_tool,
+        pgm_windres, pgm_ar,
         pgm_ranlib, pgm_lo, pgm_lc, pgm_lcc, pgm_i,
         opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_lm, opt_i,
         opt_P_signature,
@@ -833,10 +833,6 @@ pgm_lcc               :: DynFlags -> (String,[Option])
 pgm_lcc dflags = toolSettings_pgm_lcc $ toolSettings dflags
 pgm_ar                :: DynFlags -> String
 pgm_ar dflags = toolSettings_pgm_ar $ toolSettings dflags
-pgm_otool             :: DynFlags -> String
-pgm_otool dflags = toolSettings_pgm_otool $ toolSettings dflags
-pgm_install_name_tool :: DynFlags -> String
-pgm_install_name_tool dflags = toolSettings_pgm_install_name_tool $ toolSettings dflags
 pgm_ranlib            :: DynFlags -> String
 pgm_ranlib dflags = toolSettings_pgm_ranlib $ toolSettings dflags
 pgm_lo                :: DynFlags -> (String,[Option])


=====================================
compiler/GHC/Linker/Config.hs
=====================================
@@ -0,0 +1,13 @@
+-- | Linker configuration
+
+module GHC.Linker.Config
+  ( FrameworkOpts(..)
+  ) where
+
+import GHC.Prelude
+
+-- used on darwin only
+data FrameworkOpts = FrameworkOpts
+  { foFrameworkPaths    :: [String]
+  , foCmdlineFrameworks :: [String]
+  }


=====================================
compiler/GHC/Linker/Dynamic.hs
=====================================
@@ -12,6 +12,7 @@ import GHC.Prelude
 import GHC.Platform
 import GHC.Platform.Ways
 
+import GHC.Driver.Config.Linker
 import GHC.Driver.Session
 
 import GHC.Unit.Env
@@ -23,6 +24,7 @@ import GHC.SysTools.Tasks
 import GHC.Utils.Logger
 import GHC.Utils.TmpFs
 
+import Control.Monad (when)
 import System.FilePath
 
 linkDynLib :: Logger -> TmpFs -> DynFlags -> UnitEnv -> [String] -> [UnitId] -> IO ()
@@ -94,7 +96,7 @@ linkDynLib logger tmpfs dflags0 unit_env o_files dep_packages
 
     -- frameworks
     pkg_framework_opts <- getUnitFrameworkOpts unit_env (map unitId pkgs)
-    let framework_opts = getFrameworkOpts dflags platform
+    let framework_opts = getFrameworkOpts (initFrameworkOpts dflags) platform
 
     case os of
         OSMinGW32 -> do
@@ -193,7 +195,9 @@ linkDynLib logger tmpfs dflags0 unit_env o_files dep_packages
                  -- See Note [Dynamic linking on macOS]
                  ++ [ Option "-Wl,-dead_strip_dylibs", Option "-Wl,-headerpad,8000" ]
               )
-            runInjectRPaths logger dflags pkg_lib_paths output_fn
+            -- Make sure to honour -fno-use-rpaths if set on darwin as well; see #20004
+            when (gopt Opt_RPath dflags) $
+              runInjectRPaths logger (toolSettings dflags) pkg_lib_paths output_fn
         _ -> do
             -------------------------------------------------------------------
             -- Making a DSO


=====================================
compiler/GHC/Linker/MacOS.hs
=====================================
@@ -9,12 +9,15 @@ where
 import GHC.Prelude
 import GHC.Platform
 
+import GHC.Linker.Config
+
 import GHC.Driver.Session
 
 import GHC.Unit.Types
 import GHC.Unit.State
 import GHC.Unit.Env
 
+import GHC.Settings
 import GHC.SysTools.Tasks
 
 import GHC.Runtime.Interpreter
@@ -46,15 +49,13 @@ import Text.ParserCombinators.ReadP as Parser
 -- dynamic library through @-add_rpath at .
 --
 -- See Note [Dynamic linking on macOS]
-runInjectRPaths :: Logger -> DynFlags -> [FilePath] -> FilePath -> IO ()
--- Make sure to honour -fno-use-rpaths if set on darwin as well see #20004
-runInjectRPaths _ dflags _ _ | not (gopt Opt_RPath dflags) = return ()
-runInjectRPaths logger dflags lib_paths dylib = do
-  info <- lines <$> askOtool logger dflags Nothing [Option "-L", Option dylib]
+runInjectRPaths :: Logger -> ToolSettings -> [FilePath] -> FilePath -> IO ()
+runInjectRPaths logger toolSettings lib_paths dylib = do
+  info <- lines <$> askOtool logger toolSettings Nothing [Option "-L", Option dylib]
   -- filter the output for only the libraries. And then drop the @rpath prefix.
   let libs = fmap (drop 7) $ filter (isPrefixOf "@rpath") $ fmap (head.words) $ info
   -- find any pre-existing LC_PATH items
-  info <- lines <$> askOtool logger dflags Nothing [Option "-l", Option dylib]
+  info <- lines <$> askOtool logger toolSettings Nothing [Option "-l", Option dylib]
   let paths = mapMaybe get_rpath info
       lib_paths' = [ p | p <- lib_paths, not (p `elem` paths) ]
   -- only find those rpaths, that aren't already in the library.
@@ -62,7 +63,7 @@ runInjectRPaths logger dflags lib_paths dylib = do
   -- inject the rpaths
   case rpaths of
     [] -> return ()
-    _  -> runInstallNameTool logger dflags $ map Option $ "-add_rpath":(intersperse "-add_rpath" rpaths) ++ [dylib]
+    _  -> runInstallNameTool logger toolSettings $ map Option $ "-add_rpath":(intersperse "-add_rpath" rpaths) ++ [dylib]
 
 get_rpath :: String -> Maybe FilePath
 get_rpath l = case readP_to_S rpath_parser l of
@@ -96,15 +97,15 @@ getUnitFrameworkOpts unit_env dep_packages
 
   | otherwise = return []
 
-getFrameworkOpts :: DynFlags -> Platform -> [String]
-getFrameworkOpts dflags platform
+getFrameworkOpts :: FrameworkOpts -> Platform -> [String]
+getFrameworkOpts fwOpts platform
   | platformUsesFrameworks platform = framework_path_opts ++ framework_opts
   | otherwise = []
   where
-    framework_paths     = frameworkPaths dflags
+    framework_paths     = foFrameworkPaths fwOpts
     framework_path_opts = map ("-F" ++) framework_paths
 
-    frameworks     = cmdlineFrameworks dflags
+    frameworks     = foCmdlineFrameworks fwOpts
     -- reverse because they're added in reverse order from the cmd line:
     framework_opts = concat [ ["-framework", fw]
                             | fw <- reverse frameworks ]


=====================================
compiler/GHC/Linker/Static.hs
=====================================
@@ -29,6 +29,7 @@ import GHC.Linker.ExtraObj
 import GHC.Linker.Windows
 import GHC.Linker.Static.Utils
 
+import GHC.Driver.Config.Linker
 import GHC.Driver.Session
 
 import System.FilePath
@@ -171,7 +172,7 @@ linkBinary' staticLink logger tmpfs dflags unit_env o_files dep_units = do
 
     -- frameworks
     pkg_framework_opts <- getUnitFrameworkOpts unit_env dep_units
-    let framework_opts = getFrameworkOpts dflags platform
+    let framework_opts = getFrameworkOpts (initFrameworkOpts dflags) platform
 
         -- probably _stub.o files
     let extra_ld_inputs = ldInputs dflags
@@ -183,7 +184,9 @@ linkBinary' staticLink logger tmpfs dflags unit_env o_files dep_units = do
     let link dflags args | platformOS platform == OSDarwin
                             = do
                                  GHC.SysTools.runLink logger tmpfs dflags args
-                                 GHC.Linker.MacOS.runInjectRPaths logger dflags pkg_lib_paths output_fn
+                                 -- Make sure to honour -fno-use-rpaths if set on darwin as well; see #20004
+                                 when (gopt Opt_RPath dflags) $
+                                   GHC.Linker.MacOS.runInjectRPaths logger (toolSettings dflags) pkg_lib_paths output_fn
                          | otherwise
                             = GHC.SysTools.runLink logger tmpfs dflags args
 


=====================================
compiler/GHC/SysTools/Tasks.hs
=====================================
@@ -16,6 +16,8 @@ import GHC.IO (catchException)
 
 import GHC.CmmToLlvm.Config (LlvmVersion, llvmVersionStr, supportedLlvmVersionUpperBound, parseLlvmVersion, supportedLlvmVersionLowerBound)
 
+import GHC.Settings
+
 import GHC.SysTools.Process
 import GHC.SysTools.Info
 
@@ -362,15 +364,15 @@ runAr logger dflags cwd args = traceSystoolCommand logger "ar" $ do
   let ar = pgm_ar dflags
   runSomethingFiltered logger id "Ar" ar args cwd Nothing
 
-askOtool :: Logger -> DynFlags -> Maybe FilePath -> [Option] -> IO String
-askOtool logger dflags mb_cwd args = do
-  let otool = pgm_otool dflags
+askOtool :: Logger -> ToolSettings -> Maybe FilePath -> [Option] -> IO String
+askOtool logger toolSettings mb_cwd args = do
+  let otool = toolSettings_pgm_otool toolSettings
   runSomethingWith logger "otool" otool args $ \real_args ->
     readCreateProcessWithExitCode' (proc otool real_args){ cwd = mb_cwd }
 
-runInstallNameTool :: Logger -> DynFlags -> [Option] -> IO ()
-runInstallNameTool logger dflags args = do
-  let tool = pgm_install_name_tool dflags
+runInstallNameTool :: Logger -> ToolSettings -> [Option] -> IO ()
+runInstallNameTool logger toolSettings args = do
+  let tool = toolSettings_pgm_install_name_tool toolSettings
   runSomethingFiltered logger id "Install Name Tool" tool args Nothing Nothing
 
 runRanlib :: Logger -> DynFlags -> [Option] -> IO ()


=====================================
compiler/ghc.cabal.in
=====================================
@@ -421,6 +421,7 @@ Library
         GHC.Driver.Config.HsToCore
         GHC.Driver.Config.HsToCore.Ticks
         GHC.Driver.Config.HsToCore.Usage
+        GHC.Driver.Config.Linker
         GHC.Driver.Config.Logger
         GHC.Driver.Config.Parser
         GHC.Driver.Config.Stg.Debug
@@ -529,6 +530,7 @@ Library
         GHC.JS.Syntax
         GHC.JS.Transform
         GHC.Linker
+        GHC.Linker.Config
         GHC.Linker.Dynamic
         GHC.Linker.ExtraObj
         GHC.Linker.Loader



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/cd31acad391582dd16b00a823271b364ab063ca9...a74225803dc4ec14e3aef96cfe5e17bdc5f0d2a7

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/cd31acad391582dd16b00a823271b364ab063ca9...a74225803dc4ec14e3aef96cfe5e17bdc5f0d2a7
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/20221206/94556392/attachment-0001.html>


More information about the ghc-commits mailing list