Skip to content

Commit a03584d

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 cf05f6e commit a03584d

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
@@ -100,11 +100,22 @@ linkBinary' staticLink logger tmpfs dflags unit_env o_files dep_units = do
100100
-- explicit packages with the auto packages and all of their
101101
-- dependencies, and eliminating duplicates.
102102
pkgs <- mayThrowUnitErr (preloadUnitsInfo' unit_env dep_units)
103+
104+
-- Collect per-package library dirs (deduplicated, non-empty)
103105
let pkg_lib_paths = collectLibraryDirs ways_ pkgs
104-
let pkg_lib_path_opts = concatMap get_pkg_lib_path_opts pkg_lib_paths
105-
get_pkg_lib_path_opts l
106+
-- Until: https://github.com/haskell/cabal/issues/11221 is in cabal,
107+
-- we have to deal with cabal passing -dyload deploy, and manually
108+
-- inject rpaths for the rts.
109+
-- Build linker options per (pkg, libdir)
110+
let pkg_lib_path_opts =
111+
concat
112+
[ get_pkg_lib_path_opts pkg l
113+
| pkg <- pkgs
114+
, l <- collectLibraryDirs ways_ [pkg]
115+
]
116+
get_pkg_lib_path_opts pkg l
106117
| osElfTarget (platformOS platform) &&
107-
dynLibLoader dflags == SystemDependent &&
118+
(dynLibLoader dflags == SystemDependent || unitPackageNameString pkg == rts) &&
108119
ways_ `hasWay` WayDyn
109120
= let libpath = if gopt Opt_RelativeDynlibPaths dflags
110121
then "$ORIGIN" </>
@@ -125,7 +136,7 @@ linkBinary' staticLink logger tmpfs dflags unit_env o_files dep_units = do
125136
else ["-Xlinker", "-rpath-link", "-Xlinker", l]
126137
in ["-L" ++ l] ++ rpathlink ++ rpath
127138
| osMachOTarget (platformOS platform) &&
128-
dynLibLoader dflags == SystemDependent &&
139+
(dynLibLoader dflags == SystemDependent || unitPackageNameString pkg == rts) &&
129140
ways_ `hasWay` WayDyn &&
130141
useXLinkerRPath dflags (platformOS platform)
131142
= let libpath = if gopt Opt_RelativeDynlibPaths dflags

0 commit comments

Comments
 (0)