https://git.reactos.org/?p=reactos.git;a=commitdiff;h=658f742c2d70cc16844dc…
commit 658f742c2d70cc16844dcf4eeaddcb358dc755fc
Author: Victor Perevertkin <victor.perevertkin(a)reactos.org>
AuthorDate: Tue Oct 6 22:36:45 2020 +0300
Commit: Victor Perevertkin <victor.perevertkin(a)reactos.org>
CommitDate: Mon Nov 2 21:27:06 2020 +0300
[NDK][CMAKE] Introduce DATA_SEG and CODE_SEG macro
These are for putting code and data to non-default sections
At the same time, move INIT section attributes declaration to cmake files
---
hal/halx86/CMakeLists.txt | 2 +-
ntoskrnl/CMakeLists.txt | 2 +-
sdk/cmake/msvc.cmake | 4 ++--
sdk/include/ndk/section_attribs.h | 16 +++++-----------
4 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/hal/halx86/CMakeLists.txt b/hal/halx86/CMakeLists.txt
index c7f1bdaccb5..e56a791d8da 100644
--- a/hal/halx86/CMakeLists.txt
+++ b/hal/halx86/CMakeLists.txt
@@ -52,7 +52,7 @@ function(add_hal _halname)
set_module_type(${_halname} kerneldll ENTRYPOINT HalInitSystem 8)
add_cd_file(TARGET ${_halname} DESTINATION reactos/system32 NO_CAB FOR all)
if(MSVC)
- add_target_link_flags(${_halname} "/ignore:4216 /ignore:4078")
+ add_target_link_flags(${_halname} "/ignore:4216 /SECTION:INIT,ERWD")
else()
target_link_libraries(${_halname} -lgcc)
endif()
diff --git a/ntoskrnl/CMakeLists.txt b/ntoskrnl/CMakeLists.txt
index e1823f70019..13ca75e351a 100644
--- a/ntoskrnl/CMakeLists.txt
+++ b/ntoskrnl/CMakeLists.txt
@@ -36,7 +36,7 @@ set_subsystem(ntoskrnl native)
if(MSVC)
set_image_base(ntoskrnl 0x00400000)
add_target_link_flags(ntoskrnl "/SECTION:.rsrc,!DP") #Accessed from
bugcheck code
- add_target_link_flags(ntoskrnl "/SECTION:INIT,D")
+ add_target_link_flags(ntoskrnl "/SECTION:INIT,ERWD")
else()
if(GDB)
# Completely disable optimizations when debugging the kernel
diff --git a/sdk/cmake/msvc.cmake b/sdk/cmake/msvc.cmake
index d4aed60c361..a3048c34e1d 100644
--- a/sdk/cmake/msvc.cmake
+++ b/sdk/cmake/msvc.cmake
@@ -248,9 +248,9 @@ function(set_module_type_toolchain MODULE TYPE)
add_target_link_flags(${MODULE} "/DLL")
elseif(${TYPE} STREQUAL "kernelmodedriver")
# Disable linker warning 4078 (multiple sections found with different attributes)
for INIT section use
- add_target_link_flags(${MODULE} "/DRIVER /IGNORE:4078
/SECTION:INIT,D")
+ add_target_link_flags(${MODULE} "/DRIVER /SECTION:INIT,ERWD")
elseif(${TYPE} STREQUAL "wdmdriver")
- add_target_link_flags(${MODULE} "/DRIVER:WDM /IGNORE:4078
/SECTION:INIT,D")
+ add_target_link_flags(${MODULE} "/DRIVER:WDM /SECTION:INIT,ERWD")
endif()
if(RUNTIME_CHECKS)
diff --git a/sdk/include/ndk/section_attribs.h b/sdk/include/ndk/section_attribs.h
index 2d1007aac6a..4b2a6100f32 100644
--- a/sdk/include/ndk/section_attribs.h
+++ b/sdk/include/ndk/section_attribs.h
@@ -8,7 +8,7 @@ Header Name:
Abstract:
- Preprocessor definitions to put code and data into the INIT section.
+ Preprocessor definitions to put code and data into specific sections.
Author:
@@ -20,19 +20,13 @@ Author:
#if defined(__GNUC__) || defined(__clang__)
-#define INIT_SECTION __attribute__((section ("INIT")))
-#define INIT_FUNCTION __attribute__((section ("INIT")))
+#define DATA_SEG(segment) __attribute__((section(segment)))
+#define CODE_SEG(segment) __attribute__((section(segment)))
#elif defined(_MSC_VER)
-#pragma comment(linker, "/SECTION:INIT,ERW")
-#define INIT_SECTION __declspec(allocate("INIT"))
-#if (_MSC_VER >= 1800) // Visual Studio 2013 / version 12.0
-#define INIT_FUNCTION __declspec(code_seg("INIT"))
-#else
-#pragma section("INIT", read,execute,discard)
-#define INIT_FUNCTION
-#endif
+#define DATA_SEG(segment) __declspec(allocate(segment))
+#define CODE_SEG(segment) __declspec(code_seg(segment))
#else