[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 (!).
This commit is contained in:
Thomas Faber 2019-06-29 19:24:28 +02:00
parent c17a8770a3
commit c4d8e2a6e9
No known key found for this signature in database
GPG Key ID: 076E7C3D44720826
4 changed files with 16 additions and 2 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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;

View File

@ -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)