]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
rs6000: ROP - Do not disable shrink-wrapping for leaf functions [PR114759]
authorPeter Bergner <bergner@linux.ibm.com>
Tue, 18 Jun 2024 22:42:45 +0000 (17:42 -0500)
committerPeter Bergner <bergner@linux.ibm.com>
Mon, 12 Aug 2024 17:27:07 +0000 (12:27 -0500)
Only disable shrink-wrapping when using -mrop-protect when we know we
will be emitting the ROP-protect hash instructions (ie, non-leaf functions).

2024-06-17  Peter Bergner  <bergner@linux.ibm.com>

gcc/
PR target/114759
* config/rs6000/rs6000.cc (rs6000_override_options_after_change): Move
the disabling of shrink-wrapping from here....
* config/rs6000/rs6000-logue.cc (rs6000_emit_prologue): ...to here.

gcc/testsuite/
PR target/114759
* gcc.target/powerpc/pr114759-1.c: New test.

gcc/config/rs6000/rs6000-logue.cc
gcc/config/rs6000/rs6000.cc
gcc/testsuite/gcc.target/powerpc/pr114759-1.c [new file with mode: 0644]

index edc0d6c8f520b34f7f88f62bd6f1c8330ef2eb66..fdb6414f486f5887ffc66e6e7773d0acb66f0032 100644 (file)
@@ -3012,6 +3012,11 @@ rs6000_emit_prologue (void)
                            && (lookup_attribute ("no_split_stack",
                                                  DECL_ATTRIBUTES (cfun->decl))
                                == NULL));
+  /* If we are inserting ROP-protect hash instructions, disable shrink-wrap
+     until the bug where the hashst insn is emitted in the wrong location
+     is fixed.  See PR101324 for details.  */
+  if (info->rop_hash_size)
+    flag_shrink_wrap = 0;
 
   frame_pointer_needed_indeed
     = frame_pointer_needed && df_regs_ever_live_p (HARD_FRAME_POINTER_REGNUM);
index 0bcc6a2d0ab604f3a696a44bc34db7f87ab9ba3d..f2bd9edea8a16db8c224687773dc00f803ed0954 100644 (file)
@@ -3431,10 +3431,6 @@ rs6000_override_options_after_change (void)
   else if (!OPTION_SET_P (flag_cunroll_grow_size))
     flag_cunroll_grow_size = flag_peel_loops || optimize >= 3;
 
-  /* If we are inserting ROP-protect instructions, disable shrink wrap.  */
-  if (rs6000_rop_protect)
-    flag_shrink_wrap = 0;
-
   /* One of the late-combine passes runs after register allocation
      and can match define_insn_and_splits that were previously used
      only before register allocation.  Some of those define_insn_and_splits
diff --git a/gcc/testsuite/gcc.target/powerpc/pr114759-1.c b/gcc/testsuite/gcc.target/powerpc/pr114759-1.c
new file mode 100644 (file)
index 0000000..579e08e
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mdejagnu-cpu=power10 -mrop-protect -fdump-rtl-pro_and_epilogue" } */
+/* { dg-require-effective-target rop_ok } Only enable on supported ABIs. */
+
+/* Verify we still attempt shrink-wrapping when using -mrop-protect
+   and there are no function calls.  */
+
+long
+foo (long arg)
+{
+  if (arg)
+    asm ("" ::: "r20");
+  return 0;
+}
+
+/* { dg-final { scan-rtl-dump-times "Performing shrink-wrapping" 1 "pro_and_epilogue" } } */