1// Test that mixing instrumented and non-instrumented code doesn't lead to crash.
2// Build two modules (one is instrumented, another is not) that have globals
3// with same names. Check, that ASan doesn't crash with CHECK failure or
4// false positive global-buffer-overflow due to sanitized library poisons
5// globals from non-sanitized one.
6//
7// RUN: %clangxx_asan -DBUILD_INSTRUMENTED_DSO=1 -fPIC -shared -mllvm -asan-use-private-alias %s -o %dynamiclib1
8// RUN: %clangxx -DBUILD_UNINSTRUMENTED_DSO=1 -fPIC -shared %s -o %dynamiclib2
9// RUN: %clangxx %s -c -mllvm -asan-use-private-alias -o %t.o
10// RUN: %clangxx_asan %t.o %ld_flags_rpath_exe2 %ld_flags_rpath_exe1 -o %t-EXE
11// RUN: %run %t-EXE
12
13#if defined (BUILD_INSTRUMENTED_DSO)
14long h = 15;
15long f = 4;
16long foo(long *p) {
17 return *p;
18}
19#elif defined (BUILD_UNINSTRUMENTED_DSO)
20long foo(long *);
21long h = 12;
22long i = 13;
23long f = 5;
24
25int bar() {
26 if (foo(&f) != 5 || foo(&h) != 12 || foo(&i) != 13)
27 return 1;
28 return 0;
29}
30#else
31extern int bar();
32
33int main() {
34 return bar();
35}
36#endif
37

source code of compiler-rt/test/asan/TestCases/Linux/local_alias.cpp