| 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 |
asm ( |
| 17 |
" .data\n" |
| 18 |
" .align 3\n" |
| 19 |
" .globl stack_chk_guard_ptr\n" |
| 20 |
"stack_chk_guard_ptr:\n" |
| 21 |
" .word __stack_chk_guard\n" |
| 22 |
" .weak __stack_chk_guard\n" |
| 23 |
"__stack_chk_guard:\n" |
| 24 |
" .word 0xdead4321\n" |
| 25 |
" .text\n" |
| 26 |
" .type __stack_chk_fail, %function\n" |
| 27 |
"__stack_chk_fail:\n" |
| 28 |
" movs r0, #0\n" |
| 29 |
" bl exit\n" |
| 30 |
" .size __stack_chk_fail, .-__stack_chk_fail" |
| 31 |
); |
| 32 |
|
| 33 |
int |
| 34 |
main (void) |
| 35 |
{ |
| 36 |
f (); |
| 37 |
__builtin_abort (); |
| 38 |
} |