1*7c3d14c8STreehugger Robot // Test for ASAN_OPTIONS=start_deactivated=1 mode. 2*7c3d14c8STreehugger Robot // Main executable is uninstrumented, but linked to ASan runtime. The shared 3*7c3d14c8STreehugger Robot // library is instrumented. 4*7c3d14c8STreehugger Robot 5*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so 6*7c3d14c8STreehugger Robot // RUN: %clangxx -O0 %s -c -o %t.o 7*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O0 %t.o %libdl -o %t 8*7c3d14c8STreehugger Robot 9*7c3d14c8STreehugger Robot // RUN: rm -f %t.asan.options.activation-options.cc.tmp 10*7c3d14c8STreehugger Robot // RUN: rm -f %t.asan.options.ABCDE 11*7c3d14c8STreehugger Robot // RUN: echo "help=1" >%t.asan.options.activation-options.cc.tmp 12*7c3d14c8STreehugger Robot 13*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=start_deactivated=1 \ 14*7c3d14c8STreehugger Robot // RUN: ASAN_ACTIVATION_OPTIONS=include=%t.asan.options.%b %run %t 2>&1 | \ 15*7c3d14c8STreehugger Robot // RUN: FileCheck %s --check-prefix=CHECK-HELP --check-prefix=CHECK-FOUND 16*7c3d14c8STreehugger Robot 17*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=start_deactivated=1 \ 18*7c3d14c8STreehugger Robot // RUN: ASAN_ACTIVATION_OPTIONS=include=%t.asan.options not %run %t 2>&1 | \ 19*7c3d14c8STreehugger Robot // RUN: FileCheck %s --check-prefix=CHECK-NO-HELP --check-prefix=CHECK-MISSING 20*7c3d14c8STreehugger Robot 21*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=start_deactivated=1 \ 22*7c3d14c8STreehugger Robot // RUN: ASAN_ACTIVATION_OPTIONS=include=%t.asan.options.%b not %run %t --fix-name 2>&1 | \ 23*7c3d14c8STreehugger Robot // RUN: FileCheck %s --check-prefix=CHECK-NO-HELP --check-prefix=CHECK-MISSING 24*7c3d14c8STreehugger Robot 25*7c3d14c8STreehugger Robot // RUN: echo "help=1" >%t.asan.options.ABCDE 26*7c3d14c8STreehugger Robot 27*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=start_deactivated=1 \ 28*7c3d14c8STreehugger Robot // RUN: ASAN_ACTIVATION_OPTIONS=include=%t.asan.options.%b %run %t --fix-name 2>&1 | \ 29*7c3d14c8STreehugger Robot // RUN: FileCheck %s --check-prefix=CHECK-HELP --check-prefix=CHECK-FOUND 30*7c3d14c8STreehugger Robot 31*7c3d14c8STreehugger Robot // XFAIL: arm-linux-gnueabi 32*7c3d14c8STreehugger Robot // XFAIL: android 33*7c3d14c8STreehugger Robot 34*7c3d14c8STreehugger Robot #if !defined(SHARED_LIB) 35*7c3d14c8STreehugger Robot #include <assert.h> 36*7c3d14c8STreehugger Robot #include <dlfcn.h> 37*7c3d14c8STreehugger Robot #include <stdio.h> 38*7c3d14c8STreehugger Robot #include <stdlib.h> 39*7c3d14c8STreehugger Robot #include <string.h> 40*7c3d14c8STreehugger Robot #include <unistd.h> 41*7c3d14c8STreehugger Robot 42*7c3d14c8STreehugger Robot #include <string> 43*7c3d14c8STreehugger Robot 44*7c3d14c8STreehugger Robot #include "sanitizer/asan_interface.h" 45*7c3d14c8STreehugger Robot 46*7c3d14c8STreehugger Robot typedef void (*Fn)(); 47*7c3d14c8STreehugger Robot main(int argc,char * argv[])48*7c3d14c8STreehugger Robotint main(int argc, char *argv[]) { 49*7c3d14c8STreehugger Robot std::string path = std::string(argv[0]) + "-so.so"; 50*7c3d14c8STreehugger Robot 51*7c3d14c8STreehugger Robot if (argc > 1 && strcmp(argv[1], "--fix-name") == 0) { 52*7c3d14c8STreehugger Robot assert(strlen(argv[0]) > 5); 53*7c3d14c8STreehugger Robot strcpy(argv[0], "ABCDE"); 54*7c3d14c8STreehugger Robot } 55*7c3d14c8STreehugger Robot 56*7c3d14c8STreehugger Robot void *dso = dlopen(path.c_str(), RTLD_NOW); 57*7c3d14c8STreehugger Robot if (!dso) { 58*7c3d14c8STreehugger Robot fprintf(stderr, "dlopen failed: %s\n", dlerror()); 59*7c3d14c8STreehugger Robot return 1; 60*7c3d14c8STreehugger Robot } 61*7c3d14c8STreehugger Robot 62*7c3d14c8STreehugger Robot return 0; 63*7c3d14c8STreehugger Robot } 64*7c3d14c8STreehugger Robot #else // SHARED_LIB 65*7c3d14c8STreehugger Robot // Empty: all we need is an ASan shared library constructor. 66*7c3d14c8STreehugger Robot #endif // SHARED_LIB 67*7c3d14c8STreehugger Robot 68*7c3d14c8STreehugger Robot // CHECK-HELP: Available flags for {{.*}}Sanitizer: 69*7c3d14c8STreehugger Robot // CHECK-NO-HELP-NOT: Available flags for {{.*}}Sanitizer: 70*7c3d14c8STreehugger Robot // CHECK-FOUND-NOT: Failed to read options 71*7c3d14c8STreehugger Robot // CHECK-MISSING: Failed to read options 72