Blame SOURCES/gcc48-rh1537828-4.patch

4dd737
commit 14041afe24556efd5845564aa183b6451fd9d6cc
4dd737
Author: law <law@138bc75d-0d04-0410-961f-82ee72b054a4>
4dd737
Date:   Thu Feb 1 16:22:56 2018 +0000
4dd737
4dd737
            PR target/84128
4dd737
            * config/i386/i386.c (release_scratch_register_on_entry): Add new
4dd737
            OFFSET and RELEASE_VIA_POP arguments.  Use SP+OFFSET to restore
4dd737
            the scratch if RELEASE_VIA_POP is false.
4dd737
            (ix86_adjust_stack_and_probe_stack_clash): Un-constify SIZE.
4dd737
            If we have to save a temporary register, decrement SIZE appropriately.
4dd737
            Pass new arguments to release_scratch_register_on_entry.
4dd737
            (ix86_adjust_stack_and_probe): Likewise.
4dd737
            (ix86_emit_probe_stack_range): Pass new arguments to
4dd737
            release_scratch_register_on_entry.
4dd737
4dd737
            PR target/84128
4dd737
            * gcc.target/i386/pr84128.c: New test.
4dd737
4dd737
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
4dd737
index 2fe2a0c..c25d26c 100644
4dd737
--- a/gcc/config/i386/i386.c
4dd737
+++ b/gcc/config/i386/i386.c
4dd737
@@ -10182,22 +10182,39 @@ get_scratch_register_on_entry (struct scratch_reg *sr)
4dd737
     }
4dd737
 }
4dd737
 
4dd737
-/* Release a scratch register obtained from the preceding function.  */
4dd737
+/* Release a scratch register obtained from the preceding function.
4dd737
+
4dd737
+   If RELEASE_VIA_POP is true, we just pop the register off the stack
4dd737
+   to release it.  This is what non-Linux systems use with -fstack-check.
4dd737
+
4dd737
+   Otherwise we use OFFSET to locate the saved register and the
4dd737
+   allocated stack space becomes part of the local frame and is
4dd737
+   deallcated by the epilogue.  */
4dd737
 
4dd737
 static void
4dd737
-release_scratch_register_on_entry (struct scratch_reg *sr)
4dd737
+release_scratch_register_on_entry (struct scratch_reg *sr, HOST_WIDE_INT offset,
4dd737
+				   bool release_via_pop)
4dd737
 {
4dd737
   if (sr->saved)
4dd737
     {
4dd737
-      struct machine_function *m = cfun->machine;
4dd737
-      rtx x, insn = emit_insn (gen_pop (sr->reg));
4dd737
+      if (release_via_pop)
4dd737
+	{
4dd737
+	  struct machine_function *m = cfun->machine;
4dd737
+	  rtx x, insn = emit_insn (gen_pop (sr->reg));
4dd737
 
4dd737
-      /* The RTX_FRAME_RELATED_P mechanism doesn't know about pop.  */
4dd737
-      RTX_FRAME_RELATED_P (insn) = 1;
4dd737
-      x = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (UNITS_PER_WORD));
4dd737
-      x = gen_rtx_SET (VOIDmode, stack_pointer_rtx, x);
4dd737
-      add_reg_note (insn, REG_FRAME_RELATED_EXPR, x);
4dd737
-      m->fs.sp_offset -= UNITS_PER_WORD;
4dd737
+	  /* The RTX FRAME_RELATED_P mechanism doesn't know about pop.  */
4dd737
+	  RTX_FRAME_RELATED_P (insn) = 1;
4dd737
+	  x = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (UNITS_PER_WORD));
4dd737
+	  x = gen_rtx_SET (VOIDmode, stack_pointer_rtx, x);
4dd737
+	  add_reg_note (insn, REG_FRAME_RELATED_EXPR, x);
4dd737
+	  m->fs.sp_offset -= UNITS_PER_WORD;
4dd737
+	}
4dd737
+      else
4dd737
+	{
4dd737
+	  rtx x = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (offset));
4dd737
+	  x = gen_rtx_SET (VOIDmode, sr->reg, gen_rtx_MEM (word_mode, x));
4dd737
+	  emit_insn (x);
4dd737
+	}
4dd737
     }
4dd737
 }
4dd737
 
4dd737
@@ -10212,7 +10229,7 @@ release_scratch_register_on_entry (struct scratch_reg *sr)
4dd737
    pushed on the stack.  */
4dd737
 
4dd737
 static void
