MaybeReexec() in asan_mac.cc checks for presence of the ASan dylib in DYLD_INSERT_LIBRARIES, and if it is there, it will process this env. var. and remove the dylib from its value, so that spawned children don't have this variable set.
However, the current implementation only works when using a canonical absolute path to the dylib, it fails to remove the dylib for example when using @executable_path:
$ cat a.c int main() { printf("Hello world.\n"); system("ls"); } $ ls a.c libclang_rt.asan_osx_dynamic.dylib $ clang -fsanitize=address a.c $ ./a.out a.c a.out libclang_rt.asan_osx_dynamic.dylib $ DYLD_INSERT_LIBRARIES=@executable_path/libclang_rt.asan_osx_dynamic.dylib ./a.out Hello world. dyld: could not load inserted library '@executable_path/libclang_rt.asan_osx_dynamic.dylib' because image not found $
(here it's ls that fails to launch, because it's @executable_path is different)
This patch changes the processing of DYLD_INSERT_LIBRARIES to comparing values only based on filenames (ignoring directories).
You can write it as follows: