public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][AARCH64] PR target/84521 Fix frame pointer corruption with -fomit-frame-pointer with __builtin_setjmp
@ 2018-03-14 18:07 Sudakshina Das
  2018-03-19 12:12 ` James Greenhalgh
  2018-05-02 17:29 ` Jeff Law
  0 siblings, 2 replies; 17+ messages in thread
From: Sudakshina Das @ 2018-03-14 18:07 UTC (permalink / raw)
  To: gcc-patches; +Cc: nd, James Greenhalgh, Marcus Shawcroft, Richard Earnshaw

[-- Attachment #1: Type: text/plain, Size: 931 bytes --]

Hi

This patch is another partial fix for PR 84521. This is adding a 
definition to one of the target hooks used in the SJLJ implemetation so 
that AArch64 defines the hard_frame_pointer_rtx as the 
TARGET_BUILTIN_SETJMP_FRAME_VALUE. As pointed out by Wilco there is 
still a lot more work to be done for these builtins in the future.

Testing: Bootstrapped and regtested on aarch64-none-linux-gnu and added 
new test.

Is this ok for trunk?

Sudi


*** gcc/ChangeLog ***

2018-03-14  Sudakshina Das  <sudi.das@arm.com>

	* builtins.c (expand_builtin_setjmp_receiver): Update condition
	to restore frame pointer.
	* config/aarch64/aarch64.h (DONT_USE_BUILTIN_SETJMP): Update
	comment.
	* config/aarch64/aarch64.c (aarch64_builtin_setjmp_frame_value):
	New.
	(TARGET_BUILTIN_SETJMP_FRAME_VALUE): Define.

*** gcc/testsuite/ChangeLog ***

2018-03-14  Sudakshina Das  <sudi.das@arm.com>

	* gcc.c-torture/execute/pr84521.c: New test.

[-- Attachment #2: pr84521.diff --]
[-- Type: text/x-patch, Size: 3096 bytes --]

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 85affa7..640f1a9 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -898,7 +898,8 @@ expand_builtin_setjmp_receiver (rtx receiver_label)
 
   /* Now put in the code to restore the frame pointer, and argument
      pointer, if needed.  */
-  if (! targetm.have_nonlocal_goto ())
+  if (! targetm.have_nonlocal_goto ()
+      && targetm.builtin_setjmp_frame_value () != hard_frame_pointer_rtx)
     {
       /* First adjust our frame pointer to its actual value.  It was
 	 previously set to the start of the virtual area corresponding to
diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index e3c52f6..7a21c14 100644
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -474,7 +474,9 @@ extern unsigned aarch64_architecture_version;
 #define EH_RETURN_STACKADJ_RTX	gen_rtx_REG (Pmode, R4_REGNUM)
 #define EH_RETURN_HANDLER_RTX  aarch64_eh_return_handler_rtx ()
 
-/* Don't use __builtin_setjmp until we've defined it.  */
+/* Don't use __builtin_setjmp until we've defined it.
+   CAUTION: This macro is only used during exception unwinding.
+   Don't fall for its name.  */
 #undef DONT_USE_BUILTIN_SETJMP
 #define DONT_USE_BUILTIN_SETJMP 1
 
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index e1fb87f..e7ac0fe 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -12128,6 +12128,13 @@ aarch64_expand_builtin_va_start (tree valist, rtx nextarg ATTRIBUTE_UNUSED)
   expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
 }
 
+/* Implement TARGET_BUILTIN_SETJMP_FRAME_VALUE.  */
+static rtx
+aarch64_builtin_setjmp_frame_value (void)
+{
+  return hard_frame_pointer_rtx;
+}
+
 /* Implement TARGET_GIMPLIFY_VA_ARG_EXPR.  */
 
 static tree
@@ -17505,6 +17512,9 @@ aarch64_run_selftests (void)
 #undef TARGET_FOLD_BUILTIN
 #define TARGET_FOLD_BUILTIN aarch64_fold_builtin
 
+#undef TARGET_BUILTIN_SETJMP_FRAME_VALUE
+#define TARGET_BUILTIN_SETJMP_FRAME_VALUE aarch64_builtin_setjmp_frame_value
+
 #undef TARGET_FUNCTION_ARG
 #define TARGET_FUNCTION_ARG aarch64_function_arg
 
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr84521.c b/gcc/testsuite/gcc.c-torture/execute/pr84521.c
new file mode 100644
index 0000000..76b10d2
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr84521.c
@@ -0,0 +1,49 @@
+/* { dg-require-effective-target indirect_jumps } */
+
+#include <setjmp.h>
+
+jmp_buf buf;
+
+int uses_longjmp (void)
+{
+  __builtin_longjmp (buf, 1);
+}
+
+int gl;
+void after_longjmp (void)
+{
+  gl = 5;
+}
+
+int
+test_1 (int n)
+{
+  volatile int *p = alloca (n);
+  if (__builtin_setjmp (buf))
+    {
+      after_longjmp ();
+    }
+  else
+    {
+      uses_longjmp ();
+    }
+
+  return 0;
+}
+
+int __attribute__ ((optimize ("no-omit-frame-pointer")))
+test_2 (int n)
+{
+  int i;
+  int *ptr = (int *)__builtin_alloca (sizeof (int) * n);
+  for (i = 0; i < n; i++)
+    ptr[i] = i;
+  test_1 (n);
+  return 0;
+}
+
+int main (int argc, const char **argv)
+{
+  __builtin_memset (&buf, 0xaf, sizeof (buf));
+  test_2 (100);
+}

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2018-08-01 10:33 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-14 18:07 [PATCH][AARCH64] PR target/84521 Fix frame pointer corruption with -fomit-frame-pointer with __builtin_setjmp Sudakshina Das
2018-03-19 12:12 ` James Greenhalgh
2018-03-20 19:36   ` Sudakshina Das
2018-05-02 17:29 ` Jeff Law
2018-06-07 13:04   ` Sudakshina Das
2018-06-07 15:33     ` Eric Botcazou
2018-06-14 11:10       ` Sudakshina Das
2018-06-25  9:25         ` Sudakshina Das
2018-06-26 21:45           ` James Greenhalgh
2018-06-26 22:33             ` Eric Botcazou
2018-06-27  8:12               ` Wilco Dijkstra
2018-06-27  8:26                 ` Eric Botcazou
2018-06-27 11:22                   ` Wilco Dijkstra
2018-07-12 17:01                     ` Sudakshina Das
2018-07-31 21:42                       ` James Greenhalgh
2018-07-31 21:49                         ` Andrew Pinski
2018-08-01 10:33                           ` Sudakshina Das

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).