1// Test that we can properly report an ODR violation between an instrumented
2// global and a non-instrumented global if not using private aliases.
3
4// RUN: %clang_asan -fcommon %s -fPIC -shared -mllvm -asan-use-private-alias=0 -o %dynamiclib1 -DFILE1
5// RUN: %clang_asan -fcommon %s -fPIC -shared -mllvm -asan-use-private-alias=0 -o %dynamiclib2 -DFILE2
6// RUN: %clang_asan -fcommon %s -fPIE %ld_flags_rpath_exe1 %ld_flags_rpath_exe2 -o %t
7// RUN: not %run %t 2>&1 | FileCheck %s
8
9// RUN: %clang_asan -fcommon %s -fPIC -shared -mllvm -asan-use-private-alias=1 -o %dynamiclib1 -DFILE1
10// RUN: %clang_asan -fcommon %s -fPIC -shared -mllvm -asan-use-private-alias=1 -o %dynamiclib2 -DFILE2
11// RUN: %run %t 2>&1 | count 0
12
13// Unaligned accesses don't work on strict-alignment targets like SPARC.
14// UNSUPPORTED: sparc-target-arch
15
16// CHECK: The following global variable is not properly aligned.
17// CHECK: ERROR: AddressSanitizer: odr-violation
18#if defined(FILE1)
19__attribute__((aligned(8))) int x;
20__attribute__((aligned(1))) char y;
21// The gold linker puts ZZZ at the start of bss (where it is aligned)
22// unless we have a large alternative like Displace:
23__attribute__((aligned(1))) char Displace[105];
24__attribute__((aligned(1))) char ZZZ[100];
25#elif defined(FILE2)
26int ZZZ = 1;
27#else
28extern int ZZZ;
29int main() {
30 return ZZZ;
31}
32#endif
33
34

source code of compiler-rt/test/asan/TestCases/Linux/odr_c_test.c