diff options
author | Jeff Law <law@redhat.com> | 2018-01-24 14:57:16 -0700 |
---|---|---|
committer | Jeff Law <law@gcc.gnu.org> | 2018-01-24 14:57:16 -0700 |
commit | 5e77d9b130abdd5878557d34839e1b159a7f68ef (patch) | |
tree | 380dc091644ccc25405ff6216ba410ee0ebf7620 | |
parent | ffd464df03c608e008caeba1cab1c9eb276fd41e (diff) | |
download | gcc-5e77d9b130abdd5878557d34839e1b159a7f68ef.zip gcc-5e77d9b130abdd5878557d34839e1b159a7f68ef.tar.gz gcc-5e77d9b130abdd5878557d34839e1b159a7f68ef.tar.bz2 |
re PR target/83994 (%ebx is clobbered by stack-clash probing for regparm-3 function in PIC mode)
PR target/83994
* i386.c (get_probe_interval): Move to earlier point.
(ix86_compute_frame_layout): If -fstack-clash-protection and
the frame is larger than the probe interval, then use pushes
to save registers rather than reg->mem moves.
(ix86_expand_prologue): Remove conditional for int_registers_saved
assertion.
PR target/83994
* gcc.target/i386/pr83994.c: New test.
From-SVN: r257031
-rw-r--r-- | gcc/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/config/i386/i386.c | 44 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/i386/pr83994.c | 16 |
4 files changed, 56 insertions, 19 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c7b0d8e..9427ef8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2017-01-08 Jeff Law <law@redhat.com> + + PR target/83994 + * i386.c (get_probe_interval): Move to earlier point. + (ix86_compute_frame_layout): If -fstack-clash-protection and + the frame is larger than the probe interval, then use pushes + to save registers rather than reg->mem moves. + (ix86_expand_prologue): Remove conditional for int_registers_saved + assertion. + 2018-01-24 Vladimir Makarov <vmakarov@redhat.com> PR target/84014 diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 101fea6..cd68168 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -11497,6 +11497,18 @@ static void warn_once_call_ms2sysv_xlogues (const char *feature) } } +/* Return the probing interval for -fstack-clash-protection. */ + +static HOST_WIDE_INT +get_probe_interval (void) +{ + if (flag_stack_clash_protection) + return (HOST_WIDE_INT_1U + << PARAM_VALUE (PARAM_STACK_CLASH_PROTECTION_PROBE_INTERVAL)); + else + return (HOST_WIDE_INT_1U << STACK_CHECK_PROBE_INTERVAL_EXP); +} + /* When using -fsplit-stack, the allocation routines set a field in the TCB to the bottom of the stack plus this much space, measured in bytes. */ @@ -11773,7 +11785,14 @@ ix86_compute_frame_layout (void) to_allocate = offset - frame->sse_reg_save_offset; if ((!to_allocate && frame->nregs <= 1) - || (TARGET_64BIT && to_allocate >= HOST_WIDE_INT_C (0x80000000))) + || (TARGET_64BIT && to_allocate >= HOST_WIDE_INT_C (0x80000000)) + /* If stack clash probing needs a loop, then it needs a + scratch register. But the returned register is only guaranteed + to be safe to use after register saves are complete. So if + stack clash protections are enabled and the allocated frame is + larger than the probe interval, then use pushes to save + callee saved registers. */ + || (flag_stack_clash_protection && to_allocate > get_probe_interval ())) frame->save_regs_using_mov = false; if (ix86_using_red_zone () @@ -12567,18 +12586,6 @@ release_scratch_register_on_entry (struct scratch_reg *sr) } } -/* Return the probing interval for -fstack-clash-protection. */ - -static HOST_WIDE_INT -get_probe_interval (void) -{ - if (flag_stack_clash_protection) - return (HOST_WIDE_INT_1U - << PARAM_VALUE (PARAM_STACK_CLASH_PROTECTION_PROBE_INTERVAL)); - else - return (HOST_WIDE_INT_1U << STACK_CHECK_PROBE_INTERVAL_EXP); -} - /* Emit code to adjust the stack pointer by SIZE bytes while probing it. This differs from the next routine in that it tries hard to prevent @@ -13726,12 +13733,11 @@ ix86_expand_prologue (void) && (flag_stack_check == STATIC_BUILTIN_STACK_CHECK || flag_stack_clash_protection)) { - /* This assert wants to verify that integer registers were saved - prior to probing. This is necessary when probing may be implemented - as a function call (Windows). It is not necessary for stack clash - protection probing. */ - if (!flag_stack_clash_protection) - gcc_assert (int_registers_saved); + /* We expect the GP registers to be saved when probes are used + as the probing sequences might need a scratch register and + the routine to allocate one assumes the integer registers + have already been saved. */ + gcc_assert (int_registers_saved); if (flag_stack_clash_protection) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8f6d434..2c637fe 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-01-19 Jeff Law <law@redhat.com> + + PR target/83994 + * gcc.target/i386/pr83994.c: New test. + 2018-01-24 Vladimir Makarov <vmakarov@redhat.com> PR target/84014 diff --git a/gcc/testsuite/gcc.target/i386/pr83994.c b/gcc/testsuite/gcc.target/i386/pr83994.c new file mode 100644 index 0000000..dc0b7cb --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr83994.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=i686 -fpic -fstack-clash-protection" } */ +/* { dg-require-effective-target ia32 } */ + +void f1 (char *); + +__attribute__ ((regparm (3))) +int +f2 (int arg1, int arg2, int arg3) +{ + char buf[16384]; + f1 (buf); + f1 (buf); + return 0; +} + |