Skip to content

[macOS] better rpath logic #7094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion Cabal/src/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,12 @@ getRPaths lbi clbi | supportRPaths hostOS = do
(Platform _ hostOS) = hostPlatform lbi
compid = compilerId . compiler $ lbi

ghcInfoMap = compilerProperties . compiler $ lbi
hasInstallNameTool =
case Map.lookup "install_name_tool command" ghcInfoMap of
Just path -> not (null path)
Nothing -> False

-- The list of RPath-supported operating systems below reflects the
-- platforms on which Cabal's RPATH handling is tested. It does _NOT_
-- reflect whether the OS supports RPATH.
Expand All @@ -1726,7 +1732,23 @@ getRPaths lbi clbi | supportRPaths hostOS = do
-- 'False', while those operating systems themselves do support RPATH.
supportRPaths Linux   = True
supportRPaths Windows = False
supportRPaths OSX   = True
-- While macOS fundamentally supports RPaths, this flag will produce
-- linker -rpath flags for each dependency and pass them to GHC which will
-- in turn pass them verbatim to ld64. This is not desirable as we need to
-- use dead_strip_dylibs on macOS to prevent the Load Commands to exceed the
-- Load Command Size Limit (32K) on macOS. In GHC this was reworked in
-- ghc/ghc:4ff93292 (https://gitlab.haskell.org/ghc/ghc/-/commit/4ff93292243888545da452ea4d4c1987f2343591)
-- to patch the -rpath's into the library *after* linking them
-- with dead_strip_dylib. GHC relies on proper passing of -L values to find
-- the referenced libraries and subsequently produce the correct -rpath entries
-- in the library. This will be backported to GHC 8.8, 8.10, and 9.0, as
-- well as being part of GHC 9.2 onwards.
--
-- We know the GHC in question supports this if it knows about
-- `install_name_tool` or `otool`. Thus in those cases, we do not
-- want RPaths support in Cabal, but have this handeled completely in GHC in
-- a post processing step.
supportRPaths OSX   = not hasInstallNameTool
supportRPaths FreeBSD   =
case compid of
CompilerId GHC ver | ver >= mkVersion [7,10,2] -> True
Expand Down
3 changes: 3 additions & 0 deletions changelog.d/no-pass-rpath-on-macos
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
synopsis: Do not pass -rpath to GHC, but let GHC figure it out on its own.
prs: 7076
description: To reduce Load Command Sizes for dynamic libraries/executables together with https://gitlab.haskell.org/ghc/ghc/-/commit/4ff93292243888545da452ea4d4c1987f2343591