blob: dd59e4a60774a31edc6ac9a855f7247feba88958 [file] [log] [blame]
Stephen Hines6a211c52014-07-21 00:49:56 -07001// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
2// XFAIL: android
3//
Stephen Hines2d1fdb22014-05-28 23:58:16 -07004// 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 Hines86277eb2015-03-23 12:06:32 -07008// RUN: %clangxx_asan -O0 %s %libdl -o %t
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -08009// RUN: %env_asan_opts=symbolize=0 not %run %t 2>&1 | %asan_symbolize | FileCheck %s
Stephen Hines6a211c52014-07-21 00:49:56 -070010// XFAIL: arm-linux-gnueabi
Stephen Hines6d186232014-11-26 17:56:19 -080011// XFAIL: armv7l-unknown-linux-gnueabihf
Stephen Hines2d1fdb22014-05-28 23:58:16 -070012
13#if !defined(SHARED_LIB)
14#include <dlfcn.h>
15#include <stdio.h>
16#include <stdlib.h>
17
18#include <string>
19
20using std::string;
21
22typedef void (fun_t)(int*, int);
23
24int 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
51int pad[10];
52int GLOB[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
53
54extern "C"
55void inc(int index) {
56 GLOB[index]++;
57}
58
59extern "C"
60void inc2(int *a, int index) {
61 a[index]++;
62}
63#endif // SHARED_LIBS