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