Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 1 | // Check that unloading a module doesn't break coverage dumping for remaining |
| 2 | // modules. |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame^] | 3 | // RUN: %clangxx_asan -fsanitize-coverage=func -DSHARED %s -shared -o %dynamiclib1 -fPIC |
| 4 | // RUN: %clangxx_asan -fsanitize-coverage=func -DSHARED %s -shared -o %dynamiclib2 -fPIC |
| 5 | // RUN: %clangxx_asan -fsanitize-coverage=func %s %libdl -o %t |
| 6 | // RUN: export ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 7 | // RUN: mkdir -p %T/coverage-module-unloaded && cd %T/coverage-module-unloaded |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 8 | // RUN: %run %t %dynamiclib1 %dynamiclib2 2>&1 | FileCheck %s |
| 9 | // RUN: %run %t %dynamiclib1 %dynamiclib2 foo 2>&1 | FileCheck %s |
| 10 | // RUN: rm -r %T/coverage-module-unloaded |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 11 | // |
| 12 | // https://code.google.com/p/address-sanitizer/issues/detail?id=263 |
| 13 | // XFAIL: android |
| 14 | |
| 15 | #include <assert.h> |
| 16 | #include <dlfcn.h> |
| 17 | #include <stdio.h> |
| 18 | #include <unistd.h> |
| 19 | |
| 20 | #ifdef SHARED |
| 21 | extern "C" { |
| 22 | void bar() { printf("bar\n"); } |
| 23 | } |
| 24 | #else |
| 25 | |
| 26 | int main(int argc, char **argv) { |
| 27 | fprintf(stderr, "PID: %d\n", getpid()); |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 28 | assert(argc > 2); |
| 29 | void *handle1 = dlopen(argv[1], RTLD_LAZY); // %dynamiclib1 |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 30 | assert(handle1); |
| 31 | void (*bar1)() = (void (*)())dlsym(handle1, "bar"); |
| 32 | assert(bar1); |
| 33 | bar1(); |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 34 | void *handle2 = dlopen(argv[2], RTLD_LAZY); // %dynamiclib2 |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 35 | assert(handle2); |
| 36 | void (*bar2)() = (void (*)())dlsym(handle2, "bar"); |
| 37 | assert(bar2); |
| 38 | bar2(); |
| 39 | |
| 40 | // It matters whether the unloaded module has a higher or lower address range |
| 41 | // than the remaining one. Make sure to test both cases. |
| 42 | if (argc < 2) |
| 43 | dlclose(bar1 < bar2 ? handle1 : handle2); |
| 44 | else |
| 45 | dlclose(bar1 < bar2 ? handle2 : handle1); |
| 46 | return 0; |
| 47 | } |
| 48 | #endif |
| 49 | |
| 50 | // CHECK: PID: [[PID:[0-9]+]] |
| 51 | // CHECK: [[PID]].sancov: 1 PCs written |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 52 | // CHECK: coverage-module-unloaded{{.*}}1.[[PID]] |
| 53 | // CHECK: coverage-module-unloaded{{.*}}2.[[PID]] |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 54 | // Even though we've unloaded one of the libs we still dump the coverage file |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 55 | // for that lib (although the data will be inaccurate, if at all useful) |