x86: Add a -mstack-protector-guard=global test
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_gcc_build--master-arm |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_gcc_check--master-arm |
success
|
Test passed
|
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 |
success
|
Test passed
|
Commit Message
Verify that -mstack-protector-guard=global works on x86. Default stack
protector uses TLS. -mstack-protector-guard=global uses a global variable,
__stack_chk_guard, instead of TLS.
* gcc.target/i386/ssp-global.c: New file.
Comments
On Sat, Feb 1, 2025 at 11:14 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> Verify that -mstack-protector-guard=global works on x86. Default stack
> protector uses TLS. -mstack-protector-guard=global uses a global variable,
> __stack_chk_guard, instead of TLS.
>
> * gcc.target/i386/ssp-global.c: New file.
OK.
Thanks,
Uros.
>
>
> --
> H.J.
From 520d249938561639ec5c99f36947fd6795a9f2ed Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Sat, 1 Feb 2025 18:06:33 +0800
Subject: [PATCH] x86: Add a -mstack-protector-guard=global test
Verify that -mstack-protector-guard=global works on x86. Default stack
protector uses TLS. -mstack-protector-guard=global uses a global variable,
__stack_chk_guard, instead of TLS.
* gcc.target/i386/ssp-global.c: New file.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
gcc/testsuite/gcc.target/i386/ssp-global.c | 35 ++++++++++++++++++++++
1 file changed, 35 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/i386/ssp-global.c
new file mode 100644
@@ -0,0 +1,35 @@
+/* { dg-do run { target fstack_protector } } */
+/* { dg-options "-O2 -fstack-protector-all -mstack-protector-guard=global" } */
+
+#include <stdlib.h>
+
+#ifdef __LP64__
+const unsigned long int __stack_chk_guard = 0x2d853605a4d9a09cUL;
+#else
+const unsigned long int __stack_chk_guard = 0xdd2cc927UL;
+#endif
+
+void
+__stack_chk_fail (void)
+{
+ exit (0); /* pass */
+}
+
+__attribute__ ((noipa))
+void
+smash (char *p, int i)
+{
+ p[i] = 42;
+}
+
+int
+main (void)
+{
+ char foo[255];
+
+ /* smash stack */
+ for (int i = 0; i <= 400; i++)
+ smash (foo, i);
+
+ return 1;
+}
--
2.48.1