Runpath polution on macOS
GHC (and Cabal to some extend) like to pass -rpath
arguments to the linker to inject runpath's to lookup libraries at runtime in. macOS in recent version has a strict limit on the size of load commands in the executable/library headers. Runpath's count towards that limit. Having a lot of libraries, thus produce a lot of -rpath
arguments GHC passes to the linker and thus easily overflows the load command size limit.
Factors that contribute to this and make it especially hard in for GHC are:
- we place libraries into their own folders (can't just have one runpath to look up all the libraries).
- we pass runpaths indiscriminately for all libraries, even if we pass
-dead_strip_dylibs
, which will remove some libraries, but leaves the runpath info. - some build systems (e.g.
nix
) make this worse by having really long build paths.