Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 1 | // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 |
| 2 | // XFAIL: android |
| 3 | // |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 4 | // Check that asan_symbolize.py script works (for binaries, ASan RTL and |
| 5 | // shared object files. |
| 6 | |
| 7 | // RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 8 | // RUN: %clangxx_asan -O0 %s %libdl -o %t |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 9 | // RUN: %env_asan_opts=symbolize=0 not %run %t 2>&1 | %asan_symbolize | FileCheck %s |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 10 | // XFAIL: arm-linux-gnueabi |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 11 | // XFAIL: armv7l-unknown-linux-gnueabihf |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 12 | |
| 13 | #if !defined(SHARED_LIB) |
| 14 | #include <dlfcn.h> |
| 15 | #include <stdio.h> |
| 16 | #include <stdlib.h> |
| 17 | |
| 18 | #include <string> |
| 19 | |
| 20 | using std::string; |
| 21 | |
| 22 | typedef void (fun_t)(int*, int); |
| 23 | |
| 24 | int main(int argc, char *argv[]) { |
| 25 | string path = string(argv[0]) + "-so.so"; |
| 26 | printf("opening %s ... \n", path.c_str()); |
| 27 | void *lib = dlopen(path.c_str(), RTLD_NOW); |
| 28 | if (!lib) { |
| 29 | printf("error in dlopen(): %s\n", dlerror()); |
| 30 | return 1; |
| 31 | } |
| 32 | fun_t *inc2 = (fun_t*)dlsym(lib, "inc2"); |
| 33 | if (!inc2) return 1; |
| 34 | printf("ok\n"); |
| 35 | int *array = (int*)malloc(40); |
| 36 | inc2(array, 1); |
| 37 | inc2(array, -1); // BOOM |
| 38 | // CHECK: ERROR: AddressSanitizer: heap-buffer-overflow |
| 39 | // CHECK: READ of size 4 at 0x{{.*}} |
| 40 | // CHECK: #0 {{.*}} in inc2 {{.*}}asan-symbolize-sanity-test.cc:[[@LINE+21]] |
| 41 | // CHECK: #1 {{.*}} in main {{.*}}asan-symbolize-sanity-test.cc:[[@LINE-4]] |
| 42 | // CHECK: allocated by thread T{{.*}} here: |
| 43 | // CHECK: #{{.*}} in {{(wrap_|__interceptor_)?}}malloc |
| 44 | // CHECK: #{{.*}} in main {{.*}}asan-symbolize-sanity-test.cc:[[@LINE-9]] |
| 45 | return 0; |
| 46 | } |
| 47 | #else // SHARED_LIBS |
| 48 | #include <stdio.h> |
| 49 | #include <string.h> |
| 50 | |
| 51 | int pad[10]; |
| 52 | int GLOB[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
| 53 | |
| 54 | extern "C" |
| 55 | void inc(int index) { |
| 56 | GLOB[index]++; |
| 57 | } |
| 58 | |
| 59 | extern "C" |
| 60 | void inc2(int *a, int index) { |
| 61 | a[index]++; |
| 62 | } |
| 63 | #endif // SHARED_LIBS |