This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] Make MaybeReexec properly process DYLD_INSERT_LIBRARIES when using non-absolute paths
ClosedPublic

Authored by kubamracek on Jan 23 2015, 10:48 PM.

Details

Reviewers
glider
Summary

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).

Diff Detail

Event Timeline

kubamracek retitled this revision from to [compiler-rt] Make MaybeReexec properly process DYLD_INSERT_LIBRARIES when using non-absolute paths.
kubamracek updated this object.
kubamracek edited the test plan for this revision. (Show Details)
kubamracek added subscribers: Unknown Object (MLST), glider, samsonov, kcc.
samsonov added inline comments.Jan 27 2015, 4:00 PM
lib/sanitizer_common/sanitizer_libc.cc
33

You can write it as follows:

const char *t = (const char *)s;
void *res = nullptr;
for (uptr i = 0; i < n; ++i, ++t) {
  if (*t == c) res = reinterpret_cast<void*>(...);
}
return res;
kubamracek updated this revision to Diff 18866.Jan 27 2015, 5:07 PM

Addressing review comments.

So it this okay to commit?

Thanks,
Kuba

glider added a comment.Feb 2 2015, 2:56 AM

I'm ok with this patch.

glider accepted this revision.Feb 2 2015, 2:56 AM
glider added a reviewer: glider.
This revision is now accepted and ready to land.Feb 2 2015, 2:56 AM
kubamracek closed this revision.Feb 6 2015, 4:38 AM

Landed in r228392.