On Sunday 13 July 2025 21:35:23 LIU Hao wrote:
> 在 2025-7-13 21:25, Pali Rohár 写道:
> > And throws warning: ‘no_stack_protector’ attribute directive ignored
> > [-Wattributes]
> >
> >
> > If I understand correctly the code at 3d-4c is the stack protection
> > check, which should have been disabled for that function. But because
> > the ___stack_chk_guard is being changed in the function, it cause
> > calling the ___stack_chk_fail.
> >
> > So the warning is NOT harmless and cannot be ignored. It is a real issue.
>
> The CRT should not be built with stack protector.
Ok. But the attribute __no_stack_protector__ is there to allow building
CRT with -fstack-protector, no?
> Otherwise, even if we don't use the attribute there and don't see a warning,
> compiling the CRT with GCC 8 and with `-fstack-protector` will still cause
> crashes.
>
> One possible workaround is to introduce a specific Makefile recipe for
> 'stack_chk_guard.c' which doesn't use `CFLAGS`. However as said above, just
> don't build the CRT with stack protector.
I played with it a bit and seems that on gcc 8.3 it is possible to turn
stack protector per-function too via marking the function with:
__attribute__((__optimize__("no-stack-protector")))
which seems to be equivalent of flag -fno-stack-protector
Compiled code with -fstack-protector-all flag and above attribute is:
00000000 <_init>:
0: 83 3d 00 00 00 00 00 cmpl $0x0,0x0
2: dir32 ___stack_chk_guard-0x4
7: 75 2d jne 36 <_init+0x36>
9: 83 ec 2c sub $0x2c,%esp
c: 8d 44 24 1c lea 0x1c(%esp),%eax
10: 89 04 24 mov %eax,(%esp)
13: ff 15 00 00 00 00 call *0x0
15: dir32 __imp__rand_s
19: 85 c0 test %eax,%eax
1b: 75 0b jne 28 <_init+0x28>
1d: 8b 44 24 1c mov 0x1c(%esp),%eax
21: a3 00 00 00 00 mov %eax,0x0
22: dir32 ___stack_chk_guard-0x4
26: eb 0a jmp 32 <_init+0x32>
28: c7 05 00 00 00 00 ef movl $0xdeadbeef,0x0
2f: be ad de
2a: dir32 ___stack_chk_guard-0x4
32: 83 c4 2c add $0x2c,%esp
35: c3 ret
36: c3 ret
37: 90 nop
But it is different than without the -fstack-protector-all flag.
It is usable? If yes then I would propose to to define
__no_stack_protector__ as __optimize__("no-stack-protector") for those
older gcc.
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public