Delete file meant for private branch
[official-gcc.git] / libsanitizer / asan / asan_globals_win.cpp
blob19af88ab12b40ab2dbe6b572a3119b79711cb2e6
1 //===-- asan_globals_win.cpp ----------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Global registration code that is linked into every Windows DLL and EXE.
11 //===----------------------------------------------------------------------===//
13 #include "asan_interface_internal.h"
14 #if SANITIZER_WINDOWS
16 namespace __asan {
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)
32 __debugbreak();
33 #else
34 CHECK("corrupt asan global array");
35 #endif
37 // We know end >= start because the linker sorts the portion after the dollar
38 // sign alphabetically.
39 uptr n = end - start;
40 hook(start, n);
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);
51 // Register 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)() = &register_dso_globals;
56 extern "C" __declspec(allocate(".CRT$XTX"))
57 void (*const __asan_dso_unreg_hook)() = &unregister_dso_globals;
59 } // namespace __asan
61 #endif // SANITIZER_WINDOWS