MarkOates / blast

0 stars 0 forks source link

XCode 15, rpath change resulted in modification to Makefile #39

Open MarkOates opened 11 months ago

MarkOates commented 11 months ago

Problem

Since updating to XCode command line tools 15.0, a change in the linker behavior required a patch to this project's Makefile.

For context, executable binaries have compiled within them the folder locations(s) to use when searching for dylibs at runtime. These locations can be seen with either otool -l path/to/binary or otool -L path/to/binary after compilation, and show listings for each dylib in the executble. Some listings may be prefixed with @rpath (as in @rpath/path/to/dylib.dylib), representing a dynamic location. (This is related to LC_RPATH (the "load command" that sets the rpath at runtime) which was included in the error message presented at runtime.)

Since XCode 15, the system (somewhere in the udpated tools) will no longer use /usr/local/lib as a fallback or default location when searching for dylib files (it appears to be a security concern). It's unclear if this change is categorized as an unintended bug (I read the linker was completely rewritten to be faster), or a policy change.

Several possible changes are considered to fix this issue.

Option 1: Set a rpath during compilation

This can be done by including the flag -rpath '/usr/local/lib' during invocation of clang/g++ (e.g. something like g++ main.o -I./include -L./libs -rpath '/usr/local/lib'). The order or placement of -rpath flag does not appear to matter.

Option 2: Set a rpath after compilation

This can be done with $> install_name_tool -add_rpath /usr/local/lib path/to/binary

Other solutions proposed

Solution

For blast/Makefile, I've decided to explicitly set the rpath when building in MacOS to /ur/local/lib. For my build environment, this is where all the libs are located (liballegro_font.dylib, et all). Note that Mac's -framework dylibs are already available by being included in a protected cache on the mac, so they are automatically found at runtime (unless explicitly declared to be found elsewhere).

According to "The Eskimo!" from Apple, going forward, all compiled binaries should prefer to have known locations for the dylibs they are relying on, and should not rely on implicit locations for security reasons (source).

Some links