brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 435a435 Raw
46 lines · cpp
1// Checks that on OS X 10.11+ dlopen'ing a RTsanified library from a2// non-instrumented program exits with a user-friendly message.3 4// REQUIRES: osx-autointerception5 6// XFAIL: ios7 8// RUN: %clangxx -fsanitize=realtime %s -o %t.so -shared -DSHARED_LIB9// RUN: %clangxx %s -o %t10 11// RUN: %clangxx -fsanitize=realtime %s -### 2>&1 \12// RUN:   | grep "libclang_rt.rtsan_osx_dynamic.dylib" \13// RUN:   | sed -e 's/.*"\(.*libclang_rt.rtsan_osx_dynamic.dylib\)".*/\1/' \14// RUN:   | tr -d '\n' > %t.rtsan_dylib_path15 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-FAIL18// Launching a non-instrumented binary with an explicit DYLD_INSERT_LIBRARIES should work.19// RUN: env DYLD_INSERT_LIBRARIES="%{readfile:%t.rtsan_dylib_path}" %run %t %t.so 2>&1 | FileCheck %s20 21// Launching an instrumented binary with the DYLD_INSERT_LIBRARIES env variable has no error22// RUN: %clangxx -fsanitize=realtime %s -o %t23// RUN: env DYLD_INSERT_LIBRARIES="%{readfile:%t.rtsan_dylib_path}" %run %t %t.so 2>&1 | FileCheck %s --check-prefix=CHECK-INSTRUMENTED24 25#include <dlfcn.h>26#include <stdio.h>27 28#if defined(SHARED_LIB)29extern "C" void foo() { fprintf(stderr, "Hello world.\n"); }30#else  // defined(SHARED_LIB)31int main(int argc, char *argv[]) {32  void *handle = dlopen(argv[1], RTLD_NOW);33  void (*foo)() = (void (*)())dlsym(handle, "foo");34  foo();35}36#endif // defined(SHARED_LIB)37 38// CHECK: Hello world.39// CHECK-NOT: ERROR: Interceptors are not working.40 41// CHECK-FAIL-NOT: Hello world.42// CHECK-FAIL: ERROR: Interceptors are not working.43 44// CHECK-INSTRUMENTED-NOT: ERROR: Interceptors are not working45// CHECK-INSTRUMENTED: Hello world.46