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 // CHECK: The following global variable is not properly aligned.
14 // CHECK: ERROR: AddressSanitizer: odr-violation
15 #if defined(FILE1)
16 __attribute__((aligned(8))) int x;
17 __attribute__((aligned(1))) char y;
18 // The gold linker puts ZZZ at the start of bss (where it is aligned)
19 // unless we have a large alternative like Displace:
20 __attribute__((aligned(1))) char Displace[105];
21 __attribute__((aligned(1))) char ZZZ[100];
22 #elif defined(FILE2)
23 int ZZZ = 1;
24 #else
25 extern int ZZZ;
main()26 int main() {
27 return ZZZ;
28 }
29 #endif
30
31