diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2025-02-01 18:06:33 +0800 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2025-02-01 18:33:37 +0800 |
commit | b38efaf36058b40aaf8659a9348815110242ced8 (patch) | |
tree | be41df66944d48af44e3513c8426e019c4cc4037 /gcc | |
parent | d3ba88308426b3db55793831b0ae8c760aad9de7 (diff) | |
download | gcc-b38efaf36058b40aaf8659a9348815110242ced8.zip gcc-b38efaf36058b40aaf8659a9348815110242ced8.tar.gz gcc-b38efaf36058b40aaf8659a9348815110242ced8.tar.bz2 |
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>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/gcc.target/i386/ssp-global.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.target/i386/ssp-global.c b/gcc/testsuite/gcc.target/i386/ssp-global.c new file mode 100644 index 0000000..85a288c --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/ssp-global.c @@ -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; +} |