rpath compilation rules for Darwin
Functionality to add/problem to solve
Work-around for empty DYLD_LIBARY_PATH
variable (which is cleared by System Integrity Protection).
Target audience
OpenFOAM users on macOS operating system.
Proposal
Correct OpenFOAM execution depends on the right contents of the
DYLD_LIBRARY_PATH
environment variable. On Darwin System Integrity
Protection clears this variable for protected binaries. For the reason
Allrun
scripts become useless.
Previous solution for the problem was to restore values of the
DYLD_LIBRARY_PATH
variable from backup environment variable
FOAM_LD_LIBRARY_PATH
in the beginning of RunFunctions
file. The
approach was limited to the scripts, which use RunFunctions
file and
execute utulities and solvers with shell functions. I.e. it only partly
solved the problem.
In the new approach -rpath
flag is used during link phase to
compile-in list of paths to search for the dynamic libraries. The
following list is used:
-
$FOAM_USER_LIBBIN
(usually OpenFOAM is compiled manually on Darwin, so I think this location is known during compilation and relevant to user). $FOAM_SITE_LIBBIN
$FOAM_LIBBIN
$FOAM_LIBBIN/$FOAM_MPI
$FOAM_LIBBIN/dymmy
The first two folders are used as absolute paths. The last three entries
are substituted, using dynamic linker variables: @loader_path
and
@executable_path
. @loaded_path
is used in dynamic libraries and it
usually points to $FOAM_LIBBIN
. @executable_path
is used in
executables and there $FOAM_LIBBIN
is encoded as
@executable_path/../lib
(so it assumes, that bin
and lib
folders
are at the same directory tree level).
This approach still allows us to use DYLD_LIBRARY_PATH
environment
variable to override dynamic libraries search paths, while maintaining
OpenFOAM in functional state if the variable is empty.
We still need to maintain backup variable FOAM_LD_LIBRARY_PATH
as it is used by dlOpen
function as a fallback.
What does success look like, and how can we measure that?
OpenFOAM solvers and utilities are correctly executed in shell scripts (ex. Allrun
, foamJob
) without workarounds with restoration of DYLD_LIBRARY_PATH
from backup variable.
Links / references
- The Library Search Process section in https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryUsageGuidelines.html#//apple_ref/doc/uid/TP40001928-SW10
- Run-path dependent libraries section https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/RunpathDependentLibraries.html
Functionality is implemented in attached 01-feature-darwin-rpath-wmake-rules.patch.