1 /* { dg-do run } */
2 /* { dg-require-effective-target fstack_protector } */
3 /* { dg-options "-fstack-protector-all -O2" } */
4
5 extern volatile long *stack_chk_guard_ptr;
6
7 void __attribute__ ((noipa))
8 f (void)
9 {
10 volatile int x;
11 /* Munging the contents of __stack_chk_guard should trigger a
12 stack-smashing failure for this function. */
13 *stack_chk_guard_ptr += 1;
14 }
15
16 #define CHECK(REG) "\tcmp\tx0, " #REG "\n\tbeq\t1f\n"
17
18 asm (
19 " .pushsection .data\n"
20 " .align 3\n"
21 "stack_chk_guard_ptr:\n"
22 #if __ILP32__
23 " .word __stack_chk_guard\n"
24 #else
25 " .xword __stack_chk_guard\n"
26 #endif
27 " .weak __stack_chk_guard\n"
28 "__stack_chk_guard:\n"
29 " .word 0xdead4321\n"
30 " .word 0xbeef8765\n"
31 " .text\n"
32 " .type __stack_chk_fail, %function\n"
33 "__stack_chk_fail:\n"
34 " mov x0, #0\n"
35 " b exit\n"
36 " .size __stack_chk_fail, .-__stack_chk_fail\n"
37 " .popsection"
38 );
39
40 int
41 main (void)
42 {
43 f ();
44 __builtin_abort ();
45 }