This commit is contained in:
Jakub Jelinek 2018-01-30 11:26:25 +01:00
parent c587503828
commit 652d93f4cc
5 changed files with 189 additions and 104 deletions

1
.gitignore vendored
View File

@ -28,3 +28,4 @@
/gcc-7.2.1-20180104.tar.bz2
/gcc-7.2.1-20180117.tar.bz2
/gcc-7.3.1-20180125.tar.bz2
/gcc-7.3.1-20180130.tar.bz2

View File

@ -1,10 +1,10 @@
%global DATE 20180125
%global SVNREV 257047
%global DATE 20180130
%global SVNREV 257180
%global gcc_version 7.3.1
%global gcc_major 7
# Note, gcc_release must be integer, if you want to add suffixes to
# %{release}, append them after %{gcc_release} on Release: line.
%global gcc_release 1
%global gcc_release 2
%global nvptx_tools_gitrev c28050f60193b3b95a18866a96f03334e874e78f
%global nvptx_newlib_gitrev aadc8eb0ec43b7cd0dd2dfb484bae63c8b05ef24
%global _unpackaged_files_terminate_build 0
@ -237,7 +237,7 @@ Patch10: gcc7-foffload-default.patch
Patch11: gcc7-Wno-format-security.patch
Patch12: gcc7-aarch64-sanitizer-fix.patch
Patch13: gcc7-rh1512529-aarch64.patch
Patch14: gcc7-rh1536555.patch
Patch14: gcc7-pr84064.patch
Patch1000: nvptx-tools-no-ptxas.patch
Patch1001: nvptx-tools-build.patch
@ -833,7 +833,7 @@ package or when debugging this package.
%patch12 -p0 -b .aarch64-sanitizer-fix~
%endif
%patch13 -p0 -b .rh1512529-aarch64~
%patch14 -p0 -b .rh1537979~
%patch14 -p0 -b .pr84064~
cd nvptx-tools-%{nvptx_tools_gitrev}
%patch1000 -p1 -b .nvptx-tools-no-ptxas~
@ -3261,6 +3261,13 @@ fi
%endif
%changelog
* Tue Jan 30 2018 Jakub Jelinek <jakub@redhat.com> 7.3.1-2
- update from the 7 branch
- PRs c++/82461, c++/82878, libstdc++/81076, libstdc++/83658,
libstdc++/83830, libstdc++/83833, rtl-optimization/83985, target/68467,
target/81763, target/83399, target/83862, target/83905, target/84033
- fix -fstack-clash-protection ICE on i686 (#1538648, PR target/84064)
* Thu Jan 25 2018 Jakub Jelinek <jakub@redhat.com> 7.3.1-1
- update from the 7 branch
- 7.3 release

175
gcc7-pr84064.patch Normal file
View File

@ -0,0 +1,175 @@
2018-01-30 Jeff Law <law@redhat.com>
PR target/84064
* i386.c (ix86_adjust_stack_and_probe_stack_clash): New argument
INT_REGISTERS_SAVED. Check it prior to calling
get_scratch_register_on_entry.
(ix86_adjust_stack_and_probe): Similarly.
(ix86_emit_probe_stack_range): Similarly.
(ix86_expand_prologue): Corresponding changes.
* gcc.target/i386/pr84064: New test.
--- gcc/config/i386/i386.c
+++ gcc/config/i386/i386.c
@@ -12591,10 +12591,14 @@ release_scratch_register_on_entry (struct scratch_reg *sr)
This differs from the next routine in that it tries hard to prevent
attacks that jump the stack guard. Thus it is never allowed to allocate
more than PROBE_INTERVAL bytes of stack space without a suitable
- probe. */
+ probe.
+
+ INT_REGISTERS_SAVED is true if integer registers have already been
+ pushed on the stack. */
static void
-ix86_adjust_stack_and_probe_stack_clash (const HOST_WIDE_INT size)
+ix86_adjust_stack_and_probe_stack_clash (const HOST_WIDE_INT size,
+ const bool int_registers_saved)
{
struct machine_function *m = cfun->machine;
@@ -12700,6 +12704,12 @@ ix86_adjust_stack_and_probe_stack_clash (const HOST_WIDE_INT size)
}
else
{
+ /* 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);
+
struct scratch_reg sr;
get_scratch_register_on_entry (&sr);
@@ -12758,10 +12768,14 @@ ix86_adjust_stack_and_probe_stack_clash (const HOST_WIDE_INT size)
emit_insn (gen_blockage ());
}
-/* Emit code to adjust the stack pointer by SIZE bytes while probing it. */
+/* Emit code to adjust the stack pointer by SIZE bytes while probing it.
+
+ INT_REGISTERS_SAVED is true if integer registers have already been
+ pushed on the stack. */
static void
-ix86_adjust_stack_and_probe (const HOST_WIDE_INT size)
+ix86_adjust_stack_and_probe (const HOST_WIDE_INT size,
+ const bool int_registers_saved)
{
/* We skip the probe for the first interval + a small dope of 4 words and
probe that many bytes past the specified size to maintain a protection
@@ -12822,6 +12836,12 @@ ix86_adjust_stack_and_probe (const HOST_WIDE_INT size)
equality test for the loop condition. */
else
{
+ /* 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);
+
HOST_WIDE_INT rounded_size;
struct scratch_reg sr;
@@ -12949,10 +12969,14 @@ output_adjust_stack_and_probe (rtx reg)
}
/* Emit code to probe a range of stack addresses from FIRST to FIRST+SIZE,
- inclusive. These are offsets from the current stack pointer. */
+ inclusive. These are offsets from the current stack pointer.
+
+ INT_REGISTERS_SAVED is true if integer registers have already been
+ pushed on the stack. */
static void
-ix86_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size)
+ix86_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size,
+ const bool int_registers_saved)
{
/* See if we have a constant small number of probes to generate. If so,
that's the easy case. The run-time loop is made up of 6 insns in the
@@ -12980,6 +13004,12 @@ ix86_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size)
equality test for the loop condition. */
else
{
+ /* 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);
+
HOST_WIDE_INT rounded_size, last;
struct scratch_reg sr;
@@ -13733,15 +13763,10 @@ ix86_expand_prologue (void)
&& (flag_stack_check == STATIC_BUILTIN_STACK_CHECK
|| flag_stack_clash_protection))
{
- /* 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)
{
- ix86_adjust_stack_and_probe_stack_clash (allocate);
+ ix86_adjust_stack_and_probe_stack_clash (allocate,
+ int_registers_saved);
allocate = 0;
}
else if (STACK_CHECK_MOVING_SP)
@@ -13749,7 +13774,7 @@ ix86_expand_prologue (void)
if (!(crtl->is_leaf && !cfun->calls_alloca
&& allocate <= get_probe_interval ()))
{
- ix86_adjust_stack_and_probe (allocate);
+ ix86_adjust_stack_and_probe (allocate, int_registers_saved);
allocate = 0;
}
}
@@ -13765,11 +13790,12 @@ ix86_expand_prologue (void)
if (crtl->is_leaf && !cfun->calls_alloca)
{
if (size > get_probe_interval ())
- ix86_emit_probe_stack_range (0, size);
+ ix86_emit_probe_stack_range (0, size, int_registers_saved);
}
else
ix86_emit_probe_stack_range (0,
- size + get_stack_check_protect ());
+ size + get_stack_check_protect (),
+ int_registers_saved);
}
else
{
@@ -13778,10 +13804,13 @@ ix86_expand_prologue (void)
if (size > get_probe_interval ()
&& size > get_stack_check_protect ())
ix86_emit_probe_stack_range (get_stack_check_protect (),
- size - get_stack_check_protect ());
+ (size
+ - get_stack_check_protect ()),
+ int_registers_saved);
}
else
- ix86_emit_probe_stack_range (get_stack_check_protect (), size);
+ ix86_emit_probe_stack_range (get_stack_check_protect (), size,
+ int_registers_saved);
}
}
}
--- gcc/testsuite/gcc.target/i386/pr84064.c
+++ gcc/testsuite/gcc.target/i386/pr84064.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=i686 -fstack-clash-protection" } */
+/* { dg-require-effective-target ia32 } */
+
+void
+f (void *p1, void *p2)
+{
+ __builtin_memcpy (p1, p2, 1000);
+}
+

View File

@ -1,98 +0,0 @@
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 346fb4f..f0b8346 100644
--- gcc/config/i386/i386.c
+++ gcc/config/i386/i386.c
@@ -12763,6 +12763,18 @@ ix86_builtin_setjmp_frame_value (void)
return stack_realign_fp ? hard_frame_pointer_rtx : virtual_stack_vars_rtx;
}
+/* 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. */
@@ -12948,7 +12960,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 ()
@@ -13619,18 +13638,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
@@ -14558,12 +14565,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/gcc.target/i386/pr83994.c b/gcc/testsuite/gcc.target/i386/pr83994.c
new file mode 100644
index 0000000..dc0b7cb
--- /dev/null
+++ 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;
+}
+

View File

@ -1,3 +1,3 @@
SHA512 (gcc-7.3.1-20180125.tar.bz2) = fd3d407f767d01f63e6e564755c82baf25a9a9665c2dbdc0ae9796e4e522cb58b0f8ed369ed1ac31ea88ff1dddc15dc8f2e6d7461085bd54a03bbb2db6c7f102
SHA512 (gcc-7.3.1-20180130.tar.bz2) = 64b64c243872ffaf3e88eb9fdc315f3afca4dd1a8a6e610f6632ab29141bb18510a016bcd155b3c6ea38fb365f32e892a395a56b4fa6dba355a792d96cc13341
SHA512 (nvptx-newlib-aadc8eb0ec43b7cd0dd2dfb484bae63c8b05ef24.tar.bz2) = 38f97c9297ad108568352a4d28277455a3c01fd8b7864e798037e5006b6f757022e874bbf3f165775fe3b873781bc108137bbeb42dd5ed3c7d3e6747746fa918
SHA512 (nvptx-tools-c28050f60193b3b95a18866a96f03334e874e78f.tar.bz2) = 95b577a06a93bb044dbc8033e550cb36bcf2ab2687da030a7318cdc90e7467ed49665e247dcafb5ff4a7e92cdc264291d19728bd17fab902fb64b22491269330