https://git.reactos.org/?p=reactos.git;a=commitdiff;h=c4d8e2a6e9660c1f0d0d24877219baca443bbce0

commit c4d8e2a6e9660c1f0d0d24877219baca443bbce0
Author:     Thomas Faber <[email protected]>
AuthorDate: Sat Jun 29 19:24:28 2019 +0200
Commit:     Thomas Faber <[email protected]>
CommitDate: Sun Jul 7 08:18:10 2019 +0200

    [CMAKE] Ensure the INIT section is placed at the end of a module. CORE-14683
    
    For MSVC, marking the section as discardable will do this automatically.
    For GCC, we use a linker script that places it after the .reloc section
    (which should be the last "real" section, check ld --verbose output for the
    default linker script).
    
    This fixes what seems to be a regression from r55835 (!).
---
 ntoskrnl/CMakeLists.txt    |  2 ++
 sdk/cmake/gcc.cmake        |  1 +
 sdk/cmake/init-section.lds | 11 +++++++++++
 sdk/cmake/msvc.cmake       |  4 ++--
 4 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/ntoskrnl/CMakeLists.txt b/ntoskrnl/CMakeLists.txt
index 3111893fb05..5f2ac879316 100644
--- a/ntoskrnl/CMakeLists.txt
+++ b/ntoskrnl/CMakeLists.txt
@@ -31,12 +31,14 @@ 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")
 else()
     if(GDB)
         set_image_base(ntoskrnl 0x00800000)
     else()
         set_image_base(ntoskrnl 0x80800000)
     endif()
+    add_linker_script(ntoskrnl 
${REACTOS_SOURCE_DIR}/sdk/cmake/init-section.lds)
 endif()
 
 target_link_libraries(ntoskrnl cportlib csq ${PSEH_LIB} cmlib ntlsalib rtl 
${ROSSYM_LIB} libcntpr wdmguid ioevent)
diff --git a/sdk/cmake/gcc.cmake b/sdk/cmake/gcc.cmake
index f5c1ec10c69..c4c741ff6a6 100644
--- a/sdk/cmake/gcc.cmake
+++ b/sdk/cmake/gcc.cmake
@@ -318,6 +318,7 @@ function(set_module_type_toolchain MODULE TYPE)
         if(${TYPE} STREQUAL "wdmdriver")
             add_target_link_flags(${MODULE} "-Wl,--wdmdriver")
         endif()
+        add_linker_script(${MODULE} 
${REACTOS_SOURCE_DIR}/sdk/cmake/init-section.lds)
     endif()
     
     if(STACK_PROTECTOR)
diff --git a/sdk/cmake/init-section.lds b/sdk/cmake/init-section.lds
new file mode 100644
index 00000000000..2b815150105
--- /dev/null
+++ b/sdk/cmake/init-section.lds
@@ -0,0 +1,11 @@
+/* Make sure the INIT section is at the end of the module so we can reclaim 
the space */
+SECTIONS
+{
+  INIT BLOCK(__section_alignment__) :
+  {
+    __init_start__ = . ;
+    *(INIT)
+    __init_end__ = . ;
+  }
+}
+INSERT AFTER .reloc;
diff --git a/sdk/cmake/msvc.cmake b/sdk/cmake/msvc.cmake
index f7dc1544cee..44b72771af0 100644
--- a/sdk/cmake/msvc.cmake
+++ b/sdk/cmake/msvc.cmake
@@ -327,9 +327,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")
+        add_target_link_flags(${MODULE} "/DRIVER /IGNORE:4078 /SECTION:INIT,D")
     elseif(${TYPE} STREQUAL "wdmdriver")
-        add_target_link_flags(${MODULE} "/DRIVER:WDM /IGNORE:4078")
+        add_target_link_flags(${MODULE} "/DRIVER:WDM /IGNORE:4078 
/SECTION:INIT,D")
     endif()
 
     if(RUNTIME_CHECKS)

Reply via email to