From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19568 invoked by alias); 12 Oct 2018 22:26:51 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 19552 invoked by uid 89); 12 Oct 2018 22:26:51 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=non-negative, nonnegative, RFA, rfa X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 12 Oct 2018 22:26:49 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 0A9D5560C6 for ; Fri, 12 Oct 2018 18:26:48 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id HqpcvWbqbnnt for ; Fri, 12 Oct 2018 18:26:47 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id F0297116142 for ; Fri, 12 Oct 2018 18:26:47 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4233) id EB86D34BA; Fri, 12 Oct 2018 18:26:47 -0400 (EDT) From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [RFA/commit] rs6000-tdep.c:skip_prologue avoid negative left shift Date: Fri, 12 Oct 2018 22:26:00 -0000 Message-Id: <1539383206-81457-1-git-send-email-brobecker@adacore.com> X-SW-Source: 2018-10/txt/msg00301.txt.bz2 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