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