1 // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 2 // XFAIL: android 3 // Fails with debug checks: https://bugs.llvm.org/show_bug.cgi?id=46862 4 // XFAIL: !compiler-rt-optimized && !riscv64 5 // 6 // We use fast_unwind_on_malloc=0 to have full unwinding even w/o frame 7 // pointers. This setting is not on by default because it's too expensive. 8 // 9 // Different size: detect a bug if detect_odr_violation>=1 10 // RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %dynamiclib 11 // RUN: %clangxx_asan %s %ld_flags_rpath_exe -o %t-ODR-EXE 12 // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1 not %run %t-ODR-EXE 2>&1 | FileCheck %s 13 // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s 14 // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=0 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED 15 // RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s 16 // 17 // Same size: report a bug only if detect_odr_violation>=2. 18 // RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %dynamiclib -DSZ=100 19 // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED 20 // RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s 21 // RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s 22 // RUN: echo "odr_violation:foo::ZZZ" > %t.supp 23 // 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 24 // RUN: echo "odr_violation:foo::G" > %t.supp 25 // 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 26 // RUN: rm -f %t.supp 27 // 28 // Use private aliases for global variables without indicator symbol. 29 // RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared -mllvm -asan-use-private-alias %s -o %dynamiclib -DSZ=100 30 // RUN: %clangxx_asan -mllvm -asan-use-private-alias %s %ld_flags_rpath_exe -o %t-ODR-EXE 31 // RUN: %env_asan_opts=fast_unwind_on_malloc=0 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED 32 33 // Use private aliases for global variables: use indicator symbol to detect ODR violation. 34 // RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared -mllvm -asan-use-private-alias -mllvm -asan-use-odr-indicator %s -o %dynamiclib -DSZ=100 35 // RUN: %clangxx_asan -mllvm -asan-use-private-alias -mllvm -asan-use-odr-indicator %s %ld_flags_rpath_exe -o %t-ODR-EXE 36 // RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s 37 38 // Same as above but with clang switches. 39 // RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared -fsanitize-address-use-odr-indicator %s -o %dynamiclib -DSZ=100 40 // RUN: %clangxx_asan -fsanitize-address-use-odr-indicator %s %ld_flags_rpath_exe -o %t-ODR-EXE 41 // RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s 42 43 // GNU driver doesn't handle .so files properly. 44 // REQUIRES: Clang 45 46 // REQUIRES: fast-unwinder-works 47 48 #ifndef SZ 49 # define SZ 4 50 #endif 51 52 #if BUILD_SO 53 namespace foo { char G[SZ]; } 54 #else 55 #include <stdio.h> 56 namespace foo { char G[100]; } 57 // CHECK: ERROR: AddressSanitizer: odr-violation 58 // CHECK: size=100 'foo::G' {{.*}}odr-violation.cpp:[[@LINE-2]]:22 59 // CHECK: size={{4|100}} 'foo::G' 60 int main(int argc, char **argv) { 61 printf("PASS: %p\n", &foo::G); 62 } 63 #endif 64 65 // CHECK: These globals were registered at these points: 66 // CHECK: {{odr-violation.cpp|ODR-EXE}} 67 // CHECK: odr-violation.cpp{{$}} 68 // CHECK: SUMMARY: AddressSanitizer: odr-violation: global 'foo::G' at {{.*}}odr-violation.cpp 69 // DISABLED: PASS 70