https://git.reactos.org/?p=reactos.git;a=commitdiff;h=9c887efa0e90bcc5a516e…
commit 9c887efa0e90bcc5a516ebea902366398708e65f
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Mon Dec 2 14:00:35 2024 +0200
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Sun Jan 26 18:08:55 2025 +0200
[UCRT:VCRUNTIME] Add initializer sections
Use #pragma section only for MSVC (and Clang-cl), because Clang doesn't like
allocating non-const variables in a read-only section, while GCC doesn't understand
these pragmas and ignores them.
---
sdk/lib/ucrt/inc/internal_shared.h | 2 ++
sdk/lib/ucrt/vcruntime/initializers.cpp | 22 ++++++++++++++++++++++
sdk/lib/ucrt/vcruntime/vcruntime.cmake | 1 +
3 files changed, 25 insertions(+)
diff --git a/sdk/lib/ucrt/inc/internal_shared.h b/sdk/lib/ucrt/inc/internal_shared.h
index a0f1a5a841e..340407bed96 100644
--- a/sdk/lib/ucrt/inc/internal_shared.h
+++ b/sdk/lib/ucrt/inc/internal_shared.h
@@ -27,6 +27,7 @@ extern "C" {
#define _CRTALLOC(x) __attribute__((section(x)))
#endif
+#ifdef _MSC_VER
#pragma section(".CRT$XIC", long, read)
#pragma section(".CRT$XPX", long, read)
#pragma section(".CRT$XPXA", long, read)
@@ -39,6 +40,7 @@ extern "C" {
#pragma section(".CRT$XPZ", long, read)
#pragma section(".CRT$XTA", long, read)
#pragma section(".CRT$XTZ", long, read)
+#endif
extern _PIFV __xi_a[];
extern _PIFV __xi_z[];
diff --git a/sdk/lib/ucrt/vcruntime/initializers.cpp
b/sdk/lib/ucrt/vcruntime/initializers.cpp
new file mode 100644
index 00000000000..f93e918bdc7
--- /dev/null
+++ b/sdk/lib/ucrt/vcruntime/initializers.cpp
@@ -0,0 +1,22 @@
+//
+// section_markers.c
+//
+// Copyright (c) 2024 Timo Kreuzer
+//
+// Markers for CRT initializer sections.
+//
+// SPDX-License-Identifier: MIT
+//
+
+#include <internal_shared.h>
+
+_CRTALLOC(".CRT$XIA") _PIFV __xi_a[] = { 0 };
+_CRTALLOC(".CRT$XIZ") _PIFV __xi_z[] = { 0 };
+_CRTALLOC(".CRT$XCA") _PVFV __xc_a[] = { 0 };
+_CRTALLOC(".CRT$XCZ") _PVFV __xc_z[] = { 0 };
+_CRTALLOC(".CRT$XPA") _PVFV __xp_a[] = { 0 };
+_CRTALLOC(".CRT$XPZ") _PVFV __xp_z[] = { 0 };
+_CRTALLOC(".CRT$XTA") _PVFV __xt_a[] = { 0 };
+_CRTALLOC(".CRT$XTZ") _PVFV __xt_z[] = { 0 };
+
+#pragma comment(linker, "/merge:.CRT=.rdata")
diff --git a/sdk/lib/ucrt/vcruntime/vcruntime.cmake
b/sdk/lib/ucrt/vcruntime/vcruntime.cmake
index feb4a44d66d..2c3ab680910 100644
--- a/sdk/lib/ucrt/vcruntime/vcruntime.cmake
+++ b/sdk/lib/ucrt/vcruntime/vcruntime.cmake
@@ -4,6 +4,7 @@ list(APPEND UCRT_VCRUNTIME_SOURCES
vcruntime/__report_rangecheckfailure.c
vcruntime/__security_init_cookie.c
vcruntime/__vcrt_init.c
+ vcruntime/initializers.cpp
)
if(${ARCH} STREQUAL "i386")