Blame SOURCES/gcc48-rh1537828-2.patch

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