|
|
802f23 |
commit 33839c8f8aa7857cc5f22ddb3f0960999cb0dfc7
|
|
|
802f23 |
Author: law <law@138bc75d-0d04-0410-961f-82ee72b054a4>
|
|
|
802f23 |
Date: Wed Jan 31 05:02:30 2018 +0000
|
|
|
802f23 |
|
|
|
802f23 |
PR target/84064
|
|
|
802f23 |
* i386.c (ix86_adjust_stack_and_probe_stack_clash): New argument
|
|
|
802f23 |
INT_REGISTERS_SAVED. Check it prior to calling
|
|
|
802f23 |
get_scratch_register_on_entry.
|
|
|
802f23 |
(ix86_adjust_stack_and_probe): Similarly.
|
|
|
802f23 |
(ix86_emit_probe_stack_range): Similarly.
|
|
|
802f23 |
(ix86_expand_prologue): Corresponding changes.
|
|
|
802f23 |
|
|
|
802f23 |
PR target/84064
|
|
|
802f23 |
* gcc.target/i386/pr84064: New test.
|
|
|
802f23 |
|
|
|
802f23 |
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
|
|
|
802f23 |
index 5230227..2fe2a0c 100644
|
|
|
802f23 |
--- a/gcc/config/i386/i386.c
|
|
|
802f23 |
+++ b/gcc/config/i386/i386.c
|
|
|
802f23 |
@@ -10206,10 +10206,14 @@ release_scratch_register_on_entry (struct scratch_reg *sr)
|
|
|
802f23 |
This differs from the next routine in that it tries hard to prevent
|
|
|
802f23 |
attacks that jump the stack guard. Thus it is never allowed to allocate
|
|
|
802f23 |
more than PROBE_INTERVAL bytes of stack space without a suitable
|
|
|
802f23 |
- probe. */
|
|
|
802f23 |
+ probe.
|
|
|
802f23 |
+
|
|
|
802f23 |
+ INT_REGISTERS_SAVED is true if integer registers have already been
|
|
|
802f23 |
+ pushed on the stack. */
|
|
|
802f23 |
|
|
|
802f23 |
static void
|
|
|
802f23 |
-ix86_adjust_stack_and_probe_stack_clash (const HOST_WIDE_INT size)
|
|
|
802f23 |
+ix86_adjust_stack_and_probe_stack_clash (const HOST_WIDE_INT size,
|
|
|
802f23 |
+ const bool int_registers_saved)
|
|
|
802f23 |
{
|
|
|
802f23 |
struct machine_function *m = cfun->machine;
|
|
|
802f23 |
struct ix86_frame frame;
|
|
|
802f23 |
@@ -10318,6 +10322,12 @@ ix86_adjust_stack_and_probe_stack_clash (const HOST_WIDE_INT size)
|
|
|
802f23 |
}
|
|
|
802f23 |
else
|
|
|
802f23 |
{
|
|
|
802f23 |
+ /* We expect the GP registers to be saved when probes are used
|
|
|
802f23 |
+ as the probing sequences might need a scratch register and
|
|
|
802f23 |
+ the routine to allocate one assumes the integer registers
|
|
|
802f23 |
+ have already been saved. */
|
|
|
802f23 |
+ gcc_assert (int_registers_saved);
|
|
|
802f23 |
+
|
|
|
802f23 |
struct scratch_reg sr;
|
|
|
802f23 |
get_scratch_register_on_entry (&sr);
|
|
|
802f23 |
|
|
|
802f23 |
@@ -10376,10 +10386,14 @@ ix86_adjust_stack_and_probe_stack_clash (const HOST_WIDE_INT size)
|
|
|
802f23 |
emit_insn (gen_blockage ());
|
|
|
802f23 |
}
|
|
|
802f23 |
|
|
|
802f23 |
-/* Emit code to adjust the stack pointer by SIZE bytes while probing it. */
|
|
|
802f23 |
+/* Emit code to adjust the stack pointer by SIZE bytes while probing it.
|
|
|
802f23 |
+
|
|
|
802f23 |
+ INT_REGISTERS_SAVED is true if integer registers have already been
|
|
|
802f23 |
+ pushed on the stack. */
|
|
|
802f23 |
|
|
|
802f23 |
static void
|
|
|
802f23 |
-ix86_adjust_stack_and_probe (const HOST_WIDE_INT size)
|
|
|
802f23 |
+ix86_adjust_stack_and_probe (const HOST_WIDE_INT size,
|
|
|
802f23 |
+ const bool int_registers_saved)
|
|
|
802f23 |
{
|
|
|
802f23 |
/* We skip the probe for the first interval + a small dope of 4 words and
|
|
|
802f23 |
probe that many bytes past the specified size to maintain a protection
|
|
|
802f23 |
@@ -10440,6 +10454,12 @@ ix86_adjust_stack_and_probe (const HOST_WIDE_INT size)
|
|
|
802f23 |
equality test for the loop condition. */
|
|
|
802f23 |
else
|
|
|
802f23 |
{
|
|
|
802f23 |
+ /* We expect the GP registers to be saved when probes are used
|
|
|
802f23 |
+ as the probing sequences might need a scratch register and
|
|
|
802f23 |
+ the routine to allocate one assumes the integer registers
|
|
|
802f23 |
+ have already been saved. */
|
|
|
802f23 |
+ gcc_assert (int_registers_saved);
|
|
|
802f23 |
+
|
|
|
802f23 |
HOST_WIDE_INT rounded_size;
|
|
|
802f23 |
struct scratch_reg sr;
|
|
|
802f23 |
|
|
|
802f23 |
@@ -10564,10 +10584,14 @@ output_adjust_stack_and_probe (rtx reg)
|
|
|
802f23 |
}
|
|
|
802f23 |
|
|
|
802f23 |
/* Emit code to probe a range of stack addresses from FIRST to FIRST+SIZE,
|
|
|
802f23 |
- inclusive. These are offsets from the current stack pointer. */
|
|
|
802f23 |
+ inclusive. These are offsets from the current stack pointer.
|
|
|
802f23 |
+
|
|
|
802f23 |
+ INT_REGISTERS_SAVED is true if integer registers have already been
|
|
|
802f23 |
+ pushed on the stack. */
|
|
|
802f23 |
|
|
|
802f23 |
static void
|
|
|
802f23 |
-ix86_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size)
|
|
|
802f23 |
+ix86_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size,
|
|
|
802f23 |
+ const bool int_registers_saved)
|
|
|
802f23 |
{
|
|
|
802f23 |
/* See if we have a constant small number of probes to generate. If so,
|
|
|
802f23 |
that's the easy case. The run-time loop is made up of 7 insns in the
|
|
|
802f23 |
@@ -10595,6 +10619,12 @@ ix86_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size)
|
|
|
802f23 |
equality test for the loop condition. */
|
|
|
802f23 |
else
|
|
|
802f23 |
{
|
|
|
802f23 |
+ /* We expect the GP registers to be saved when probes are used
|
|
|
802f23 |
+ as the probing sequences might need a scratch register and
|
|
|
802f23 |
+ the routine to allocate one assumes the integer registers
|
|
|
802f23 |
+ have already been saved. */
|
|
|
802f23 |
+ gcc_assert (int_registers_saved);
|
|
|
802f23 |
+
|
|
|
802f23 |
HOST_WIDE_INT rounded_size, last;
|
|
|
802f23 |
struct scratch_reg sr;
|
|
|
802f23 |
|
|
|
802f23 |
@@ -11072,20 +11102,15 @@ ix86_expand_prologue (void)
|
|
|
802f23 |
&& (flag_stack_check == STATIC_BUILTIN_STACK_CHECK
|
|
|
802f23 |
|| flag_stack_clash_protection))
|
|
|
802f23 |
{
|
|
|
802f23 |
- /* We expect the GP registers to be saved when probes are used
|
|
|
802f23 |
- as the probing sequences might need a scratch register and
|
|
|
802f23 |
- the routine to allocate one assumes the integer registers
|
|
|
802f23 |
- have already been saved. */
|
|
|
802f23 |
- gcc_assert (int_registers_saved);
|
|
|
802f23 |
-
|
|
|
802f23 |
if (flag_stack_clash_protection)
|
|
|
802f23 |
{
|
|
|
802f23 |
- ix86_adjust_stack_and_probe_stack_clash (allocate);
|
|
|
802f23 |
+ ix86_adjust_stack_and_probe_stack_clash (allocate,
|
|
|
802f23 |
+ int_registers_saved);
|
|
|
802f23 |
allocate = 0;
|
|
|
802f23 |
}
|
|
|
802f23 |
else if (STACK_CHECK_MOVING_SP)
|
|
|
802f23 |
{
|
|
|
802f23 |
- ix86_adjust_stack_and_probe (allocate);
|
|
|
802f23 |
+ ix86_adjust_stack_and_probe (allocate, int_registers_saved);
|
|
|
802f23 |
allocate = 0;
|
|
|
802f23 |
}
|
|
|
802f23 |
else
|
|
|
802f23 |
@@ -11096,9 +11121,11 @@ ix86_expand_prologue (void)
|
|
|
802f23 |
size = 0x80000000 - get_stack_check_protect () - 1;
|
|
|
802f23 |
|
|
|
802f23 |
if (TARGET_STACK_PROBE)
|
|
|
802f23 |
- ix86_emit_probe_stack_range (0, size + get_stack_check_protect ());
|
|
|
802f23 |
+ ix86_emit_probe_stack_range (0, size + get_stack_check_protect (),
|
|
|
802f23 |
+ int_registers_saved);
|
|
|
802f23 |
else
|
|
|
802f23 |
- ix86_emit_probe_stack_range (get_stack_check_protect (), size);
|
|
|
802f23 |
+ ix86_emit_probe_stack_range (get_stack_check_protect (), size,
|
|
|
802f23 |
+ int_registers_saved);
|
|
|
802f23 |
}
|
|
|
802f23 |
}
|
|
|
802f23 |
|
|
|
802f23 |
diff --git a/gcc/testsuite/gcc.target/i386/pr84064.c b/gcc/testsuite/gcc.target/i386/pr84064.c
|
|
|
802f23 |
new file mode 100644
|
|
|
802f23 |
index 0000000..01f8d9e
|
|
|
802f23 |
--- /dev/null
|
|
|
802f23 |
+++ b/gcc/testsuite/gcc.target/i386/pr84064.c
|
|
|
802f23 |
@@ -0,0 +1,10 @@
|
|
|
802f23 |
+/* { dg-do compile } */
|
|
|
802f23 |
+/* { dg-options "-O2 -march=i686 -fstack-clash-protection" } */
|
|
|
802f23 |
+/* { dg-require-effective-target ia32 } */
|
|
|
802f23 |
+
|
|
|
802f23 |
+void
|
|
|
802f23 |
+f (void *p1, void *p2)
|
|
|
802f23 |
+{
|
|
|
802f23 |
+ __builtin_memcpy (p1, p2, 1000);
|
|
|
802f23 |
+}
|
|
|
802f23 |
+
|