public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] MIPS: Fix __builtin_longjmp (PR 64242)
@ 2020-07-12  6:27 Paul Hua
  2020-07-28  1:02 ` Paul Hua
  2020-08-24 22:06 ` Jeff Law
  0 siblings, 2 replies; 3+ messages in thread
From: Paul Hua @ 2020-07-12  6:27 UTC (permalink / raw)
  To: gcc-patches

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

From 589dbe8a1c2397bfafefa4e84abe5ec6e6798928 Mon Sep 17 00:00:00 2001
From: Andrew Pinski <apinski@marvell.com>
Date: Wed, 12 Feb 2020 11:42:57 +0000
Subject: [PATCH] MIPS: Fix __builtin_longjmp (PR 64242)

The problem here is mips has its own builtin_longjmp
pattern and it was not fixed when expand_builtin_longjmp
was fixed.  We need to read the new fp and gp before
restoring the stack as the buffer might be a local
variable.

Change-Id: I3416568e260e6bde3ad5cc470fb4f2ecfa207f05
Signed-off-by: Andrew Pinski <apinski@marvell.com>

This patch from Andrew, I bootstrapped and tested on mips64el-linux-gnu.

OK for master ?

gcc/ChangeLog:

        PR middle-end/64242
        * config/mips/mips.md (builtin_longjmp): Restore the frame pointer
           and stack pointer and gp.

[-- Attachment #2: mips-fix-pr64242.patch --]
[-- Type: text/x-patch, Size: 1582 bytes --]

From 589dbe8a1c2397bfafefa4e84abe5ec6e6798928 Mon Sep 17 00:00:00 2001
From: Andrew Pinski <apinski@marvell.com>
Date: Wed, 12 Feb 2020 11:42:57 +0000
Subject: [PATCH] MIPS: Fix __builtin_longjmp (PR 64242)

The problem here is mips has its own builtin_longjmp
pattern and it was not fixed when expand_builtin_longjmp
was fixed.  We need to read the new fp and gp before
restoring the stack as the buffer might be a local
variable.

Change-Id: I3416568e260e6bde3ad5cc470fb4f2ecfa207f05
Signed-off-by: Andrew Pinski <apinski@marvell.com>
---
 gcc/config/mips/mips.md | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/config/mips/mips.md b/gcc/config/mips/mips.md
index dd9fdd1418d..8bafbe82bd3 100644
--- a/gcc/config/mips/mips.md
+++ b/gcc/config/mips/mips.md
@@ -6601,9 +6601,19 @@
 
   /* This bit is similar to expand_builtin_longjmp except that it
      restores $gp as well.  */
-  mips_emit_move (hard_frame_pointer_rtx, fp);
   mips_emit_move (pv, lab);
+  /* Restore the frame pointer and stack pointer and gp.  We must use a
+     temporary since the setjmp buffer may be a local.  */
+  fp = copy_to_reg (fp);
+  gpv = copy_to_reg (gpv);
   emit_stack_restore (SAVE_NONLOCAL, stack);
+
+  /* Ensure the frame pointer move is not optimized.  */
+  emit_insn (gen_blockage ());
+  emit_clobber (hard_frame_pointer_rtx);
+  emit_clobber (frame_pointer_rtx);
+  emit_clobber (gp);
+  mips_emit_move (hard_frame_pointer_rtx, fp);
   mips_emit_move (gp, gpv);
   emit_use (hard_frame_pointer_rtx);
   emit_use (stack_pointer_rtx);
-- 
2.17.1


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

* Re: [PATCH] MIPS: Fix __builtin_longjmp (PR 64242)
  2020-07-12  6:27 [PATCH] MIPS: Fix __builtin_longjmp (PR 64242) Paul Hua
@ 2020-07-28  1:02 ` Paul Hua
  2020-08-24 22:06 ` Jeff Law
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Hua @ 2020-07-28  1:02 UTC (permalink / raw)
  To: gcc-patches

ping?

On Sun, Jul 12, 2020 at 2:27 PM Paul Hua <paul.hua.gm@gmail.com> wrote:
>
> From 589dbe8a1c2397bfafefa4e84abe5ec6e6798928 Mon Sep 17 00:00:00 2001
> From: Andrew Pinski <apinski@marvell.com>
> Date: Wed, 12 Feb 2020 11:42:57 +0000
> Subject: [PATCH] MIPS: Fix __builtin_longjmp (PR 64242)
>
> The problem here is mips has its own builtin_longjmp
> pattern and it was not fixed when expand_builtin_longjmp
> was fixed.  We need to read the new fp and gp before
> restoring the stack as the buffer might be a local
> variable.
>
> Change-Id: I3416568e260e6bde3ad5cc470fb4f2ecfa207f05
> Signed-off-by: Andrew Pinski <apinski@marvell.com>
>
> This patch from Andrew, I bootstrapped and tested on mips64el-linux-gnu.
>
> OK for master ?
>
> gcc/ChangeLog:
>
>         PR middle-end/64242
>         * config/mips/mips.md (builtin_longjmp): Restore the frame pointer
>            and stack pointer and gp.

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

* Re: [PATCH] MIPS: Fix __builtin_longjmp (PR 64242)
  2020-07-12  6:27 [PATCH] MIPS: Fix __builtin_longjmp (PR 64242) Paul Hua
  2020-07-28  1:02 ` Paul Hua
@ 2020-08-24 22:06 ` Jeff Law
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff Law @ 2020-08-24 22:06 UTC (permalink / raw)
  To: Paul Hua, gcc-patches

On Sun, 2020-07-12 at 14:27 +0800, Paul Hua wrote:
> From 589dbe8a1c2397bfafefa4e84abe5ec6e6798928 Mon Sep 17 00:00:00 2001
> From: Andrew Pinski <apinski@marvell.com>
> Date: Wed, 12 Feb 2020 11:42:57 +0000
> Subject: [PATCH] MIPS: Fix __builtin_longjmp (PR 64242)
> 
> The problem here is mips has its own builtin_longjmp
> pattern and it was not fixed when expand_builtin_longjmp
> was fixed.  We need to read the new fp and gp before
> restoring the stack as the buffer might be a local
> variable.
> 
> Change-Id: I3416568e260e6bde3ad5cc470fb4f2ecfa207f05
> Signed-off-by: Andrew Pinski <apinski@marvell.com>
> 
> This patch from Andrew, I bootstrapped and tested on mips64el-linux-gnu.
> 
> OK for master ?
> 
> gcc/ChangeLog:
> 
>         PR middle-end/64242
>         * config/mips/mips.md (builtin_longjmp): Restore the frame pointer
>            and stack pointer and gp.
OK
jeff


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

end of thread, other threads:[~2020-08-24 22:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-12  6:27 [PATCH] MIPS: Fix __builtin_longjmp (PR 64242) Paul Hua
2020-07-28  1:02 ` Paul Hua
2020-08-24 22:06 ` Jeff Law

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).