For an odr-violation error due to a source file linked into two DSOs, or
one DSO and the main executable, it can be difficult to identify the DSO
name. Let's print the module name in the error report.
```
echo 'extern long var; int main() { return var; }' > a.cc
echo 'long var;' > b.cc
clang++ -fpic -fsanitize=address -shared b.cc -o b.so
clang++ -fsanitize=address a.cc b.cc ./b.so -o a
```
w/o this patch:
```
==1375386==ERROR: AddressSanitizer: odr-violation (0x56067cb06240):
[1] size=8 'var' b.cc
[2] size=8 'var' b.cc
...
```
w/ this patch:
```
==1375386==ERROR: AddressSanitizer: odr-violation (0x56067cb06240):
[1] size=8 'var' b.cc in /tmp/c/a
[2] size=8 'var' b.cc in ./b.so
```
In addition, update the `report_globals=2` message to include the module
name
```
==1451005==Added Global[0x7fcfe59ae040]: beg=0x7fcfe59ae140 size=8/32 name=var source=b.cc module=./b.so dyn_init=0 odr_indicator=0x55754f939260
```
73 lines
3.9 KiB
C++
73 lines
3.9 KiB
C++
// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
|
|
// XFAIL: android
|
|
// Fails with debug checks: https://bugs.llvm.org/show_bug.cgi?id=46862
|
|
// XFAIL: !compiler-rt-optimized && !target=riscv64{{.*}}
|
|
//
|
|
// We use fast_unwind_on_malloc=0 to have full unwinding even w/o frame
|
|
// pointers. This setting is not on by default because it's too expensive.
|
|
//
|
|
// Note, -asan-use-private-alias=1 -asan-use-odr-indicator=1 is the default.
|
|
// -fno-sanitize-address-use-odr-indicator turns off both.
|
|
//
|
|
// Different size: detect a bug if detect_odr_violation>=1
|
|
// RUN: %clangxx_asan -g -DBUILD_SO=1 -fPIC -shared -fno-sanitize-address-use-odr-indicator %s -o %dynamiclib
|
|
// RUN: %clangxx_asan -g -fno-sanitize-address-use-odr-indicator %s %ld_flags_rpath_exe -o %t-ODR-EXE
|
|
// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1 not %run %t-ODR-EXE 2>&1 | FileCheck %s
|
|
// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
|
|
// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=0 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
|
|
// RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s
|
|
//
|
|
// Same size: report a bug only if detect_odr_violation>=2.
|
|
// RUN: %clangxx_asan -g -DBUILD_SO=1 -fPIC -shared -fno-sanitize-address-use-odr-indicator %s -o %dynamiclib -DSZ=100
|
|
// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
|
|
// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
|
|
// RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s
|
|
// RUN: echo "odr_violation:foo::ZZZ" > %t.supp
|
|
// 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
|
|
// RUN: echo "odr_violation:foo::G" > %t.supp
|
|
// 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
|
|
// RUN: rm -f %t.supp
|
|
//
|
|
// Use private aliases for global variables without indicator symbol.
|
|
// RUN: %clangxx_asan -g -DBUILD_SO=1 -fPIC -shared -mllvm -asan-use-odr-indicator=0 %s -o %dynamiclib -DSZ=100
|
|
// RUN: %clangxx_asan -g -mllvm -asan-use-odr-indicator=0 %s %ld_flags_rpath_exe -o %t-ODR-EXE
|
|
// RUN: %env_asan_opts=fast_unwind_on_malloc=0 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
|
|
|
|
// Use private aliases for global variables: use indicator symbol to detect ODR violation.
|
|
// RUN: %clangxx_asan -g -DBUILD_SO=1 -fPIC -shared %s -o %dynamiclib -DSZ=100
|
|
// RUN: %clangxx_asan -g %s %ld_flags_rpath_exe -o %t-ODR-EXE
|
|
// RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s
|
|
|
|
// Same as above but with clang switches.
|
|
// RUN: %clangxx_asan -g -DBUILD_SO=1 -fPIC -shared -fsanitize-address-use-odr-indicator %s -o %dynamiclib -DSZ=100
|
|
// RUN: %clangxx_asan -g -fsanitize-address-use-odr-indicator %s %ld_flags_rpath_exe -o %t-ODR-EXE
|
|
// RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s
|
|
|
|
// GNU driver doesn't handle .so files properly.
|
|
// REQUIRES: Clang
|
|
|
|
// REQUIRES: fast-unwinder-works
|
|
|
|
#ifndef SZ
|
|
# define SZ 4
|
|
#endif
|
|
|
|
#if BUILD_SO
|
|
namespace foo { char G[SZ]; }
|
|
#else
|
|
#include <stdio.h>
|
|
namespace foo { char G[100]; }
|
|
// CHECK: ERROR: AddressSanitizer: odr-violation
|
|
// CHECK: size=100 'foo::G' {{.*}}odr-violation.cpp:[[@LINE-2]] in {{.*}}.tmp-ODR-EXE
|
|
// CHECK: size={{4|100}} 'foo::G'
|
|
int main(int argc, char **argv) {
|
|
printf("PASS: %p\n", &foo::G);
|
|
}
|
|
#endif
|
|
|
|
// CHECK: These globals were registered at these points:
|
|
// CHECK: {{odr-violation.cpp|ODR-EXE}}
|
|
// CHECK: odr-violation.cpp{{$}}
|
|
// CHECK: SUMMARY: AddressSanitizer: odr-violation: global 'foo::G' at {{.*}}odr-violation.cpp
|
|
// DISABLED: PASS
|