brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 9bb652c Raw
48 lines · cpp
1// RUN: %clangxx -g -O0 %s -o %t2 3// Check that trying to dlopen() the ASan dylib fails.4// We explicitly set `abort_on_error=0` because5// - By default the lit config sets this but we don't want this6//   test to implicitly depend on this.7// - It avoids requiring `--crash` to be passed to `not`.8// RUN: %env_asan_opts=abort_on_error=0 APPLE_ASAN_INIT_FOR_DLOPEN=0 not \9// RUN:   %run %t %shared_libasan 2>&1 | \10// RUN:   FileCheck -check-prefix=CHECK-DL-OPEN-FAIL %s11// RUN: env -u APPLE_ASAN_INIT_FOR_DLOPEN %env_asan_opts=abort_on_error=0 not \12// RUN:   %run %t %shared_libasan 2>&1 | \13// RUN:   FileCheck -check-prefix=CHECK-DL-OPEN-FAIL %s14 15// Check that we can successfully dlopen the ASan dylib when we set the right16// environment variable.17// RUN: env APPLE_ASAN_INIT_FOR_DLOPEN=1 %run %t %shared_libasan 2>&1 | \18// RUN:   FileCheck -check-prefix=CHECK-DL-OPEN-SUCCESS %s19 20#include <dlfcn.h>21#include <stdio.h>22 23// CHECK-DL-OPEN-FAIL: ERROR: Interceptors are not working24// CHECK-SAME-DL-OPEN-FAIL: Please launch the executable with: DYLD_INSERT_LIBRARIES={{.+}}/libclang_rt.asan_{{.+}}_dynamic.dylib25 26int main(int argc, char **argv) {27  if (argc != 2) {28    fprintf(stderr, "Usage: %s <dylib_path>\n", argv[0]);29    return 1;30  }31  const char *dylib_path = argv[1];32  void *handle = dlopen(dylib_path, RTLD_LAZY);33  if (!handle) {34    fprintf(stderr, "Failed to dlopen: %s\n", dlerror());35    return 1;36  }37  // Make sure we can find a function we expect to be in the dylib.38  void *fn = dlsym(handle, "__sanitizer_mz_size");39  if (!fn) {40    fprintf(stderr, "Failed to get symbol: %s\n", dlerror());41    return 1;42  }43  // TODO(dliew): Actually call a function from the dylib that is safe to call.44  // CHECK-DL-OPEN-SUCCESS: DONE45  printf("DONE\n");46  return 0;47}48