1 // Test for direct coverage writing enabled at activation time. 2 3 // RUN: %clangxx_asan -fsanitize-coverage=func -DSHARED %s -shared -o %dynamiclib -fPIC 4 // RUN: %clangxx -c -DSO_DIR=\"%T\" %s -o %t.o 5 // RUN: %clangxx_asan -fsanitize-coverage=func %t.o %libdl -o %t 6 7 // RUN: rm -rf %T/coverage-direct-activation 8 9 // RUN: mkdir -p %T/coverage-direct-activation/normal 10 // RUN: %env_asan_opts=coverage=1,coverage_direct=0,coverage_dir=%T/coverage-direct-activation/normal:verbosity=1 %run %t %dynamiclib 11 // RUN: %sancov print %T/coverage-direct-activation/normal/*.sancov >%T/coverage-direct-activation/normal/out.txt 12 13 // RUN: mkdir -p %T/coverage-direct-activation/direct 14 // RUN: %env_asan_opts=start_deactivated=1,coverage_direct=1,verbosity=1 \ 15 // RUN: ASAN_ACTIVATION_OPTIONS=coverage=1,coverage_dir=%T/coverage-direct-activation/direct %run %t %dynamiclib 16 // RUN: cd %T/coverage-direct-activation/direct 17 // RUN: %sancov rawunpack *.sancov.raw 18 // RUN: %sancov print *.sancov >out.txt 19 // RUN: cd ../.. 20 21 // Test start_deactivated=1,coverage=1 in ASAN_OPTIONS. 22 23 // RUN: diff -u coverage-direct-activation/normal/out.txt coverage-direct-activation/direct/out.txt 24 25 // RUN: mkdir -p %T/coverage-direct-activation/direct2 26 // RUN: %env_asan_opts=start_deactivated=1,coverage=1,coverage_direct=1,verbosity=1 \ 27 // RUN: ASAN_ACTIVATION_OPTIONS=coverage_dir=%T/coverage-direct-activation/direct2 %run %t %dynamiclib 28 // RUN: cd %T/coverage-direct-activation/direct2 29 // RUN: %sancov rawunpack *.sancov.raw 30 // RUN: %sancov print *.sancov >out.txt 31 // RUN: cd ../.. 32 33 // RUN: diff -u coverage-direct-activation/normal/out.txt coverage-direct-activation/direct2/out.txt 34 35 // XFAIL: android 36 37 #include <assert.h> 38 #include <dlfcn.h> 39 #include <stdio.h> 40 #include <unistd.h> 41 42 #ifdef SHARED 43 extern "C" { 44 void bar() { printf("bar\n"); } 45 } 46 #else 47 48 int main(int argc, char **argv) { 49 fprintf(stderr, "PID: %d\n", getpid()); 50 assert(argc > 1); 51 void *handle1 = dlopen(argv[1], RTLD_LAZY); // %dynamiclib 52 assert(handle1); 53 void (*bar1)() = (void (*)())dlsym(handle1, "bar"); 54 assert(bar1); 55 bar1(); 56 57 return 0; 58 } 59 #endif 60