| 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) |
| 26 | int ZZZ = 1; |
| 27 | #else |
| 28 | extern int ZZZ; |
| 29 | int main() { |
| 30 | return ZZZ; |
| 31 | } |
| 32 | #endif |
| 33 | |
| 34 | |