4dd737
-ix86_adjust_stack_and_probe_stack_clash (const HOST_WIDE_INT size,
4dd737
+ix86_adjust_stack_and_probe_stack_clash (HOST_WIDE_INT size,
4dd737
 					 const bool int_registers_saved)
4dd737
 {
4dd737
   struct machine_function *m = cfun->machine;
4dd737
@@ -10331,6 +10348,12 @@ ix86_adjust_stack_and_probe_stack_clash (const HOST_WIDE_INT size,
4dd737
       struct scratch_reg sr;
4dd737
       get_scratch_register_on_entry (&sr);
4dd737
 
4dd737
+      /* If we needed to save a register, then account for any space
4dd737
+	 that was pushed (we are not going to pop the register when
4dd737
+	 we do the restore).  */
4dd737
+      if (sr.saved)
4dd737
+	size -= UNITS_PER_WORD;
4dd737
+
4dd737
       /* Step 1: round SIZE down to a multiple of the interval.  */
4dd737
       HOST_WIDE_INT rounded_size = size & -probe_interval;
4dd737
 
4dd737
@@ -10379,7 +10402,9 @@ ix86_adjust_stack_and_probe_stack_clash (const HOST_WIDE_INT size,
4dd737
 				   m->fs.cfa_reg == stack_pointer_rtx);
4dd737
       dump_stack_clash_frame_info (PROBE_LOOP, size != rounded_size);
4dd737
 
4dd737
-      release_scratch_register_on_entry (&sr);
4dd737
+      /* This does not deallocate the space reserved for the scratch
4dd737
+	 register.  That will be deallocated in the epilogue.  */
4dd737
+      release_scratch_register_on_entry (&sr, size, false);
4dd737
     }
4dd737
 
4dd737
   /* Make sure nothing is scheduled before we are done.  */
4dd737
@@ -10392,7 +10417,7 @@ ix86_adjust_stack_and_probe_stack_clash (const HOST_WIDE_INT size,
4dd737
    pushed on the stack.  */
4dd737
 
4dd737
 static void
4dd737
-ix86_adjust_stack_and_probe (const HOST_WIDE_INT size,
4dd737
+ix86_adjust_stack_and_probe (HOST_WIDE_INT size,
4dd737
 			     const bool int_registers_saved)
4dd737
 {
4dd737
   /* We skip the probe for the first interval + a small dope of 4 words and
4dd737
@@ -10465,6 +10490,11 @@ ix86_adjust_stack_and_probe (const HOST_WIDE_INT size,
4dd737
 
4dd737
       get_scratch_register_on_entry (&sr);
4dd737
 
4dd737
+      /* If we needed to save a register, then account for any space
4dd737
+	 that was pushed (we are not going to pop the register when
4dd737
+	 we do the restore).  */
4dd737
+      if (sr.saved)
4dd737
+	size -= UNITS_PER_WORD;
4dd737
 
4dd737
       /* Step 1: round SIZE to the previous multiple of the interval.  */
4dd737
 
4dd737
@@ -10516,7 +10546,9 @@ ix86_adjust_stack_and_probe (const HOST_WIDE_INT size,
4dd737
 						    (get_probe_interval ()
4dd737
 						     + dope))));
4dd737
 
4dd737
-      release_scratch_register_on_entry (&sr);
4dd737
+      /* This does not deallocate the space reserved for the scratch
4dd737
+	 register.  That will be deallocated in the epilogue.  */
4dd737
+      release_scratch_register_on_entry (&sr, size, false);
4dd737
     }
4dd737
 
4dd737
   gcc_assert (cfun->machine->fs.cfa_reg != stack_pointer_rtx);
4dd737
@@ -10669,7 +10701,7 @@ ix86_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size,
4dd737
 						       sr.reg),
4dd737
 					 rounded_size - size));
4dd737
 
4dd737
-      release_scratch_register_on_entry (&sr);
4dd737
+      release_scratch_register_on_entry (&sr, size, true);
4dd737
     }
4dd737
 
4dd737
   /* Make sure nothing is scheduled before we are done.  */
4dd737
diff --git a/gcc/testsuite/gcc.target/i386/pr84128.c b/gcc/testsuite/gcc.target/i386/pr84128.c
4dd737
new file mode 100644
4dd737
index 0000000..a8323fd
4dd737
--- /dev/null
4dd737
+++ b/gcc/testsuite/gcc.target/i386/pr84128.c
4dd737
@@ -0,0 +1,30 @@
4dd737
+/* { dg-do run } */
4dd737
+/* { dg-options "-O2 -march=i686 -mtune=generic -fstack-clash-protection" } */
4dd737
+/* { dg-require-effective-target ia32 } */
4dd737
+
4dd737
+__attribute__ ((noinline, noclone, weak, regparm (3)))
4dd737
+int
4dd737
+f1 (long arg0, int (*pf) (long, void *))
4dd737
+{
4dd737
+  unsigned char buf[32768];
4dd737
+  return pf (arg0, buf);
4dd737
+}
4dd737
+
4dd737
+__attribute__ ((noinline, noclone, weak))
4dd737
+int
4dd737
+f2 (long arg0, void *ignored)
4dd737
+{
4dd737
+  if (arg0 != 17)
4dd737
+    __builtin_abort ();
4dd737
+  return 19;
4dd737
+}
4dd737
+
4dd737
+int
4dd737
+main (void)
4dd737
+{
4dd737
+  if (f1 (17, f2) != 19)
4dd737
+    __builtin_abort ();
4dd737
+  return 0;
4dd737
+}
4dd737
+
4dd737
+