Blame SOURCES/gcc48-rh1537828-2.patch

56d343
commit f7765f70e0e254fd9ce4469c7281c69cd06c9467
56d343
Author: law <law@138bc75d-0d04-0410-961f-82ee72b054a4>
56d343
Date:   Wed Jan 24 21:57:16 2018 +0000
56d343
56d343
            PR target/83994
56d343
            * i386.c (get_probe_interval): Move to earlier point.
56d343
            (ix86_compute_frame_layout): If -fstack-clash-protection and
56d343
            the frame is larger than the probe interval, then use pushes
56d343
            to save registers rather than reg->mem moves.
56d343
            (ix86_expand_prologue): Remove conditional for int_registers_saved
56d343
            assertion.
56d343
56d343
            PR target/83994
56d343
            * gcc.target/i386/pr83994.c: New test.
56d343
56d343
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
56d343
index 15cfe83..5230227 100644
56d343
--- a/gcc/config/i386/i386.c
56d343
+++ b/gcc/config/i386/i386.c
56d343
@@ -9371,6 +9371,18 @@ ix86_builtin_setjmp_frame_value (void)
56d343
   return stack_realign_fp ? hard_frame_pointer_rtx : virtual_stack_vars_rtx;
56d343
 }
56d343
 
56d343
+/* Return the probing interval for -fstack-clash-protection.  */
56d343
+
56d343
+static HOST_WIDE_INT
56d343
+get_probe_interval (void)
56d343
+{
56d343
+  if (flag_stack_clash_protection)
56d343
+    return (HOST_WIDE_INT_1U
56d343
+	    << PARAM_VALUE (PARAM_STACK_CLASH_PROTECTION_PROBE_INTERVAL));
56d343
+  else
56d343
+    return (HOST_WIDE_INT_1U << STACK_CHECK_PROBE_INTERVAL_EXP);
56d343
+}
56d343
+
56d343
 /* When using -fsplit-stack, the allocation routines set a field in
56d343
    the TCB to the bottom of the stack plus this much space, measured
56d343
    in bytes.  */
56d343
@@ -9545,7 +9557,15 @@ ix86_compute_frame_layout (struct ix86_frame *frame)
56d343
   to_allocate = offset - frame->sse_reg_save_offset;
56d343
 
56d343
   if ((!to_allocate && frame->nregs <= 1)
56d343
-      || (TARGET_64BIT && to_allocate >= (HOST_WIDE_INT) 0x80000000))
56d343
+      || (TARGET_64BIT && to_allocate >= (HOST_WIDE_INT) 0x80000000)
56d343
+      /* If stack clash probing needs a loop, then it needs a
56d343
+	 scratch register.  But the returned register is only guaranteed
56d343
+	 to be safe to use after register saves are complete.  So if
56d343
+	 stack clash protections are enabled and the allocated frame is
56d343
+	 larger than the probe interval, then use pushes to save
56d343
+	 callee saved registers.  */
56d343
+      || (flag_stack_clash_protection && to_allocate > get_probe_interval ()))
56d343
+
56d343
     frame->save_regs_using_mov = false;
56d343
 
56d343
   if (ix86_using_red_zone ()
56d343
@@ -10181,18 +10201,6 @@ release_scratch_register_on_entry (struct scratch_reg *sr)
56d343
     }
56d343
 }
56d343
 
56d343
-/* Return the probing interval for -fstack-clash-protection.  */
56d343
-
56d343
-static HOST_WIDE_INT
56d343
-get_probe_interval (void)
56d343
-{
56d343
-  if (flag_stack_clash_protection)
56d343
-    return (HOST_WIDE_INT_1U
56d343
-	    << PARAM_VALUE (PARAM_STACK_CLASH_PROTECTION_PROBE_INTERVAL));
56d343
-  else
56d343
-    return (HOST_WIDE_INT_1U << STACK_CHECK_PROBE_INTERVAL_EXP);
56d343
-}
56d343
-
56d343
 /* Emit code to adjust the stack pointer by SIZE bytes while probing it.
56d343
 
56d343
    This differs from the next routine in that it tries hard to prevent
56d343
@@ -11064,12 +11072,11 @@ ix86_expand_prologue (void)
56d343
       && (flag_stack_check == STATIC_BUILTIN_STACK_CHECK
56d343
 	  || flag_stack_clash_protection))
56d343
     {
56d343
-      /* This assert wants to verify that integer registers were saved
56d343
-	 prior to probing.  This is necessary when probing may be implemented
56d343
-	 as a function call (Windows).  It is not necessary for stack clash
56d343
-	 protection probing.  */
56d343
-      if (!flag_stack_clash_protection)
56d343
-	gcc_assert (int_registers_saved);
56d343
+      /* We expect the GP registers to be saved when probes are used
56d343
+	 as the probing sequences might need a scratch register and
56d343
+	 the routine to allocate one assumes the integer registers
56d343
+	 have already been saved.  */
56d343
+      gcc_assert (int_registers_saved);
56d343
 
56d343
       if (flag_stack_clash_protection)
56d343
 	{
56d343
diff --git a/gcc/testsuite/gcc.target/i386/pr83994.c b/gcc/testsuite/gcc.target/i386/pr83994.c
56d343
new file mode 100644
56d343
index 0000000..dc0b7cb
56d343
--- /dev/null
56d343
+++ b/gcc/testsuite/gcc.target/i386/pr83994.c
56d343
@@ -0,0 +1,16 @@
56d343
+/* { dg-do compile } */
56d343
+/* { dg-options "-O2 -march=i686 -fpic -fstack-clash-protection" } */
56d343
+/* { dg-require-effective-target ia32 } */
56d343
+
56d343
+void f1 (char *);
56d343
+
56d343
+__attribute__ ((regparm (3)))
56d343
+int
56d343
+f2 (int arg1, int arg2, int arg3)
56d343
+{
56d343
+  char buf[16384];
56d343
+  f1 (buf);
56d343
+  f1 (buf);
56d343
+  return 0;
56d343
+}
56d343
+