ghc-9.2.2: The GHC API
Safe HaskellSafe-Inferred
LanguageHaskell2010

GHC.Linker.MacOS

Synopsis

Documentation

runInjectRPaths :: Logger -> DynFlags -> [FilePath] -> FilePath -> IO () Source #

On macOS we rely on the linkers -dead_strip_dylibs flag to remove unused libraries from the dynamic library. We do this to reduce the number of load commands that end up in the dylib, and has been limited to 32K (32768) since macOS Sierra (10.14).

-dead_strip_dylibs does not dead strip -rpath entries, as such passing -l and -rpath to the linker will result in the unnecesasry libraries not being included in the load commands, however the -rpath entries are all forced to be included. This can lead to 100s of -rpath entries being included when only a handful of libraries end up being truly linked.

Thus after building the library, we run a fixup phase where we inject the -rpath for each found library (in the given library search paths) into the dynamic library through -add_rpath.

See Note [Dynamic linking on macOS]