From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id iSjfODoU5WrjdxkAWB0awg (envelope-from ) for ; Fri, 30 Oct 2026 18:03:38 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=XDkhmYFc; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id E2D60378006; Fri, 30 Oct 2026 18:03:38 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 08790378002 for ; Fri, 30 Oct 2026 18:03:38 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 248134BAE7CD for ; Fri, 30 Oct 2026 22:03:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 248134BAE7CD Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=XDkhmYFc Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by sourceware.org (Postfix) with ESMTPS id E98F84BAE7DD for ; Fri, 30 Oct 2026 22:02:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E98F84BAE7DD Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E98F84BAE7DD Authentication-Results: sourceware.org; arc=none smtp.remote-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793397742; cv=none; b=HjhS9tjze64uYobKfrsDaIM6+X6GvdR0iI03FwCAAh8lhdl5JHVg9jb8OVS6waoyEf+ZWuwOmgvmLy3NstCZLQHhIRx/H2+fSa7GUaA86zQJgaR6wBa9kALnDCIUaJH8bR4Jk+ZAvC3RgLp6YfAyQOnFivZddI2FNAh+/qA5ym4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793397742; c=relaxed/simple; bh=4GYoRAuaHrwqGflDsT4i/zAwRBrM+/3kvjwiBmcuYGY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=pdC8TYLgfZX13ON9Nvc72SFcJz+g4b4/IzN1oAbRac0HAkSLWWuG8qqtu4xjnnCXmsng9wOI2DSaHmwIhUIc+M6yOS1rfzpyaDtYze8L8M08tBStQx/yoWAXFJoIxIkhKtJaXBTmbgfNLRpYad0jc0M0t8Bt1y8nQrSo+LT+gwQ= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=XDkhmYFc DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E98F84BAE7DD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1793397743; x=1824933743; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=4GYoRAuaHrwqGflDsT4i/zAwRBrM+/3kvjwiBmcuYGY=; b=XDkhmYFc/31UitPtp8hdSmxLO2SCktLzKuLEwa11NsyGW8W3gdDFva3d Ht7YZ0SHT0KdVT2cRpTA6/4ANTb8CYw/M9G7lOVjw8Js1aT/MRguyNlj1 x/3H5vR62sW40v10Xbbbqaibq9rE64NXSlNM+XsN34ofh3C79dBtoQQKM j6PqmwuFKeWxJ7Uo5xeklFL70wj2TFemNDNqN+ohFe3pYuC58H8ruVvjT bjPi4enniNeKgag/Jn00tCTHZoFBLmgrxRKsgcNFYS+X3ymtXg/BHF60k 6vman1L8O6THwsvBMPLM4JHUD6wT+gwdLNkP29Lz+IZPSMO/HAfRNj/or A==; X-CSE-ConnectionGUID: pO0Gkt/tRdmH0vdmAHhk0g== X-CSE-MsgGUID: zyYRSKpBTHCyETWvzD6xnA== X-IronPort-AV: E=McAfee;i="6800,10657,11951"; a="2062194" X-IronPort-AV: E=Sophos;i="6.27,186,1787036400"; d="scan'208";a="2062194" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Oct 2026 15:02:21 -0700 X-CSE-ConnectionGUID: k+KeLtUTSUO483NDJZlBDg== X-CSE-MsgGUID: NoeZT2kRQvCSl+vr4oBxmQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,186,1787036400"; d="scan'208";a="5631187" Received: from dut1048pvc.igk.intel.com (HELO localhost) ([10.211.177.228]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Oct 2026 15:02:20 -0700 From: Stephan Rohr To: gdb-patches@sourceware.org Subject: [PATCH 2/2] gdb/amd64: recognize pushp %rbp as a frame setup Date: Fri, 30 Oct 2026 22:02:01 +0000 Message-ID: <20261030220201.2288060-3-stephan.rohr@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261030220201.2288060-1-stephan.rohr@intel.com> References: <20261030220201.2288060-1-stephan.rohr@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Klaus Gerlicher With PPX enabled, clang and icpx start a frame pointer prologue with pushp %rbp (REX2 prefix with W set) where GCC emits push %rbp. amd64_analyze_frame_setup only knew push %rbp, so it did not see the frame setup. "break FUNC" on a function without debug info then stopped at the first instruction instead of after the prologue. Extend amd64_analyze_frame_setup to support pushp %rbp. As GCC emits push %rbp, test it with the assembly clang 20.1 generates from amd64-apx-extended-prologue-analysis.c. Tested on Diamond Rapids. --- gdb/amd64-tdep.c | 25 +++- ...d64-apx-extended-prologue-analysis-clang.S | 139 ++++++++++++++++++ .../amd64-apx-extended-prologue-analysis.c | 7 +- .../amd64-apx-extended-prologue-analysis.exp | 14 +- 4 files changed, 176 insertions(+), 9 deletions(-) create mode 100644 gdb/testsuite/gdb.arch/amd64-apx-extended-prologue-analysis-clang.S diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c index c43ffca7b8b..0bf9ba49bb8 100644 --- a/gdb/amd64-tdep.c +++ b/gdb/amd64-tdep.c @@ -2687,11 +2687,30 @@ amd64_analyze_frame_setup (gdbarch *gdbarch, CORE_ADDR pc, bfd_endian byte_order = gdbarch_byte_order (gdbarch); gdb_byte buf[3]; gdb_byte op = read_code_unsigned_integer (pc, 1, byte_order); + const CORE_ADDR start_pc = pc; + + /* With a REX2 prefix (Intel APX), 0x55 is also "push %rbp", or + "pushp %rbp" with the PPX hint. */ + if (rex2_prefix_p (op)) + { + gdb_byte payload = read_code_unsigned_integer (pc + 1, 1, byte_order); + + /* 0x55 is push in opcode map 0, so REX2.M0 must be zero, and + REX2.B4 and REX2.B3 must be zero, as they extend the register + number in the opcode. REX2.W is the PPX hint of pushp, and the + other bits do not affect push. */ + const gdb_byte rex2_mask = (REX2_M << 4) | (REX_B << 4) | REX_B; + if ((payload & rex2_mask) != 0) + return start_pc; + + pc += 2; + op = read_code_unsigned_integer (pc, 1, byte_order); + } if (op == 0x55) /* pushq %rbp. */ { - /* Take into account that we've executed the `pushq %rbp' that - starts this instruction sequence. */ + /* Take into account that we've executed the `pushq %rbp' or + `pushp %rbp' that starts this instruction sequence. */ cache->saved_regs[AMD64_RBP_REGNUM] = 0; cache->sp_offset += 8; @@ -2725,7 +2744,7 @@ amd64_analyze_frame_setup (gdbarch *gdbarch, CORE_ADDR pc, return pc + 1; } - return pc; + return start_pc; } /* Check whether PC points at code pushing registers onto the stack. If so, diff --git a/gdb/testsuite/gdb.arch/amd64-apx-extended-prologue-analysis-clang.S b/gdb/testsuite/gdb.arch/amd64-apx-extended-prologue-analysis-clang.S new file mode 100644 index 00000000000..8e87b108e80 --- /dev/null +++ b/gdb/testsuite/gdb.arch/amd64-apx-extended-prologue-analysis-clang.S @@ -0,0 +1,139 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2025-2026 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* This file is compiled from gdb.arch/amd64-apx-extended-prologue-analysis.c + using clang 20.1.2 with flags: -g0 -O1 -S + -mapx-features=egpr,push2pop2,ppx -mgeneral-regs-only + -fno-omit-frame-pointer -fno-asynchronous-unwind-tables -fno-addrsig. */ + + .file "amd64-apx-extended-prologue-analysis.c" + .text + .globl bar # -- Begin function bar + .p2align 4 + .type bar,@function +bar: # @bar +# %bb.0: + pushp %rbp + movq %rsp, %rbp + # kill: def $edi killed $edi def $rdi + leal (%rdi,%rdi), %eax + popp %rbp + retq +.Lfunc_end0: + .size bar, .Lfunc_end0-bar + # -- End function + .globl foo # -- Begin function foo + .p2align 4 + .type foo,@function +foo: # @foo +# %bb.0: + pushp %rbp + movq %rsp, %rbp + push2p %r14, %r15 + push2p %r12, %r13 + pushp %rbx + subq $264, %rsp # imm = 0x108 + movl %ecx, %r14d + movl %edx, %r15d + movl %esi, %r12d + movl %edi, %ebx + movl %edi, %edi + xorl %eax, %eax + .p2align 4 +.LBB1_1: # =>This Inner Loop Header: Depth=1 + leal (%rdi,%rax), %ecx + movb %cl, -304(%rbp,%rax) + incq %rax + cmpq $256, %rax # imm = 0x100 + jne .LBB1_1 +# %bb.2: + # kill: def $edi killed $edi killed $rdi + callq bar + movl %eax, %r13d + movl %r12d, %edi + callq bar + movl %eax, %r12d + movl %r15d, %edi + callq bar + movl %eax, %r15d + movl %r14d, %edi + callq bar + addl %ebx, %r13d + addl %r12d, %r15d + addl %r13d, %r15d + addl %r15d, %eax + addq $264, %rsp # imm = 0x108 + popp %rbx + pop2p %r13, %r12 + pop2p %r15, %r14 + popp %rbp + retq +.Lfunc_end1: + .size foo, .Lfunc_end1-foo + # -- End function + .globl nocsr # -- Begin function nocsr + .p2align 4 + .type nocsr,@function +nocsr: # @nocsr +# %bb.0: + pushp %rbp + movq %rsp, %rbp + push2p %r10, %r11 + push2p %r8, %r9 + push2p %rdx, %rsi + pushp %rcx + pushq %rax + callq bar + addq $8, %rsp + popp %rcx + pop2p %rsi, %rdx + pop2p %r9, %r8 + pop2p %r11, %r10 + popp %rbp + retq +.Lfunc_end2: + .size nocsr, .Lfunc_end2-nocsr + # -- End function + .globl main # -- Begin function main + .p2align 4 + .type main,@function +main: # @main +# %bb.0: + pushp %rbp + movq %rsp, %rbp + pushp %rbx + pushq %rax + movl %edi, %ebx + leal 1(%rbx), %esi + leal 2(%rbx), %edx + leal (%rbx,%rbx), %ecx + callq foo + movl %eax, %ecx + movl %ebx, %edi + callq nocsr + addl %ecx, %eax + movl %eax, -12(%rbp) + movl -12(%rbp), %eax + addq $8, %rsp + popp %rbx + popp %rbp + retq +.Lfunc_end3: + .size main, .Lfunc_end3-main + # -- End function + .ident "Ubuntu clang version 20.1.2 (0ubuntu1~24.04.3)" + .section ".note.GNU-stack","",@progbits diff --git a/gdb/testsuite/gdb.arch/amd64-apx-extended-prologue-analysis.c b/gdb/testsuite/gdb.arch/amd64-apx-extended-prologue-analysis.c index ee137e7845d..1f2642b5ec7 100644 --- a/gdb/testsuite/gdb.arch/amd64-apx-extended-prologue-analysis.c +++ b/gdb/testsuite/gdb.arch/amd64-apx-extended-prologue-analysis.c @@ -39,7 +39,8 @@ bar (int x) push2p pushes its second register first. Without a frame pointer, a single pushp comes first, to align the stack for push2p. With only - EGPR enabled, the registers are saved with push. + EGPR enabled, the registers are saved with push, and clang starts the + frame setup with pushp %rbp. So to be able to unwind a register, GDB needs to skip the prologue past the register pushes and stack allocation (to access .cfi @@ -78,7 +79,9 @@ foo (int a, int b, int c, int d) Without a frame pointer, a single pushp comes first, to align the stack for push2p. With only EGPR enabled, the 24 registers are saved with - single pushes, more than there are legacy GPRs. */ + single pushes, more than there are legacy GPRs. clang starts the frame + setup with pushp %rbp, does not save %r16 - %r31, and pushes %rax only + to align the stack. */ __attribute__ ((noinline, no_caller_saved_registers)) int nocsr (int x) { diff --git a/gdb/testsuite/gdb.arch/amd64-apx-extended-prologue-analysis.exp b/gdb/testsuite/gdb.arch/amd64-apx-extended-prologue-analysis.exp index ccc8a134bf8..d9e45d2c29d 100644 --- a/gdb/testsuite/gdb.arch/amd64-apx-extended-prologue-analysis.exp +++ b/gdb/testsuite/gdb.arch/amd64-apx-extended-prologue-analysis.exp @@ -36,6 +36,9 @@ # - single pushes of %r16 - %r31: with only EGPR enabled, the compiler saves # the registers of nocsr with more than 16 single pushes. # +# - pushp frame setup: with PPX enabled, clang starts the frame setup with +# pushp %rbp instead of push %rbp.# +# # As in amd64-extended-prologue-analysis.exp, each case is tested with a # binary compiled from the C source, and with a binary assembled from the # assembly generated from it. The assembly keeps testing the prologues the @@ -43,13 +46,13 @@ require allow_apx_tests -standard_testfile .c -no-cfi.S .S -offset.S -egpr.S +standard_testfile .c -no-cfi.S .S -offset.S -egpr.S -clang.S # Return {HAS_FRAME END REGS} for the prologue of FUNC, read from its # disassembly: whether it has a frame pointer setup, the address after the # prologue and the registers it saves, in push order. The prologue is an -# optional endbr64, an optional push %rbp followed by mov %rsp,%rbp, the -# register pushes and an optional sub from %rsp. +# optional endbr64, an optional push or pushp of %rbp followed by +# mov %rsp,%rbp, the register pushes and an optional sub from %rsp. proc prologue_info { func } { set insns {} gdb_test_multiple "disassemble $func" "" -lbl { @@ -71,7 +74,7 @@ proc prologue_info { func } { set has_frame 0 set regs {} - if { [lindex $insns $i 1] eq "push %rbp" + if { [regexp {^pushp? %rbp$} [lindex $insns $i 1]] && [lindex $insns [expr {$i + 1}] 1] eq "mov %rsp,%rbp" } { set has_frame 1 lappend regs rbp @@ -169,6 +172,9 @@ set cases [list \ {-mapxf -fomit-frame-pointer -fno-asynchronous-unwind-tables} 0 \ "single pushes of %r16 - %r31" $srcfile5 \ {-mapx-features=egpr -fno-omit-frame-pointer \ + -fno-asynchronous-unwind-tables} 0 \ + "pushp frame setup" $srcfile6 \ + {-mapx-features=egpr,push2pop2,ppx -fno-omit-frame-pointer \ -fno-asynchronous-unwind-tables} 0] set n 0 -- 2.43.0 ________________________________________ Intel Deutschland GmbH Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 (89) 99143-0 www.intel.de Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman Chairperson of the Supervisory Board: Sonja Pierer Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.