74 lines · cpp
1// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=3162// XFAIL: android3// Fails with debug checks: https://bugs.llvm.org/show_bug.cgi?id=468624// XFAIL: !compiler-rt-optimized && !target=riscv64{{.*}}5//6// We use fast_unwind_on_malloc=0 to have full unwinding even w/o frame7// pointers. This setting is not on by default because it's too expensive.8//9// Note, -asan-use-private-alias=1 -asan-use-odr-indicator=1 is the default.10// -fno-sanitize-address-use-odr-indicator turns off both.11//12// Different size: detect a bug if detect_odr_violation>=113// RUN: mkdir -p %t.dir && cd %t.dir14// RUN: %clangxx_asan -g -DBUILD_SO=1 -fPIC -shared -fno-sanitize-address-use-odr-indicator %s -o %dynamiclib15// RUN: %clangxx_asan -g -fno-sanitize-address-use-odr-indicator %s %ld_flags_rpath_exe -o %t.dir/ODR-EXE16// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1 not %run %t.dir/ODR-EXE 2>&1 | FileCheck %s17// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t.dir/ODR-EXE 2>&1 | FileCheck %s18// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=0 %run %t.dir/ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED19// RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t.dir/ODR-EXE 2>&1 | FileCheck %s20//21// Same size: report a bug only if detect_odr_violation>=2.22// RUN: %clangxx_asan -g -DBUILD_SO=1 -fPIC -shared -fno-sanitize-address-use-odr-indicator %s -o %dynamiclib -DSZ=10023// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1 %run %t.dir/ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED24// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t.dir/ODR-EXE 2>&1 | FileCheck %s25// RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t.dir/ODR-EXE 2>&1 | FileCheck %s26// RUN: echo "odr_violation:foo::ZZZ" > %t.dir/supp27// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2:suppressions=%t.dir/supp not %run %t.dir/ODR-EXE 2>&1 | FileCheck %s28// RUN: echo "odr_violation:foo::G" > %t.dir/supp29// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2:suppressions=%t.dir/supp %run %t.dir/ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED30// RUN: rm -f %t.dir/supp31//32// Use private aliases for global variables without indicator symbol.33// RUN: %clangxx_asan -g -DBUILD_SO=1 -fPIC -shared -mllvm -asan-use-odr-indicator=0 %s -o %dynamiclib -DSZ=10034// RUN: %clangxx_asan -g -mllvm -asan-use-odr-indicator=0 %s %ld_flags_rpath_exe -o %t.dir/ODR-EXE35// RUN: %env_asan_opts=fast_unwind_on_malloc=0 %run %t.dir/ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED36 37// Use private aliases for global variables: use indicator symbol to detect ODR violation.38// RUN: %clangxx_asan -g -DBUILD_SO=1 -fPIC -shared %s -o %dynamiclib -DSZ=10039// RUN: %clangxx_asan -g %s %ld_flags_rpath_exe -o %t.dir/ODR-EXE40// RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t.dir/ODR-EXE 2>&1 | FileCheck %s41 42// Same as above but with clang switches.43// RUN: %clangxx_asan -g -DBUILD_SO=1 -fPIC -shared -fsanitize-address-use-odr-indicator %s -o %dynamiclib -DSZ=10044// RUN: %clangxx_asan -g -fsanitize-address-use-odr-indicator %s %ld_flags_rpath_exe -o %t.dir/ODR-EXE45// RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t.dir/ODR-EXE 2>&1 | FileCheck %s46 47// GNU driver doesn't handle .so files properly.48// REQUIRES: Clang49 50// REQUIRES: fast-unwinder-works51 52#ifndef SZ53# define SZ 454#endif55 56#if BUILD_SO57namespace foo { char G[SZ]; }58#else59#include <stdio.h>60namespace foo { char G[100]; }61// CHECK: ERROR: AddressSanitizer: odr-violation62// CHECK: size=100 'foo::G' {{.*}}odr-violation.cpp:[[@LINE-2]] in {{.*}}/ODR-EXE63// CHECK: size={{4|100}} 'foo::G'64int main(int argc, char **argv) {65 printf("PASS: %p\n", &foo::G);66}67#endif68 69// CHECK: These globals were registered at these points:70// CHECK: {{odr-violation.cpp|ODR-EXE}}71// CHECK: odr-violation.cpp{{$}}72// CHECK: SUMMARY: AddressSanitizer: odr-violation: global 'foo::G' at {{.*}}odr-violation.cpp73// DISABLED: PASS74