gcc/
[official-gcc.git] / libsanitizer / asan / asan_preinit.cc
blob31042401536dfdced13f03d013a9cab9fd8766c4
1 //===-- asan_preinit.cc ---------------------------------------------------===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is a part of AddressSanitizer, an address sanity checker.
9 //
10 // Call __asan_init at the very early stage of process startup.
11 // On Linux we use .preinit_array section (unless PIC macro is defined).
12 //===----------------------------------------------------------------------===//
13 #include "asan_internal.h"
15 #if ASAN_USE_PREINIT_ARRAY && !defined(PIC)
16 // On Linux, we force __asan_init to be called before anyone else
17 // by placing it into .preinit_array section.
18 // FIXME: do we have anything like this on Mac?
19 // The symbol is called __local_asan_preinit, because it's not intended to be
20 // exported.
21 __attribute__((section(".preinit_array"), used))
22 void (*__local_asan_preinit)(void) = __asan_init;
23 #elif SANITIZER_WINDOWS && defined(_DLL)
24 // On Windows, when using dynamic CRT (/MD), we can put a pointer
25 // to __asan_init into the global list of C initializers.
26 // See crt0dat.c in the CRT sources for the details.
27 #pragma section(".CRT$XIB", long, read) // NOLINT
28 __declspec(allocate(".CRT$XIB")) void (*__asan_preinit)() = __asan_init;
29 #endif