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 | // REQUIRES: stable-runtime |
11 | |
12 | // UNSUPPORTED: ios |
13 | |
14 | #if !defined(SHARED_LIB) |
15 | #include <dlfcn.h> |
16 | #include <stdio.h> |
17 | #include <stdlib.h> |
18 | |
19 | #include <string> |
20 | |
21 | using std::string; |
22 | |
23 | typedef void (fun_t)(int*, int); |
24 | |
25 | int main(int argc, char *argv[]) { |
26 | string path = string(argv[0]) + "-so.so" ; |
27 | printf(format: "opening %s ... \n" , path.c_str()); |
28 | void *lib = dlopen(file: path.c_str(), RTLD_NOW); |
29 | if (!lib) { |
30 | printf(format: "error in dlopen(): %s\n" , dlerror()); |
31 | return 1; |
32 | } |
33 | fun_t *inc2 = (fun_t*)dlsym(handle: lib, name: "inc2" ); |
34 | if (!inc2) return 1; |
35 | printf(format: "ok\n" ); |
36 | int *array = (int*)malloc(size: 40); |
37 | inc2(array, 1); |
38 | inc2(array, -1); // BOOM |
39 | // CHECK: ERROR: AddressSanitizer: heap-buffer-overflow |
40 | // CHECK: READ of size 4 at 0x{{.*}} |
41 | // CHECK: #0 {{.*}} in inc2 {{.*}}asan-symbolize-sanity-test.cpp:[[@LINE+21]] |
42 | // CHECK: #1 {{.*}} in main {{.*}}asan-symbolize-sanity-test.cpp:[[@LINE-4]] |
43 | // CHECK: allocated by thread T{{.*}} here: |
44 | // CHECK: #{{.*}} in {{(wrap_|_?__interceptor_)?}}malloc |
45 | // CHECK: #{{.*}} in main {{.*}}asan-symbolize-sanity-test.cpp:[[@LINE-9]] |
46 | return 0; |
47 | } |
48 | #else // SHARED_LIBS |
49 | #include <stdio.h> |
50 | #include <string.h> |
51 | |
52 | int pad[10]; |
53 | int GLOB[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
54 | |
55 | extern "C" |
56 | void inc(int index) { |
57 | GLOB[index]++; |
58 | } |
59 | |
60 | extern "C" |
61 | void inc2(int *a, int index) { |
62 | a[index]++; |
63 | } |
64 | #endif // SHARED_LIBS |
65 | |