crt: Check for compiler support for `no_stack_protector` This commit contains two changes: 1. `no_stack_protector` is applied only when one of the `-fstack-protector*` options is in effect, for example, when someone builds the CRT with such an option in their `CFLAGS`. 2. When the attribute is required but is not supported by the compiler, it results in broken executables. Now in this case an error is triggered. Signed-off-by: LIU Hao <lh_mouse@126.com>
diff --git a/mingw-w64-crt/ssp/stack_chk_guard.c b/mingw-w64-crt/ssp/stack_chk_guard.c index 8f0ca85..6a4d862 100644 --- a/mingw-w64-crt/ssp/stack_chk_guard.c +++ b/mingw-w64-crt/ssp/stack_chk_guard.c
@@ -10,10 +10,18 @@ void *__stack_chk_guard; +#if defined __SSP__ || defined __SSP_STRONG__ || defined __SSP_ALL__ // This function requires `no_stack_protector` because it changes the // value of `__stack_chk_guard`, causing stack checks to fail before // returning from this function. -__attribute__((__constructor__, __no_stack_protector__)) +# if (defined __GNUC__ && __GNUC__ >= 11) || (defined __clang__ && __clang_major__ >= 7) +__attribute__((__no_stack_protector__)) +# else +# error This file can not be built with stack protector enabled. Remove \ + -fstack-protector* options from CFLAGS. +# endif +#endif +__attribute__((__constructor__)) static void __cdecl init(void) { unsigned int ui;