1 //===-- asan_globals_win.cpp ----------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Global registration code that is linked into every Windows DLL and EXE.
11 //===----------------------------------------------------------------------===//
13 #include "asan_interface_internal.h"
18 #pragma section(".ASAN$GA", read, write)
19 #pragma section(".ASAN$GZ", read, write)
20 extern "C" __declspec(allocate(".ASAN$GA"))
21 ALIGNED(sizeof(__asan_global
)) __asan_global __asan_globals_start
= {};
22 extern "C" __declspec(allocate(".ASAN$GZ"))
23 ALIGNED(sizeof(__asan_global
)) __asan_global __asan_globals_end
= {};
24 #pragma comment(linker, "/merge:.ASAN=.data")
26 static void call_on_globals(void (*hook
)(__asan_global
*, uptr
)) {
27 __asan_global
*start
= &__asan_globals_start
+ 1;
28 __asan_global
*end
= &__asan_globals_end
;
29 uptr bytediff
= (uptr
)end
- (uptr
)start
;
30 if (bytediff
% sizeof(__asan_global
) != 0) {
31 #if defined(SANITIZER_DLL_THUNK) || defined(SANITIZER_DYNAMIC_RUNTIME_THUNK)
34 CHECK("corrupt asan global array");
37 // We know end >= start because the linker sorts the portion after the dollar
38 // sign alphabetically.
43 static void register_dso_globals() {
44 call_on_globals(&__asan_register_globals
);
47 static void unregister_dso_globals() {
48 call_on_globals(&__asan_unregister_globals
);
52 #pragma section(".CRT$XCU", long, read)
53 #pragma section(".CRT$XTX", long, read)
54 extern "C" __declspec(allocate(".CRT$XCU"))
55 void (*const __asan_dso_reg_hook
)() = ®ister_dso_globals
;
56 extern "C" __declspec(allocate(".CRT$XTX"))
57 void (*const __asan_dso_unreg_hook
)() = &unregister_dso_globals
;
61 #endif // SANITIZER_WINDOWS