45 lines · cpp
1// Checks that on OS X 10.11+ (where we do not re-exec anymore, because2// interceptors work automatically), dlopen'ing a TSanified library from a3// non-instrumented program exits with a user-friendly message.4 5// REQUIRES: osx-autointerception6 7// XFAIL: ios8 9// RUN: %clangxx_tsan %s -o %t.so -shared -DSHARED_LIB10// RUN: %clangxx_tsan -fno-sanitize=thread %s -o %t11 12// RUN: %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// RUN: | tr -d '\n' > %t.tsan_dylib_path16 17// Launching a non-instrumented binary that dlopen's an instrumented library should fail.18// RUN: not %run %t %t.so 2>&1 | FileCheck %s --check-prefix=CHECK-FAIL19// Launching a non-instrumented binary with an explicit DYLD_INSERT_LIBRARIES should work.20// RUN: env DYLD_INSERT_LIBRARIES="%{readfile:%t.tsan_dylib_path}" %run %t %t.so 2>&1 | FileCheck %s21 22#include <dlfcn.h>23#include <pthread.h>24#include <stdio.h>25 26#if defined(SHARED_LIB)27extern "C" void foo() {28 fprintf(stderr, "Hello world.\n");29}30#else // defined(SHARED_LIB)31int main(int argc, char *argv[]) {32 void *handle = dlopen(argv[1], RTLD_NOW);33 fprintf(stderr, "handle = %p\n", handle);34 void (*foo)() = (void (*)())dlsym(handle, "foo");35 fprintf(stderr, "foo = %p\n", foo);36 foo();37}38#endif // defined(SHARED_LIB)39 40// CHECK: Hello world.41// CHECK-NOT: ERROR: Interceptors are not working.42 43// CHECK-FAIL-NOT: Hello world.44// CHECK-FAIL: ERROR: Interceptors are not working.45