[gcc r13-9085] x86: Disable stack protector for naked functions
H.J. Lu
hjl@gcc.gnu.org
Fri Oct 4 19:46:05 GMT 2024
https://gcc.gnu.org/g:bd9f62324853686c65e1b4331a187102e1e526b0
commit r13-9085-gbd9f62324853686c65e1b4331a187102e1e526b0
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Fri Oct 4 16:21:15 2024 +0800
x86: Disable stack protector for naked functions
Since naked functions should not enable stack protector, define
TARGET_STACK_PROTECT_RUNTIME_ENABLED_P to disable stack protector
for naked functions.
gcc/
PR target/116962
* config/i386/i386.cc (ix86_stack_protect_runtime_enabled_p): New
function.
(TARGET_STACK_PROTECT_RUNTIME_ENABLED_P): New.
gcc/testsuite/
PR target/116962
* gcc.target/i386/pr116962.c: New file.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
(cherry picked from commit 7d2845da112214f064e7b24531cc67e256b5177e)
Diff:
---
gcc/config/i386/i386.cc | 11 +++++++++++
gcc/testsuite/gcc.target/i386/pr116962.c | 10 ++++++++++
2 files changed, 21 insertions(+)
diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index f8bd772d74a4..1e43ae15d7bd 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -22983,6 +22983,13 @@ ix86_stack_protect_guard (void)
return default_stack_protect_guard ();
}
+static bool
+ix86_stack_protect_runtime_enabled_p (void)
+{
+ /* Naked functions should not enable stack protector. */
+ return !ix86_function_naked (current_function_decl);
+}
+
/* For 32-bit code we can save PIC register setup by using
__stack_chk_fail_local hidden function instead of calling
__stack_chk_fail directly. 64-bit code doesn't need to setup any PIC
@@ -25107,6 +25114,10 @@ ix86_libgcc_floating_mode_supported_p
#undef TARGET_STACK_PROTECT_GUARD
#define TARGET_STACK_PROTECT_GUARD ix86_stack_protect_guard
+#undef TARGET_STACK_PROTECT_RUNTIME_ENABLED_P
+#define TARGET_STACK_PROTECT_RUNTIME_ENABLED_P \
+ ix86_stack_protect_runtime_enabled_p
+
#if !TARGET_MACHO
#undef TARGET_STACK_PROTECT_FAIL
#define TARGET_STACK_PROTECT_FAIL ix86_stack_protect_fail
diff --git a/gcc/testsuite/gcc.target/i386/pr116962.c b/gcc/testsuite/gcc.target/i386/pr116962.c
new file mode 100644
index 000000000000..ced16eee746b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr116962.c
@@ -0,0 +1,10 @@
+/* { dg-do compile { target fstack_protector } } */
+/* { dg-options "-O2 -fstack-protector-all" } */
+/* { dg-final { scan-assembler-not "__stack_chk_fail" } } */
+
+__attribute__ ((naked))
+void
+foo (void)
+{
+ asm ("ret");
+}
More information about the Gcc-cvs
mailing list