From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 5FB29386F82A for ; Sun, 21 Jun 2020 11:27:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5FB29386F82A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.11] (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id CFE5F1E79B; Sun, 21 Jun 2020 07:27:38 -0400 (EDT) Subject: Re: [PATCH v2 1/2] Add i386 support for endbr skipping To: Victor Collod , gdb-patches@sourceware.org References: <0c2e7c13-3a10-0f83-955b-e08dcd628d17@simark.ca> <20200611225455.9354-1-vcollod@nvidia.com> <20200611225455.9354-2-vcollod@nvidia.com> From: Simon Marchi Message-ID: <1d846c51-1736-45a6-b4ae-5bae77314b49@simark.ca> Date: Sun, 21 Jun 2020 07:27:38 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200611225455.9354-2-vcollod@nvidia.com> Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Jun 2020 11:27:40 -0000 On 2020-06-11 6:54 p.m., Victor Collod via Gdb-patches wrote: > 2020-06-11 Victor Collod > > * i386-tdep.c (i386_skip_endbr): Add a helper function to skip endbr. > (i386_analyze_prologue): Call i386_skip_endbr. > --- > gdb/i386-tdep.c | 19 +++++++++++++++++++ > 1 file changed, 19 insertions(+) > > diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c > index 9b905c1996a..263a3fd452e 100644 > --- a/gdb/i386-tdep.c > +++ b/gdb/i386-tdep.c > @@ -1537,6 +1537,24 @@ struct i386_insn i386_frame_setup_skip_insns[] = > { 0 } > }; > > +/* Check whether PC points to an endbr32 instruction. */ > +static CORE_ADDR > +i386_skip_endbr (CORE_ADDR pc) > +{ > + static const gdb_byte endbr32[] = { 0xf3, 0x0f, 0x1e, 0xfb }; > + > + gdb_byte buf[sizeof (endbr32)]; > + > + /* Stop there if we can't read the code */ > + if (target_read_code (pc, buf, sizeof (endbr32))) > + return pc; > + > + /* If the instruction isn't an endbr32, stop */ > + if (memcmp (buf, endbr32, sizeof (endbr32)) != 0) > + return pc; > + > + return pc + sizeof (endbr32); > +} > > /* Check whether PC points to a no-op instruction. */ > static CORE_ADDR > @@ -1814,6 +1832,7 @@ i386_analyze_prologue (struct gdbarch *gdbarch, > CORE_ADDR pc, CORE_ADDR current_pc, > struct i386_frame_cache *cache) > { > + pc = i386_skip_endbr (pc); > pc = i386_skip_noop (pc); > pc = i386_follow_jump (gdbarch, pc); > pc = i386_analyze_struct_return (pc, current_pc, cache); > -- > 2.20.1 Hi Victor, I hadn't realized that this instriction also existed in the 32 bit variant. The patch looks fine, but is just missing a test. You could maybe adapt gdb.arch/amd64-prologue-skip-cf-protection.exp so that it runs on i386 as well? If so, I'd rename it from amd64- to i386-, like there are other tests running on both amd64 and i386 that are prefixed i386. It's not great, but at least it would be consistent. Simon