public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFA/commit] rs6000-tdep.c:skip_prologue avoid negative left shift
@ 2018-10-12 22:26 Joel Brobecker
  2018-10-13  4:26 ` Kevin Buettner
  0 siblings, 1 reply; 3+ messages in thread
From: Joel Brobecker @ 2018-10-12 22:26 UTC (permalink / raw)
  To: gdb-patches

the rs6000-tdep.c::skip_prologue function has the following code:

          unsigned int all_mask = ~((1U << fdata->saved_gpr) - 1);

          /* Not a recognized prologue instruction.
             Handle optimizer code motions into the prologue by continuing
             the search if we have no valid frame yet or if the return
             address is not yet saved in the frame.  Also skip instructions
             if some of the GPRs expected to be saved are not yet saved.  */
          if (fdata->frameless == 0 && fdata->nosavedpc == 0
              && (fdata->gpr_mask & all_mask) == all_mask)
            break;

The problem is that fdata->saved_gpr is initialized to -1, and so,
if no instruction is found in the function's prologue that causes us
to set that field to a non-negative value, the sanitizer crashes
with the following message:

    rs6000-tdep.c:1965:34: runtime error: shift exponent -1 is negative

This patch fixes the issue the by only doing the shift if saved_gpr
is not negative. When saved_gpr is negative, we actually don't need
the shift.

gdb/ChangeLog:

        * rs6000-tdep.c (skip_prologue): Fix potential negative left
        shifting.

Tested on ppc-linux native.
Also tested on ppc-elf (baremetal) using AdaCore's testsuite.

I will commit in a couple of weeks unless there are objections.

Thanks,
-- 
Joel

---
 gdb/rs6000-tdep.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index ce01be5..45dffbe 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -1962,16 +1962,19 @@ skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, CORE_ADDR lim_pc,
 
       else
 	{
-	  unsigned int all_mask = ~((1U << fdata->saved_gpr) - 1);
-
 	  /* Not a recognized prologue instruction.
 	     Handle optimizer code motions into the prologue by continuing
 	     the search if we have no valid frame yet or if the return
 	     address is not yet saved in the frame.  Also skip instructions
 	     if some of the GPRs expected to be saved are not yet saved.  */
 	  if (fdata->frameless == 0 && fdata->nosavedpc == 0
-	      && (fdata->gpr_mask & all_mask) == all_mask)
-	    break;
+	      && fdata->saved_gpr != -1)
+	    {
+	      unsigned int all_mask = ~((1U << fdata->saved_gpr) - 1);
+
+	      if ((fdata->gpr_mask & all_mask) == all_mask)
+		break;
+	    }
 
 	  if (op == 0x4e800020		/* blr */
 	      || op == 0x4e800420)	/* bctr */
-- 
2.1.4

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

* Re: [RFA/commit] rs6000-tdep.c:skip_prologue avoid negative left shift
  2018-10-12 22:26 [RFA/commit] rs6000-tdep.c:skip_prologue avoid negative left shift Joel Brobecker
@ 2018-10-13  4:26 ` Kevin Buettner
  2018-11-01 21:47   ` Joel Brobecker
  0 siblings, 1 reply; 3+ messages in thread
From: Kevin Buettner @ 2018-10-13  4:26 UTC (permalink / raw)
  To: gdb-patches; +Cc: Joel Brobecker

On Fri, 12 Oct 2018 18:26:46 -0400
Joel Brobecker <brobecker@adacore.com> wrote:

> gdb/ChangeLog:
> 
>         * rs6000-tdep.c (skip_prologue): Fix potential negative left
>         shifting.

LGTM.

Kevin

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

* Re: [RFA/commit] rs6000-tdep.c:skip_prologue avoid negative left shift
  2018-10-13  4:26 ` Kevin Buettner
@ 2018-11-01 21:47   ` Joel Brobecker
  0 siblings, 0 replies; 3+ messages in thread
From: Joel Brobecker @ 2018-11-01 21:47 UTC (permalink / raw)
  To: Kevin Buettner; +Cc: gdb-patches

> > gdb/ChangeLog:
> > 
> >         * rs6000-tdep.c (skip_prologue): Fix potential negative left
> >         shifting.
> 
> LGTM.

Thanks Kevin. I finally took the time to push this patch in.

-- 
Joel

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

end of thread, other threads:[~2018-11-01 21:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-12 22:26 [RFA/commit] rs6000-tdep.c:skip_prologue avoid negative left shift Joel Brobecker
2018-10-13  4:26 ` Kevin Buettner
2018-11-01 21:47   ` Joel Brobecker

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