Skip to content

Commit 3e7c948

Browse files
committed
compiler: inject rpath for the rts as needed.
This is needed until haskell/cabal#11221 is properly addressed to ensure that a linked dynamic binary will have the appropriate path for the rts (sublib).
1 parent 2133278 commit 3e7c948

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

compiler/GHC/Linker/Static.hs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,22 @@ linkBinary' staticLink logger tmpfs dflags blm unit_env o_files dep_units = do
9292
-- explicit packages with the auto packages and all of their
9393
-- dependencies, and eliminating duplicates.
9494
pkgs <- mayThrowUnitErr (preloadUnitsInfo' unit_env dep_units)
95+
96+
-- Collect per-package library dirs (deduplicated, non-empty)
9597
let pkg_lib_paths = collectLibraryDirs ways_ pkgs
96-
let pkg_lib_path_opts = concatMap get_pkg_lib_path_opts pkg_lib_paths
97-
get_pkg_lib_path_opts l
98+
-- Until: https://github.com/haskell/cabal/issues/11221 is in cabal,
99+
-- we have to deal with cabal passing -dyload deploy, and manually
100+
-- inject rpaths for the rts.
101+
-- Build linker options per (pkg, libdir)
102+
let pkg_lib_path_opts =
103+
concat
104+
[ get_pkg_lib_path_opts pkg l
105+
| pkg <- pkgs
106+
, l <- collectLibraryDirs ways_ [pkg]
107+
]
108+
get_pkg_lib_path_opts pkg l
98109
| osElfTarget (platformOS platform) &&
99-
dynLibLoader dflags == SystemDependent &&
110+
(dynLibLoader dflags == SystemDependent || unitPackageNameString pkg == "rts") &&
100111
ways_ `hasWay` WayDyn
101112
= let libpath = if gopt Opt_RelativeDynlibPaths dflags
102113
then "$ORIGIN" </>
@@ -117,7 +128,7 @@ linkBinary' staticLink logger tmpfs dflags blm unit_env o_files dep_units = do
117128
else ["-Xlinker", "-rpath-link", "-Xlinker", l]
118129
in ["-L" ++ l] ++ rpathlink ++ rpath
119130
| osMachOTarget (platformOS platform) &&
120-
dynLibLoader dflags == SystemDependent &&
131+
(dynLibLoader dflags == SystemDependent || unitPackageNameString pkg == "rts") &&
121132
ways_ `hasWay` WayDyn &&
122133
useXLinkerRPath dflags (platformOS platform)
123134
= let libpath = if gopt Opt_RelativeDynlibPaths dflags

0 commit comments

Comments
 (0)