[Bug target/86832] [8/9 Regression] GCC v8.2.0 tries to use native TLS with -fstack-protector-strong on Windows (mingw-w64)
jakub at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Nov 21 17:36:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86832
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |uros at gcc dot gnu.org
--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I believe this is caused by the PR81708 changes.
While i386 defaulted to SSP_TLS rather than SSP_GLOBAL on everything but
Android,
the -mstack-protector-guard= switch controlled pretty much whether the i386.md
special stack protector patterns are used (if tls) or whether generic code is
used (global). These special stack protector patterns did one thing if
TARGET_THREAD_SSP_OFFSET macro was defined (only defined on glibc targets) -
code like:
movq %fs:40, %rax
movq %rax, -8(%rbp)
xorl %eax, %eax
in the prologue and
movq -8(%rbp), %rdx
xorq %fs:40, %rdx
je .L4
in the epilogue. If TARGET_THREAD_SSP_OFFSET macro wasn't defined, it would do
instead:
movq .refptr.__stack_chk_guard(%rip), %rax
movq (%rax), %rcx
movq %rcx, -8(%rbp)
xorl %ecx, %ecx
and
movq .refptr.__stack_chk_guard(%rip), %rdx
movq -8(%rbp), %rcx
xorq (%rdx), %rcx
je .L4
(this is taken from 7.x cross to mingw).
Finally, for Android or when -mstack-protector-guard=global was used, it
emitted:
movq __stack_chk_guard(%rip), %rax
movq %rax, -8(%rbp)
and
movq __stack_chk_guard(%rip), %rdx
cmpq %rdx, %rcx
je .L4
Note, apart from OS specific details, those =global sequences are similar to
the =tls ones when TARGET_THREAD_SSP_OFFSET is not defined, the main difference
is that the =tls ones are more secure as they clear registers containing the
guard as quickly as possible. The PR81708 changes dropped the non-tls special
stack_protector_* patterns from i386.md and now =tls implies really tls, but
the default remained, so mingw32 or darwin still default to tls and just use 0
offset by default.
So, this patch changes the default for mingw32, darwin and everything else
except gnu-user*.h to be =global, and just forces those special i386.md more
secure patterns unconditionally (slightly changing the generated code on
Android, but it is one extra insn in prologue and one fewer in the epilogue).
More information about the Gcc-bugs
mailing list