Author: jgardou Date: Sat Oct 4 20:26:14 2014 New Revision: 64527
URL: http://svn.reactos.org/svn/reactos?rev=64527&view=rev Log: [GCC/CMAKE] - Add a way to conditionally use the GCC stack protector. Just add -DSTACK_PROTECTOR:BOOL=TRUE as argument to configure.cmd/sh
Added: trunk/reactos/lib/gcc_ssp/ trunk/reactos/lib/gcc_ssp/CMakeLists.txt (with props) trunk/reactos/lib/gcc_ssp/gcc_ssp.c (with props) Modified: trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt trunk/reactos/cmake/config.cmake trunk/reactos/cmake/gcc.cmake trunk/reactos/lib/CMakeLists.txt trunk/reactos/lib/sdk/crt/msvcrtex.cmake trunk/reactos/ntoskrnl/CMakeLists.txt trunk/reactos/ntoskrnl/ntkrnlmp/CMakeLists.txt
Modified: trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/CMakeL... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt [iso-8859-1] Sat Oct 4 20:26:14 2014 @@ -210,6 +210,11 @@ 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 @@ 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)
Modified: trunk/reactos/cmake/config.cmake URL: http://svn.reactos.org/svn/reactos/trunk/reactos/cmake/config.cmake?rev=6452... ============================================================================== --- trunk/reactos/cmake/config.cmake [iso-8859-1] (original) +++ trunk/reactos/cmake/config.cmake [iso-8859-1] Sat Oct 4 20:26:14 2014 @@ -75,6 +75,9 @@ "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
Modified: trunk/reactos/cmake/gcc.cmake URL: http://svn.reactos.org/svn/reactos/trunk/reactos/cmake/gcc.cmake?rev=64527&a... ============================================================================== --- trunk/reactos/cmake/gcc.cmake [iso-8859-1] (original) +++ trunk/reactos/cmake/gcc.cmake [iso-8859-1] Sat Oct 4 20:26:14 2014 @@ -28,6 +28,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 @@ -281,6 +285,10 @@ 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)
Modified: trunk/reactos/lib/CMakeLists.txt URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/CMakeLists.txt?rev=6452... ============================================================================== --- trunk/reactos/lib/CMakeLists.txt [iso-8859-1] (original) +++ trunk/reactos/lib/CMakeLists.txt [iso-8859-1] Sat Oct 4 20:26:14 2014 @@ -13,6 +13,9 @@ 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)
Added: trunk/reactos/lib/gcc_ssp/CMakeLists.txt URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/gcc_ssp/CMakeLists.txt?... ============================================================================== --- trunk/reactos/lib/gcc_ssp/CMakeLists.txt (added) +++ trunk/reactos/lib/gcc_ssp/CMakeLists.txt [iso-8859-1] Sat Oct 4 20:26:14 2014 @@ -0,0 +1,2 @@ + +add_library(gcc_ssp STATIC gcc_ssp.c)
Propchange: trunk/reactos/lib/gcc_ssp/CMakeLists.txt ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/reactos/lib/gcc_ssp/gcc_ssp.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/gcc_ssp/gcc_ssp.c?rev=6... ============================================================================== --- trunk/reactos/lib/gcc_ssp/gcc_ssp.c (added) +++ trunk/reactos/lib/gcc_ssp/gcc_ssp.c [iso-8859-1] Sat Oct 4 20:26:14 2014 @@ -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"); +}
Propchange: trunk/reactos/lib/gcc_ssp/gcc_ssp.c ------------------------------------------------------------------------------ charset = UTF-8
Propchange: trunk/reactos/lib/gcc_ssp/gcc_ssp.c ------------------------------------------------------------------------------ svn:eol-style = native
Propchange: trunk/reactos/lib/gcc_ssp/gcc_ssp.c ------------------------------------------------------------------------------ svn:mime-type = text/plain
Modified: trunk/reactos/lib/sdk/crt/msvcrtex.cmake URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/msvcrtex.cmake?... ============================================================================== --- trunk/reactos/lib/sdk/crt/msvcrtex.cmake [iso-8859-1] (original) +++ trunk/reactos/lib/sdk/crt/msvcrtex.cmake [iso-8859-1] Sat Oct 4 20:26:14 2014 @@ -85,4 +85,8 @@ target_link_libraries(msvcrtex oldnames) endif()
+if(STACK_PROTECTOR) + target_link_libraries(msvcrtex gcc_ssp) +endif() + add_dependencies(msvcrtex psdk asm)
Modified: trunk/reactos/ntoskrnl/CMakeLists.txt URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/CMakeLists.txt?rev... ============================================================================== --- trunk/reactos/ntoskrnl/CMakeLists.txt [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/CMakeLists.txt [iso-8859-1] Sat Oct 4 20:26:14 2014 @@ -44,6 +44,10 @@ 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)
Modified: trunk/reactos/ntoskrnl/ntkrnlmp/CMakeLists.txt URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ntkrnlmp/CMakeList... ============================================================================== --- trunk/reactos/ntoskrnl/ntkrnlmp/CMakeLists.txt [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/ntkrnlmp/CMakeLists.txt [iso-8859-1] Sat Oct 4 20:26:14 2014 @@ -30,6 +30,10 @@ set_image_base(ntkrnlmp 0x80800000) endif()
+if(STACK_PROTECTOR) + target_link_libraries(ntkrnlmp gcc_ssp) +endif() + target_link_libraries(ntkrnlmp cportlib csq