On Monday 14 July 2025 10:46:36 LIU Hao wrote:
> 在 2025-7-13 23:02, Pali Rohár 写道:
> > I see. But I think it is better to apply at least this "debugging
> > purposes" attribute than nothing. It is only for older gcc versions.
> > And with __SSP__ checks it can be targeted just for
> > -fstack-protector-string CRT builds, which is what the original commit
> > is aiming.
> > 
> > What about something like this in the stack_chk_guard.c file?
> > 
> > #if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 11
> >    #if (defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__))
> >      #define __no_stack_protector__ __optimize__("no-stack-protector")
> >    #else
> >      #define __no_stack_protector__
> >    #endif
> > #endif
> 
> I'd rather that we don't abuse the `optimize` attribute. Clang also doesn't
> support it, so there's no workaround for Clang 7-.
> 
> It should be an error if SSP is enabled when compiling this file:
> 
> 
> diff --git a/mingw-w64-crt/ssp/stack_chk_guard.c 
> b/mingw-w64-crt/ssp/stack_chk_guard.c
> index be43d8c7e..6a728d712 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't be built with stack protector enabled. Remove \
> +         -fstack-protector* options from CFLAGS.
> +# endif
> +#endif
> +__attribute__((__constructor__))
>  static void __cdecl init(void)
>  {
>    unsigned int ui;
> 

Ok, that is also a solution.


_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to