1 //===-- asan_globals_win.cc -----------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Global registration code that is linked into every Windows DLL and EXE.
12 //===----------------------------------------------------------------------===//
14 #include "asan_interface_internal.h"
19 #pragma section(".ASAN$GA", read, write) // NOLINT
20 #pragma section(".ASAN$GZ", read, write) // NOLINT
21 extern "C" __declspec(allocate(".ASAN$GA"))
22 ALIGNED(sizeof(__asan_global)) __asan_global __asan_globals_start = {};
23 extern "C" __declspec(allocate(".ASAN$GZ"))
24 ALIGNED(sizeof(__asan_global)) __asan_global __asan_globals_end = {};
25 #pragma comment(linker, "/merge:.ASAN=.data")
27 static void call_on_globals(void (*hook)(__asan_global *, uptr)) {
28 __asan_global *start = &__asan_globals_start + 1;
29 __asan_global *end = &__asan_globals_end;
30 uptr bytediff = (uptr)end - (uptr)start;
31 if (bytediff % sizeof(__asan_global) != 0) {
32 #ifdef SANITIZER_DLL_THUNK
35 CHECK("corrupt asan global array");
38 // We know end >= start because the linker sorts the portion after the dollar
39 // sign alphabetically.
44 static void register_dso_globals() {
45 call_on_globals(&__asan_register_globals);
48 static void unregister_dso_globals() {
49 call_on_globals(&__asan_unregister_globals);
53 #pragma section(".CRT$XCU", long, read) // NOLINT
54 #pragma section(".CRT$XTX", long, read) // NOLINT
55 extern "C" __declspec(allocate(".CRT$XCU"))
56 void (*const __asan_dso_reg_hook)() = ®ister_dso_globals;
57 extern "C" __declspec(allocate(".CRT$XTX"))
58 void (*const __asan_dso_unreg_hook)() = &unregister_dso_globals;
62 #endif // SANITIZER_WINDOWS