| 1 | // Checks that on OS X 10.11+ (where we do not re-exec anymore, because |
| 2 | // interceptors work automatically), dlopen'ing a TSanified library from a |
| 3 | // non-instrumented program exits with a user-friendly message. |
| 4 | |
| 5 | // REQUIRES: osx-autointerception |
| 6 | |
| 7 | // XFAIL: ios |
| 8 | |
| 9 | // RUN: %clangxx_tsan %s -o %t.so -shared -DSHARED_LIB |
| 10 | // RUN: %clangxx_tsan -fno-sanitize=thread %s -o %t |
| 11 | |
| 12 | // RUN: TSAN_DYLIB_PATH=`%clangxx_tsan %s -### 2>&1 \ |
| 13 | // RUN: | grep "libclang_rt.tsan_osx_dynamic.dylib" \ |
| 14 | // RUN: | sed -e 's/.*"\(.*libclang_rt.tsan_osx_dynamic.dylib\)".*/\1/'` |
| 15 | |
| 16 | // Launching a non-instrumented binary that dlopen's an instrumented library should fail. |
| 17 | // RUN: not %run %t %t.so 2>&1 | FileCheck %s --check-prefix=CHECK-FAIL |
| 18 | // Launching a non-instrumented binary with an explicit DYLD_INSERT_LIBRARIES should work. |
| 19 | // RUN: DYLD_INSERT_LIBRARIES=$TSAN_DYLIB_PATH %run %t %t.so 2>&1 | FileCheck %s |
| 20 | |
| 21 | #include <dlfcn.h> |
| 22 | #include <pthread.h> |
| 23 | #include <stdio.h> |
| 24 | |
| 25 | #if defined(SHARED_LIB) |
| 26 | extern "C" void foo() { |
| 27 | fprintf(stderr, "Hello world.\n" ); |
| 28 | } |
| 29 | #else // defined(SHARED_LIB) |
| 30 | int main(int argc, char *argv[]) { |
| 31 | void *handle = dlopen(file: argv[1], RTLD_NOW); |
| 32 | fprintf(stderr, format: "handle = %p\n" , handle); |
| 33 | void (*foo)() = (void (*)())dlsym(handle: handle, name: "foo" ); |
| 34 | fprintf(stderr, format: "foo = %p\n" , foo); |
| 35 | foo(); |
| 36 | } |
| 37 | #endif // defined(SHARED_LIB) |
| 38 | |
| 39 | // CHECK: Hello world. |
| 40 | // CHECK-NOT: ERROR: Interceptors are not working. |
| 41 | |
| 42 | // CHECK-FAIL-NOT: Hello world. |
| 43 | // CHECK-FAIL: ERROR: Interceptors are not working. |
| 44 | |