From: Andreas Krebbel Date: Thu, 14 May 2020 06:16:27 +0000 (+0200) Subject: Make anti_adjust_stack_and_probe_stack_clash extern and use it for Z X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d3e5bae174d9d2ed115a364d5b404d179458a622;p=gcc.git Make anti_adjust_stack_and_probe_stack_clash extern and use it for Z When compiling with -mbackchain -fstack-clash-protection currently no probes are emitted. This patch adjusts the "allocate_stack" expander to call anti_adjust_stack_and_probe_stack_clash when needed. In order to do this I had to export that function from explow.c. Ok for mainline? gcc/ChangeLog: 2020-05-14 Andreas Krebbel * config/s390/s390.md ("allocate_stack"): Call anti_adjust_stack_and_probe_stack_clash when stack clash protection is enabled. * explow.c (anti_adjust_stack_and_probe_stack_clash): Remove prototype. Remove static. * explow.h (anti_adjust_stack_and_probe_stack_clash): Add prototype. gcc/testsuite/ChangeLog: 2020-05-14 Andreas Krebbel * gcc.target/s390/stack-clash-3.c: New test. --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c1ee99eb0df..0b326ee09e8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2020-05-14 Andreas Krebbel + + * config/s390/s390.md ("allocate_stack"): Call + anti_adjust_stack_and_probe_stack_clash when stack clash + protection is enabled. + * explow.c (anti_adjust_stack_and_probe_stack_clash): Remove + prototype. Remove static. + * explow.h (anti_adjust_stack_and_probe_stack_clash): Add + prototype. + 2020-05-13 Kelvin Nilsen * config/rs6000/altivec.h (vec_extractl): New #define. diff --git a/gcc/config/s390/s390.md b/gcc/config/s390/s390.md index cf53ef1b791..908de587e17 100644 --- a/gcc/config/s390/s390.md +++ b/gcc/config/s390/s390.md @@ -11007,7 +11007,12 @@ rtx temp = gen_reg_rtx (Pmode); emit_move_insn (temp, s390_back_chain_rtx ()); - anti_adjust_stack (operands[1]); + + if (flag_stack_clash_protection) + anti_adjust_stack_and_probe_stack_clash (operands[1]); + else + anti_adjust_stack (operands[1]); + emit_move_insn (s390_back_chain_rtx (), temp); emit_move_insn (operands[0], virtual_stack_dynamic_rtx); diff --git a/gcc/explow.c b/gcc/explow.c index b838f035870..15c9cfb0318 100644 --- a/gcc/explow.c +++ b/gcc/explow.c @@ -43,7 +43,6 @@ along with GCC; see the file COPYING3. If not see #include "output.h" static rtx break_out_memory_refs (rtx); -static void anti_adjust_stack_and_probe_stack_clash (rtx); /* Truncate and perhaps sign-extend C as appropriate for MODE. */ @@ -1948,7 +1947,7 @@ emit_stack_clash_protection_probe_loop_end (rtx loop_lab, rtx end_loop, allocate/probe beyond that because this probing style does not guarantee signal handling capability if the guard is hit. */ -static void +void anti_adjust_stack_and_probe_stack_clash (rtx size) { /* First ensure SIZE is Pmode. */ diff --git a/gcc/explow.h b/gcc/explow.h index cc44bf8520a..0df8c62b82a 100644 --- a/gcc/explow.h +++ b/gcc/explow.h @@ -69,6 +69,10 @@ extern void anti_adjust_stack (rtx); /* Add some bytes to the stack while probing it. An rtx says how many. */ extern void anti_adjust_stack_and_probe (rtx, bool); +/* Add some bytes to the stack while probing it. An rtx says how + many. Add additional probes to prevent stack clashing attacks. */ +extern void anti_adjust_stack_and_probe_stack_clash (rtx); + /* Support for building allocation/probing loops for stack-clash protection of dyamically allocated stack space. */ extern void compute_stack_clash_protection_loop_data (rtx *, rtx *, rtx *, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 916bc2d40c8..bb3e4c86adc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2020-05-14 Andreas Krebbel + + * gcc.target/s390/stack-clash-3.c: New test. + 2020-05-13 Kelvin Nilsen * gcc.target/powerpc/vec-extracth-0.c: New. diff --git a/gcc/testsuite/gcc.target/s390/stack-clash-3.c b/gcc/testsuite/gcc.target/s390/stack-clash-3.c new file mode 100644 index 00000000000..929d3fbb365 --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/stack-clash-3.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=z900 -fstack-clash-protection -mbackchain" } */ + +extern void bar (char *); + +void +foo () +{ + char * mem = __builtin_alloca (20000); + bar (mem); +} + +/* For alloca a common code routine emits the probes. Make sure the + "probe_stack" expander is used in that case. We want to use mem + compares instead of stores. */ +/* { dg-final { scan-assembler-times "cg\t" 5 { target lp64 } } } */ +/* { dg-final { scan-assembler-times "c\t" 5 { target { ! lp64 } } } } */