Reimplementation of dlOpen for macOS to avoid SIP problems
Functionality to add/problem to solve
SIP (System Integrity Protection) on macOS clears environment variables, which affect behaviour of dynamic linker (DYLD_LIBRARY_PATH
). OpenFOAM keeps backup of this variable in FOAM_LD_LIBRARY_PATH
and currently it restores DYLD_LIBRARY_PATH
in RunFunctions
file. This solution is not quite complete, as it (a) requires sourcing of RunFunctions
file, (b) additional errors appear depending on a user workflow (ex. #2793 (closed), #2555 (closed)).
The patch solves the problem by iterating through paths stored in backup variable, while loading dynamic library.
Target audience
OpenFOAM users on macOS with SIP enabled.
Proposal
Try to emulate dlopen
behaviour: iterate over paths stored in FOAM_LD_LIBRARY_PATH
, for each of the paths construct full path to the library, try to load a library using full path.
What does success look like, and how can we measure that?
- There is no need to restore
DYLD_LIBRARY_PATH
inRunFunctions
. - User with SIP enabled can load additional libraries in case files and solver finds them independently of the way the case is executed (from command line, from a script using
runApplication
function, from a script usingfoamJob
script, etc.)
Funding
Patch implementing the functionality is attached to the issue.
01-dlopen-SIP-remediation.patch
Note
sprintf
and vfork
are deprecated on macOS, so I also added changes to remove deprecation warnings during compilation.