diff options
author | mrkun <mrgutkun@gmail.com> | 2022-11-29 21:10:30 +0300 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-12-06 15:46:38 -0500 |
commit | 4e28f49e0a23f54a7b9b18a9010f19b0b15223db (patch) | |
tree | 9909569c7fc6fb1d28cf9300f94ba1b37ac8bb85 | |
parent | aaaaa79b9b381bb6697a90ff460d2d520152505e (diff) | |
download | haskell-4e28f49e0a23f54a7b9b18a9010f19b0b15223db.tar.gz |
Push DynFlags out of runInjectRPaths
-rw-r--r-- | compiler/GHC/Linker/Dynamic.hs | 5 | ||||
-rw-r--r-- | compiler/GHC/Linker/MacOS.hs | 13 | ||||
-rw-r--r-- | compiler/GHC/Linker/Static.hs | 4 |
3 files changed, 13 insertions, 9 deletions
diff --git a/compiler/GHC/Linker/Dynamic.hs b/compiler/GHC/Linker/Dynamic.hs index 17c178ea85..175b5fb24a 100644 --- a/compiler/GHC/Linker/Dynamic.hs +++ b/compiler/GHC/Linker/Dynamic.hs @@ -23,6 +23,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 () @@ -193,7 +194,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 diff --git a/compiler/GHC/Linker/MacOS.hs b/compiler/GHC/Linker/MacOS.hs index a7d7d86ec7..d64a1075b2 100644 --- a/compiler/GHC/Linker/MacOS.hs +++ b/compiler/GHC/Linker/MacOS.hs @@ -15,6 +15,7 @@ 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 +47,13 @@ import Text.ParserCombinators.ReadP as Parser -- dynamic library through @-add_rpath@. -- -- 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 (toolSettings 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 (toolSettings 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 +61,7 @@ runInjectRPaths logger dflags lib_paths dylib = do -- inject the rpaths case rpaths of [] -> return () - _ -> runInstallNameTool logger (toolSettings 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 diff --git a/compiler/GHC/Linker/Static.hs b/compiler/GHC/Linker/Static.hs index 2bbe6dfc17..baff075b08 100644 --- a/compiler/GHC/Linker/Static.hs +++ b/compiler/GHC/Linker/Static.hs @@ -183,7 +183,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 |