1// RUN: %clangxx -DFUNC=zzzz %s -shared -o %dynamiclib -fPIC
2// RUN: %clangxx_asan -DFUNC=main %s -o %t %ld_flags_rpath_exe
3// RUN: %run %t
4
5// GNU driver doesn't handle .so files properly.
6// REQUIRES: Clang
7
8// This test ensures that we call __asan_init early enough.
9// We build a shared library w/o asan instrumentation
10// and the binary with asan instrumentation.
11// Both files include the same header (emulated by -DFUNC here)
12// with C++ template magic which runs global initializer at library load time.
13// The function get() is instrumented with asan, but called
14// before the usual constructors are run.
15// So, we must make sure that __asan_init is executed even earlier.
16//
17// See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56393
18
19struct A {
20 int foo() const { return 0; }
21};
22A get () { return A(); }
23template <class> struct O {
24 static A const e;
25};
26template <class T> A const O <T>::e = get();
27int FUNC() {
28 return O<int>::e.foo();
29}
30
31

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