]> git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/asan/TestCases/asan-symbolize-sanity-test.cc
Imported Upstream version 1.5.0+dfsg1
[rustc.git] / src / compiler-rt / test / asan / TestCases / asan-symbolize-sanity-test.cc
1 // Check that asan_symbolize.py script works (for binaries, ASan RTL and
2 // shared object files.
3
4 // RUN: %clangxx_asan -O0 %p/SharedLibs/shared-lib-test-so.cc -fPIC -shared -o %t-so.so
5 // RUN: %clangxx_asan -O0 %s -ldl -o %t
6 // RUN: ASAN_OPTIONS=symbolize=0 not %run %t 2>&1 | %asan_symbolize | FileCheck %s
7 #include <dlfcn.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10
11 #include <string>
12
13 using std::string;
14
15 typedef void (fun_t)(int*, int);
16
17 int main(int argc, char *argv[]) {
18 string path = string(argv[0]) + "-so.so";
19 printf("opening %s ... \n", path.c_str());
20 void *lib = dlopen(path.c_str(), RTLD_NOW);
21 if (!lib) {
22 printf("error in dlopen(): %s\n", dlerror());
23 return 1;
24 }
25 fun_t *inc2 = (fun_t*)dlsym(lib, "inc2");
26 if (!inc2) return 1;
27 printf("ok\n");
28 int *array = (int*)malloc(40);
29 inc2(array, 1);
30 inc2(array, -1); // BOOM
31 // CHECK: ERROR: AddressSanitizer: heap-buffer-overflow
32 // CHECK: READ of size 4 at 0x{{.*}}
33 // CHECK: #0 {{.*}} in inc2 {{.*}}shared-lib-test-so.cc:26
34 // CHECK: #1 {{.*}} in main {{.*}}asan-symbolize-sanity-test.cc:[[@LINE-4]]
35 // CHECK: allocated by thread T{{.*}} here:
36 // CHECK: #{{.*}} in {{(wrap_|__interceptor_)?}}malloc
37 // CHECK: #{{.*}} in main {{.*}}asan-symbolize-sanity-test.cc:[[@LINE-9]]
38 return 0;
39 }