Home | History | Annotate | Download | only in Linux
      1 // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
      2 // XFAIL: android
      3 //
      4 // We use fast_unwind_on_malloc=0 to have full unwinding even w/o frame
      5 // pointers. This setting is not on by default because it's too expensive.
      6 //
      7 // Different size: detect a bug if detect_odr_violation>=1
      8 // RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t-ODR-SO.so
      9 // RUN: %clangxx_asan %s %t-ODR-SO.so -Wl,-R. -o %t-ODR-EXE
     10 // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1 not %run %t-ODR-EXE 2>&1 | FileCheck %s
     11 // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
     12 // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=0     %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
     13 // RUN: %env_asan_opts=fast_unwind_on_malloc=0                        not %run %t-ODR-EXE 2>&1 | FileCheck %s
     14 //
     15 // Same size: report a bug only if detect_odr_violation>=2.
     16 // RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t-ODR-SO.so -DSZ=100
     17 // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1     %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
     18 // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
     19 // RUN: %env_asan_opts=fast_unwind_on_malloc=0                        not %run %t-ODR-EXE 2>&1 | FileCheck %s
     20 // RUN: echo "odr_violation:foo::ZZZ" > %t.supp
     21 // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2:suppressions=%t.supp  not %run %t-ODR-EXE 2>&1 | FileCheck %s
     22 // RUN: echo "odr_violation:foo::G" > %t.supp
     23 // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2:suppressions=%t.supp      %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
     24 // RUN: rm -f %t.supp
     25 
     26 // GNU driver doesn't handle .so files properly.
     27 // REQUIRES: Clang
     28 
     29 #ifndef SZ
     30 # define SZ 4
     31 #endif
     32 
     33 #if BUILD_SO
     34 namespace foo { char G[SZ]; }
     35 #else
     36 #include <stdio.h>
     37 namespace foo { char G[100]; }
     38 // CHECK: ERROR: AddressSanitizer: odr-violation
     39 // CHECK: size=100 'foo::G' {{.*}}odr-violation.cc:[[@LINE-2]]:22
     40 // CHECK: size={{4|100}} 'foo::G'
     41 int main(int argc, char **argv) {
     42   printf("PASS: %p\n", &foo::G);
     43 }
     44 #endif
     45 
     46 // CHECK: These globals were registered at these points:
     47 // CHECK: ODR-EXE
     48 // CHECK: ODR-SO
     49 // CHECK: SUMMARY: AddressSanitizer: odr-violation: global 'foo::G' at {{.*}}odr-violation.cc
     50 // DISABLED: PASS
     51