diff options
author | Kuba Brecka <kuba.brecka@gmail.com> | 2016-03-15 14:30:28 +0000 |
---|---|---|
committer | Kuba Brecka <kuba.brecka@gmail.com> | 2016-03-15 14:30:28 +0000 |
commit | d7724fcbaf8d9f71fe17d2414741b2596379e098 (patch) | |
tree | 3ba5a9d66cbc78ec3d1ba9f31c0f212faa993a43 /lib/sanitizer_common | |
parent | 961e78720a32929d7e4fc13a72d7266d59672c42 (diff) |
[sanitizer] On OS X, verify that interceptors work and abort if not
On OS X 10.11+, we have "automatic interceptors", so we don't need to use DYLD_INSERT_LIBRARIES when launching instrumented programs. However, non-instrumented programs that load TSan late (e.g. via dlopen) are currently broken, as TSan will still try to initialize, but the program will crash/hang at random places (because the interceptors don't work). This patch adds an explicit check that interceptors are working, and if not, it aborts and prints out an error message suggesting to explicitly use DYLD_INSERT_LIBRARIES.
Differential Revision: http://reviews.llvm.org/D18121
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@263551 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common')
-rw-r--r-- | lib/sanitizer_common/sanitizer_mac.cc | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/sanitizer_common/sanitizer_mac.cc b/lib/sanitizer_common/sanitizer_mac.cc index 25c1c683d..0b025fcb9 100644 --- a/lib/sanitizer_common/sanitizer_mac.cc +++ b/lib/sanitizer_common/sanitizer_mac.cc @@ -627,6 +627,21 @@ void MaybeReexec() { CHECK("execv failed" && 0); } + // Verify that interceptors really work. We'll use dlsym to locate + // "pthread_create", if interceptors are working, it should really point to + // "wrap_pthread_create" within our own dylib. + Dl_info info_pthread_create; + void *dlopen_addr = dlsym(RTLD_DEFAULT, "pthread_create"); + CHECK(dladdr(dlopen_addr, &info_pthread_create)); + if (internal_strcmp(info.dli_fname, info_pthread_create.dli_fname) != 0) { + Report( + "ERROR: Interceptors are not working. This may be because %s is " + "loaded too late (e.g. via dlopen). Please launch the executable " + "with:\n%s=%s\n", + SanitizerToolName, kDyldInsertLibraries, info.dli_fname); + CHECK("interceptors not installed" && 0); + } + if (!lib_is_in_env) return; |