1 // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 2 // XFAIL: android 3 // 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 8 // RUN: %clangxx_asan -O0 %s -ldl -o %t 9 // RUN: env ASAN_OPTIONS=symbolize=0 not %run %t 2>&1 | %asan_symbolize | FileCheck %s 10 // XFAIL: arm-linux-gnueabi 11 12 #if !defined(SHARED_LIB) 13 #include <dlfcn.h> 14 #include <stdio.h> 15 #include <stdlib.h> 16 17 #include <string> 18 19 using std::string; 20 21 typedef void (fun_t)(int*, int); 22 23 int main(int argc, char *argv[]) { 24 string path = string(argv[0]) + "-so.so"; 25 printf("opening %s ... \n", path.c_str()); 26 void *lib = dlopen(path.c_str(), RTLD_NOW); 27 if (!lib) { 28 printf("error in dlopen(): %s\n", dlerror()); 29 return 1; 30 } 31 fun_t *inc2 = (fun_t*)dlsym(lib, "inc2"); 32 if (!inc2) return 1; 33 printf("ok\n"); 34 int *array = (int*)malloc(40); 35 inc2(array, 1); 36 inc2(array, -1); // BOOM 37 // CHECK: ERROR: AddressSanitizer: heap-buffer-overflow 38 // CHECK: READ of size 4 at 0x{{.*}} 39 // CHECK: #0 {{.*}} in inc2 {{.*}}asan-symbolize-sanity-test.cc:[[@LINE+21]] 40 // CHECK: #1 {{.*}} in main {{.*}}asan-symbolize-sanity-test.cc:[[@LINE-4]] 41 // CHECK: allocated by thread T{{.*}} here: 42 // CHECK: #{{.*}} in {{(wrap_|__interceptor_)?}}malloc 43 // CHECK: #{{.*}} in main {{.*}}asan-symbolize-sanity-test.cc:[[@LINE-9]] 44 return 0; 45 } 46 #else // SHARED_LIBS 47 #include <stdio.h> 48 #include <string.h> 49 50 int pad[10]; 51 int GLOB[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 52 53 extern "C" 54 void inc(int index) { 55 GLOB[index]++; 56 } 57 58 extern "C" 59 void inc2(int *a, int index) { 60 a[index]++; 61 } 62 #endif // SHARED_LIBS 63