[GCC/CMAKE]

- Add a way to conditionally use the GCC stack protector.
Just add -DSTACK_PROTECTOR:BOOL=TRUE as argument to configure.cmd/sh

svn path=/trunk/; revision=64527
This commit is contained in:
Jérôme Gardou 2014-10-04 20:26:14 +00:00
parent 4e9593f906
commit 87daca2bea
9 changed files with 61 additions and 0 deletions

View file

@ -210,6 +210,11 @@ endif()
target_link_libraries(freeldr_pe freeldr_common cportlib cmlib rtl libcntpr)
target_link_libraries(freeldr_pe_dbg freeldr_common cportlib cmlib rtl libcntpr)
if (STACK_PROTECTOR)
target_link_libraries(freeldr_pe gcc_ssp)
target_link_libraries(freeldr_pe_dbg gcc_ssp)
endif()
add_dependencies(freeldr_pe asm)
add_dependencies(freeldr_pe_dbg asm)
@ -266,6 +271,11 @@ endif()
target_link_libraries(setupldr_pe freeldr_common cportlib cmlib rtl libcntpr)
target_link_libraries(setupldr_pe_dbg freeldr_common cportlib cmlib rtl libcntpr)
if (STACK_PROTECTOR)
target_link_libraries(setupldr_pe gcc_ssp)
target_link_libraries(setupldr_pe_dbg gcc_ssp)
endif()
add_dependencies(setupldr_pe asm)
add_dependencies(setupldr_pe_dbg asm)

View file

@ -75,6 +75,9 @@ set(_PREFAST_ FALSE CACHE BOOL
"Whether to enable PREFAST while compiling.")
set(_VS_ANALYZE_ FALSE CACHE BOOL
"Whether to enable static analysis while compiling.")
else()
set(STACK_PROTECTOR FALSE CACHE BOOL
"Whether to enbable the GCC stack checker while compiling")
endif()
set(USE_DUMMY_PSEH FALSE CACHE BOOL

View file

@ -30,6 +30,10 @@ if(USE_DUMMY_PSEH)
add_definitions(-D_USE_DUMMY_PSEH=1)
endif()
if(STACK_PROTECTOR)
add_compile_flags(${MODULE} "-fstack-protector-all")
endif()
# Compiler Core
add_compile_flags("-pipe -fms-extensions -fno-strict-aliasing")
if(GCC_VERSION VERSION_GREATER 4.7)
@ -281,6 +285,10 @@ function(set_module_type_toolchain MODULE TYPE)
add_target_link_flags(${MODULE} "-Wl,--wdmdriver")
endif()
endif()
if(STACK_PROTECTOR)
target_link_libraries(${MODULE} gcc_ssp)
endif()
endfunction()
function(add_delay_importlibs _module)

View file

@ -13,6 +13,9 @@ add_subdirectory(drivers)
add_subdirectory(epsapi)
add_subdirectory(fast486)
add_subdirectory(fslib)
if (STACK_PROTECTOR)
add_subdirectory(gcc_ssp)
endif()
add_subdirectory(lsalib)
add_subdirectory(ppcmmu)
add_subdirectory(pseh)

View file

@ -0,0 +1,2 @@
add_library(gcc_ssp STATIC gcc_ssp.c)

View file

@ -0,0 +1,23 @@
#define FAST_FAIL_STACK_COOKIE_CHECK_FAILURE 2
/* Should be random :-/ */
void * __stack_chk_guard = (void*)0xf00df00d;
#if 0
void __stack_chk_guard_setup()
{
unsigned char * p;
p = (unsigned char *)&__stack_chk_guard; // *** Notice that this takes the address of __stack_chk_guard ***
/* If you have the ability to generate random numbers in your kernel then use them,
otherwise for 32-bit code: */
*p = 0x00000aff; // *** p is &__stack_chk_guard so *p writes to __stack_chk_guard rather than *__stack_chk_guard ***
}
#endif
void __stack_chk_fail()
{
/* Like __fastfail */
__asm__("int $0x29" : : "c"(FAST_FAIL_STACK_COOKIE_CHECK_FAILURE) : "memory");
}

View file

@ -85,4 +85,8 @@ if(NOT MSVC)
target_link_libraries(msvcrtex oldnames)
endif()
if(STACK_PROTECTOR)
target_link_libraries(msvcrtex gcc_ssp)
endif()
add_dependencies(msvcrtex psdk asm)

View file

@ -44,6 +44,10 @@ target_link_libraries(ntoskrnl
wdmguid
ioevent)
if(STACK_PROTECTOR)
target_link_libraries(ntoskrnl gcc_ssp)
endif()
add_importlibs(ntoskrnl hal kdcom bootvid)
add_pch(ntoskrnl ${REACTOS_SOURCE_DIR}/ntoskrnl/include/ntoskrnl.h NTOSKRNL_SOURCE)
add_dependencies(ntoskrnl psdk bugcodes asm)

View file

@ -30,6 +30,10 @@ else()
set_image_base(ntkrnlmp 0x80800000)
endif()
if(STACK_PROTECTOR)
target_link_libraries(ntkrnlmp gcc_ssp)
endif()
target_link_libraries(ntkrnlmp
cportlib
csq