From: James Greenhalgh <james.greenhalgh@arm.com>
To: Sudi Das <Sudi.Das@arm.com>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
nd <nd@arm.com>, Marcus Shawcroft <Marcus.Shawcroft@arm.com>,
Richard Earnshaw <Richard.Earnshaw@arm.com>
Subject: Re: [PATCH][AARCH64] PR target/84521 Fix frame pointer corruption with -fomit-frame-pointer with __builtin_setjmp
Date: Mon, 19 Mar 2018 12:12:00 -0000 [thread overview]
Message-ID: <20180319121142.GA36085@arm.com> (raw)
In-Reply-To: <4ee92fe8-3070-0129-59ad-40cbe0207822@arm.com>
On Wed, Mar 14, 2018 at 05:40:49PM +0000, Sudi Das wrote:
> 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?
OK.
Thanks,
James
> *** 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.
> 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);
> +}
next prev parent reply other threads:[~2018-03-19 12:12 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-14 18:07 Sudakshina Das
2018-03-19 12:12 ` James Greenhalgh [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180319121142.GA36085@arm.com \
--to=james.greenhalgh@arm.com \
--cc=Marcus.Shawcroft@arm.com \
--cc=Richard.Earnshaw@arm.com \
--cc=Sudi.Das@arm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=nd@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).