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 %libdl -o %t 9 // RUN: %env_asan_opts=symbolize=0 not %run %t 2>&1 | %asan_symbolize | FileCheck %s 10 // XFAIL: arm-linux-gnueabi 11 // XFAIL: armv7l-unknown-linux-gnueabihf 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 64