65 lines · cpp
1// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=3162// XFAIL: android3//4// Check that asan_symbolize.py script works (for binaries, ASan RTL and5// shared object files.6 7// RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so8// RUN: %clangxx_asan -O0 %s %libdl -o %t9// RUN: %env_asan_opts=symbolize=0 not %run %t 2>&1 | %asan_symbolize | FileCheck %s10// REQUIRES: stable-runtime11 12// UNSUPPORTED: ios13 14#if !defined(SHARED_LIB)15#include <dlfcn.h>16#include <stdio.h>17#include <stdlib.h>18 19#include <string>20 21using std::string;22 23typedef void (fun_t)(int*, int);24 25int main(int argc, char *argv[]) {26 string path = string(argv[0]) + "-so.so";27 printf("opening %s ... \n", path.c_str());28 void *lib = dlopen(path.c_str(), RTLD_NOW);29 if (!lib) {30 printf("error in dlopen(): %s\n", dlerror());31 return 1;32 }33 fun_t *inc2 = (fun_t*)dlsym(lib, "inc2");34 if (!inc2) return 1;35 printf("ok\n");36 int *array = (int*)malloc(40);37 inc2(array, 1);38 inc2(array, -1); // BOOM39 // CHECK: ERROR: AddressSanitizer: heap-buffer-overflow40 // 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_)?}}malloc45 // CHECK: #{{.*}} in main {{.*}}asan-symbolize-sanity-test.cpp:[[@LINE-9]]46 return 0;47}48#else // SHARED_LIBS49#include <stdio.h>50#include <string.h>51 52int pad[10];53int GLOB[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};54 55extern "C"56void inc(int index) {57 GLOB[index]++;58}59 60extern "C"61void inc2(int *a, int index) {62 a[index]++;63}64#endif // SHARED_LIBS65