Home | History | Annotate | Download | only in Darwin
      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 // RUN: %clangxx_tsan %s -o %t.so -shared -DSHARED_LIB
      8 // RUN: %clangxx_tsan -fno-sanitize=thread %s -o %t
      9 
     10 // RUN: TSAN_DYLIB_PATH=`%clangxx_tsan %s -### 2>&1 \
     11 // RUN:   | grep "libclang_rt.tsan_osx_dynamic.dylib" \
     12 // RUN:   | sed -e 's/.*"\(.*libclang_rt.tsan_osx_dynamic.dylib\)".*/\1/'`
     13 
     14 // Launching a non-instrumented binary that dlopen's an instrumented library should fail.
     15 // RUN: not %run %t %t.so 2>&1 | FileCheck %s --check-prefix=CHECK-FAIL
     16 // Launching a non-instrumented binary with an explicit DYLD_INSERT_LIBRARIES should work.
     17 // RUN: DYLD_INSERT_LIBRARIES=$TSAN_DYLIB_PATH %run %t %t.so 2>&1 | FileCheck %s
     18 
     19 #include <dlfcn.h>
     20 #include <pthread.h>
     21 #include <stdio.h>
     22 
     23 #if defined(SHARED_LIB)
     24 extern "C" void foo() {
     25   fprintf(stderr, "Hello world.\n");
     26 }
     27 #else  // defined(SHARED_LIB)
     28 int main(int argc, char *argv[]) {
     29   void *handle = dlopen(argv[1], RTLD_NOW);
     30   fprintf(stderr, "handle = %p\n", handle);
     31   void (*foo)() = (void (*)())dlsym(handle, "foo");
     32   fprintf(stderr, "foo = %p\n", foo);
     33   foo();
     34 }
     35 #endif  // defined(SHARED_LIB)
     36 
     37 // CHECK: Hello world.
     38 // CHECK-NOT: ERROR: Interceptors are not working.
     39 
     40 // CHECK-FAIL-NOT: Hello world.
     41 // CHECK-FAIL: ERROR: Interceptors are not working.
     42