From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id wbUfKWLWwGqgFy8AWB0awg (envelope-from ) for ; Sat, 03 Oct 2026 06:18:10 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=PFF02kI+; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id A06D21E050; Sat, 03 Oct 2026 06:18:10 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 006671E04E for ; Sat, 03 Oct 2026 06:18:07 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 08E064BA902A for ; Sat, 3 Oct 2026 10:18:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 08E064BA902A Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=PFF02kI+ Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id CAD734BA79A3 for ; Sat, 3 Oct 2026 10:17:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CAD734BA79A3 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CAD734BA79A3 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791022660; cv=none; b=eDtAfbCMmseGK4wx2BB1L0S+0riJXo3yaiYVGO66VyHYudoY42C/PXFhLWM7mHG3HfUBqtdew2zKhiBuA14Lpi17/g4GzZFI2u+ruWISNxNhEyOIp3rMGWatEhMQjbabNueJSDe1DH6T2i2XL3cfLgnpY4ZKJr9fNtExlzmuxrY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791022660; c=relaxed/simple; bh=VpS1i4C2h4JAL7W7QMy+PJquUQZU6Jqw8OO3XbFnfCw=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=gLI96btHBU376A3+2skB/iVxac4b+uErL6wVnUYiJlKb0LKlJ44JEZybawMnYtmY+teFepyWx2CTvRzFGA2ArtmK8lMdlTnmcWk69Gpq2DQvzTu6/6wiSWKMAHpWZppq/0oiEsFehZ+k2+fBilj2GP+wBHrRdDVEJnmdcmlXYJ0= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=PFF02kI+ DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CAD734BA79A3 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4a0286c981dso4441355e9.2 for ; Sat, 03 Oct 2026 03:17:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1791022659; x=1791627459; darn=sourceware.org; h=content-transfer-encoding:content-type:in-reply-to:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to:content-type; bh=nunX0opSCO8N3hvsAE63ZJhIOPu32vCSuLFsFumEvIw=; b=PFF02kI+aCdNGG4kkEvYZvG0R0jYzD85WWKPnsdeqr6J+Y6VhdX0Kc9bDZQ7eraAzI UOoq2hLJYwjqfKUZzC54rVTqfS1Oo6mN7PTi4g5Ed2ukoLU9fzSYJhP35scldhMlMZwi 0MtxGrK1u1Re4TQRHGw0mDqvhow9sjazQ3QhyaCBvRxwVDudMnyMFIHMGpTbHEmA0ueF so5P9eUulaepZD9sc8oEEbQt60Tkp1DggCO4xYQyBhIhNudShbVL0zrcU3Wdt5vy8LXE hMQ8u6qFzgRd4scHBveesQi7bgW2bj8PYkW1O+x2cc6IfEMK0/WltjCmOYD5UGg2G9l2 XkuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791022659; x=1791627459; h=content-transfer-encoding:content-type:in-reply-to:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=nunX0opSCO8N3hvsAE63ZJhIOPu32vCSuLFsFumEvIw=; b=Vbvko5jwB7duLKXW5PU9EWHD2Akch6Ivf7C+1c5JlKZ2ODr5X+QlJ6m0OrxyP1ErXa iGLBmm7slZUbBuEHYapQjR4ccoy1NJT0SC/yl2ZmVoH19giBQPeaZZPcF7Yf4o+pzPTN trKMKbLUvfbVjY3GwhqwwiYKNgkXVkVhI+wUrSezUKoR4BQy9smWu1u+/HHO7p2v7qsk roorXBfgDtBzyjw7c0TkTLxOfO+2Z4/EXjIv2ffJn29gfNsdPLqaRcB6+kMV6UOMoPOF OcmvppvC2IRGNO1HKCQTxamPQzN3uaqMdkiAbF1thoKAa+gcHOCXkqweg+nmHRW6NH0S X/Pw== X-Forwarded-Encrypted: i=1; AKwUvBydRD7fky9ZGAWWzRGEEKJ8IK6YI4AaTyfjTWto59SFuRKBK/mdA1v6y229PuBRnUjQ0v67vbOlic+TWg==@sourceware.org X-Gm-Message-State: AFuF++l1p+nIXLxM1f2Q6q5ous3uJRSn4dmvGpmahC63MOmmbjwLcmzl ZsUJYDmc3yeWHBF8mZyDpEabs09DN4bxDOfKl1wW3BXOx5n5T3Q+nivbTYpfEE9y X-Gm-Gg: AYBFou2BWx6bBJnvKAgem0lS5cN8GZ+yZ4iUhHTpfa+oIEhSWDFUQRkkCd/3MTTNQKn S5gPQ6hyogEAStLsZs8o1EP6DQpK2Jqct41FUPJ+bP+QgCgvYkHWinQIVOpxWCJFYHK9Al+aX7m E3keAkn6MRo0+sg7oec79p+2V5vhtOn6p0M0/50kMBMo7+2q8aQ7nimNBrlbleMW4ycqPGU2zns eBo8uu9fu2xkngZg9GP6Bu3ZhjW3VkT4/lGu1WJvbTkpWB9kaRsOv316E+Q0Af/cjAyG4a2szVv /BUHBSqYxCu+xxNCYDkS7Ue1EIzySSDPBTfYNEA6sHUk8a88gutksWCsRNf83UrnF0d3AXp/few Xn5SLpEh8CcONenXIu/wbPodw6lGSp/PmtIZpS/3DmYqFVRpajv501l+3Ux7WsgEQAT/doudxZg fAsnJyCnGhXUO/z27TINkjIIbbt8dMxGtfb1F54Oq2lkqFBitt5oTHOG6HOAIED+FfJFUeSSFKz un1ozK1sw== X-Received: by 2002:a05:600c:6387:b0:49f:c1a1:5222 with SMTP id 5b1f17b1804b1-4a168105db2mr27931315e9.33.1791022658499; Sat, 03 Oct 2026 03:17:38 -0700 (PDT) Received: from [192.168.0.39] ([86.12.57.161]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a027f2a4c4sm170967755e9.2.2026.10.03.03.17.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 03 Oct 2026 03:17:38 -0700 (PDT) Message-ID: <318696f3-58db-4d5a-a3db-b785acbcefc2@gmail.com> Date: Sat, 3 Oct 2026 11:17:37 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] gdb/aarch64: Step through GNU ld's erratum 843419 veneers Content-Language: en-US To: cocolato , gdb-patches@sourceware.org References: From: Luis In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 Hi, Thanks for the patch. Before I review it, do you have a copyright assignment on file to be able to contribute this change? Otherwise we might not be able to accept it, as we currently don“t accept DCO-style contributions. On 30/09/2026 06:49, cocolato wrote: > GNU ld's Cortex-A53 erratum 843419 workaround can move an instruction > into an e843419@ veneer. A plain branch replaces the original > instruction; the veneer executes it and branches back to the next > instruction in the same function. Neither branch updates the link > register. > > When next or finish from an inline frame enters the veneer, GDB can > mistake it for a function call. With no veneer unwind information, GDB > can use an earlier call's return address from the link register for a > step-resume breakpoint, running the inferior to completion instead of > stopping after the inline function. > > Recognize GNU ld's named e843419@ veneers through the existing > in_indirect_branch_thunk hook, before subroutine-entry handling. > Recognize both veneer instructions; minimal-symbol lookup already > checks the bounds of GNU ld's sized symbols. Stripped veneer symbols > remain unsupported. > > skip_trampoline_code is too late on the forward STEP_OVER_ALL path: > GDB has already set the caller-return breakpoint and returned. The > existing hook needs no generic stepping changes or instruction decoding. > > The assembly and DWARF regression test exercises next and inline finish > using explicitly defined veneer instructions and symbols. It reproduces the > GDB stepping bug without a Cortex-A53 CPU or the hardware erratum, > independent of compiler optimization and linker sequence detection. > A call to helper leaves a stale link register before entering the > veneer, which has no debug or unwind information. The assertions check > the initial inline backtrace, returned source line, and exact stop > address. > > To reproduce on a native AArch64 ELF target: > > 1. Build GDB at the base commit below and retain its executable and > data-directory. Apply this patch and build the patched GDB. > 2. From the patched build's gdb/testsuite directory, run the same test > with each GDB. Use absolute executable and data-directory paths: > > make check \ > RUNTESTFLAGS="GDB=/path/to/gdb \ > GDBFLAGS=--data-directory=/path/to/data-directory \ > gdb.arch/aarch64-erratum-843419-veneer.exp" > > Save gdb.sum and gdb.log after each run; the next run overwrites them. > > Recorded next sessions (patched source path shortened): > > Before: > (gdb) next > [Inferior 1 (process 46367) exited normally] > (gdb) p $pc == (void *) &inline_high > No registers. > > After: > (gdb) next > outer () at .../aarch64-erratum-843419-veneer.S:58 > 58 /* Outer after inline. */ > (gdb) p $pc == (void *) &inline_high > $1 = 1 > > finish likewise changes from normal inferior exit to stopping at > inline_high in outer. The new test changes from 4 PASS and 4 FAIL to > 8 PASS and no FAIL. > > Tested on native aarch64-unknown-linux-gnu in an Ubuntu 26.04 container, > with GCC 15.2.0, GNU ld 2.46, and GDB 19.0.50.20260929-git. > Base commit: 4ba6bd8393418b63dc3efa0ec6f934903a10f140. > These eight existing test files stayed at 241 PASS and no FAIL in both > runs: > > gdb.arch/aarch64-prologue.exp > gdb.arch/aarch64-unwind-pc.exp > gdb.opt/inline-cmds.exp > gdb.opt/inline-bt.exp > gdb.dwarf2/dw2-inline-stepping.exp > gdb.base/finish.exp > gdb.base/step-over-no-symbols.exp > gdb.base/step-line.exp > > A rerun after comment-only cleanup also gave 8 PASS and no FAIL. > The full GDB testsuite and other targets were not tested. > > CPython issue #157965 reports layout-sensitive failures in > test_bt_unwinds_from_inside_jit_executor on AArch64 release builds. > Later main builds did not consistently reproduce them, so the standalone > fixture is the regression test. > > A separate check used a preserved CPython binary with a GNU ld-generated > e843419@ veneer and PYTHON_JIT=0. Before the fix, finish ran the inferior > to exit and bt reported "No stack." With the fix, it stopped in > mro_invoke with a valid backtrace. This used an existing binary; current > CPython main was not rebuilt and the issue's JIT test was not rerun. > > Related report: https://github.com/python/cpython/issues/157965 > --- > This is my first contribution to GDB. I have not completed an FSF > copyright assignment. Could you please point me to the appropriate form? > > gdb/aarch64-tdep.c | 16 +++ > .../gdb.arch/aarch64-erratum-843419-veneer.S | 84 +++++++++++++ > .../aarch64-erratum-843419-veneer.exp | 111 ++++++++++++++++++ > 3 files changed, 211 insertions(+) > create mode 100644 gdb/testsuite/gdb.arch/aarch64-erratum-843419-veneer.S > create mode 100644 gdb/testsuite/gdb.arch/aarch64-erratum-843419-veneer.exp > > diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c > index 950ad4f6..9e1b5612 100644 > --- a/gdb/aarch64-tdep.c > +++ b/gdb/aarch64-tdep.c > @@ -34,6 +34,7 @@ > #include "frame-base.h" > #include "trad-frame.h" > #include "objfiles.h" > +#include "symtab.h" > #include "dwarf2.h" > #include "dwarf2/frame.h" > #include "gdbtypes.h" > @@ -4158,6 +4159,19 @@ aarch64_cannot_store_register (struct gdbarch *gdbarch, int regnum) > && regnum < tdep->pauth_reg_base + tdep->pauth_reg_count); > } > > +/* Implement the in_indirect_branch_thunk gdbarch method. GNU ld's > + Cortex-A53 erratum 843419 veneers branch back into the same function, > + so step through them rather than treating them as function calls. */ > + > +static bool > +aarch64_in_indirect_branch_thunk (gdbarch *, CORE_ADDR pc) > +{ > + bound_minimal_symbol minsym = lookup_minimal_symbol_by_pc (pc); > + > + return (minsym.minsym != nullptr > + && startswith (minsym.minsym->linkage_name (), "e843419@")); > +} > + > /* Implement the stack_frame_destroyed_p gdbarch method. */ > > static bool > @@ -4788,6 +4802,8 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) > aarch64_breakpoint::bp_from_kind); > set_gdbarch_have_nonsteppable_watchpoint (gdbarch, true); > set_gdbarch_get_next_pcs (gdbarch, aarch64_software_single_step); > + set_gdbarch_in_indirect_branch_thunk (gdbarch, > + aarch64_in_indirect_branch_thunk); > > /* Information about registers, etc. */ > set_gdbarch_sp_regnum (gdbarch, AARCH64_SP_REGNUM); > diff --git a/gdb/testsuite/gdb.arch/aarch64-erratum-843419-veneer.S b/gdb/testsuite/gdb.arch/aarch64-erratum-843419-veneer.S > new file mode 100644 > index 00000000..e14a0d14 > --- /dev/null > +++ b/gdb/testsuite/gdb.arch/aarch64-erratum-843419-veneer.S > @@ -0,0 +1,84 @@ > +/* Copyright 2026 Free Software Foundation, Inc. > + > + This file is part of GDB. > + > + 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 . */ > + > +/* Calling helper leaves a stale link register. The veneer has no debug > + or unwind information. */ > + .text > + .global main > + .type main, %function > +main: > + .cfi_startproc > + stp x29, x30, [sp, -16]! > + .cfi_def_cfa_offset 16 > + .cfi_offset x29, -16 > + .cfi_offset x30, -8 > + mov x29, sp > + bl outer > + mov w0, 0 > + ldp x29, x30, [sp], 16 > + .cfi_def_cfa_offset 0 > + .cfi_restore x29 > + .cfi_restore x30 > + ret > + .cfi_endproc > + .size main, .-main > + > + .global outer > + .type outer, %function > +outer: > + .cfi_startproc > + stp x29, x30, [sp, -16]! > + .cfi_def_cfa_offset 16 > + .cfi_offset x29, -16 > + .cfi_offset x30, -8 > + mov x29, sp > + mov x0, sp > + > + /* Outer call line. */ > + /* Inline body line. */ > + .global inline_low > +inline_low: > + bl helper > + b .Lveneer > + > + /* Outer after inline. */ > + .global inline_high > +inline_high: > + ldp x29, x30, [sp], 16 > + .cfi_def_cfa_offset 0 > + .cfi_restore x29 > + .cfi_restore x30 > + ret > + .cfi_endproc > + .global outer_end > +outer_end: > + .size outer, .-outer > + > +helper: > + ret > + > + .type "e843419@0000_00000000_0000", %function > +"e843419@0000_00000000_0000": > +.Lveneer: > + ldr x2, [x0] > + b inline_high > + .size "e843419@0000_00000000_0000", .-.Lveneer > + > + .global program_end > +program_end: > + > + .section .note.GNU-stack,"",%progbits > diff --git a/gdb/testsuite/gdb.arch/aarch64-erratum-843419-veneer.exp b/gdb/testsuite/gdb.arch/aarch64-erratum-843419-veneer.exp > new file mode 100644 > index 00000000..67a76052 > --- /dev/null > +++ b/gdb/testsuite/gdb.arch/aarch64-erratum-843419-veneer.exp > @@ -0,0 +1,111 @@ > +# Copyright 2026 Free Software Foundation, Inc. > + > +# This file is part of GDB. > + > +# 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 . > + > +# Test stepping over a Cortex-A53 erratum 843419 veneer in an inline function. > +# Fixed instructions and debug information avoid dependence on compiler > +# optimizations or linker layout. > + > +load_lib dwarf.exp > + > +require is_aarch64_target > +require is_elf_target > +require dwarf2_support > + > +standard_testfile .S -dw.S > + > +set outer_call_line [gdb_get_line_number "Outer call line"] > +set inline_line [gdb_get_line_number "Inline body line"] > +set outer_after_line [gdb_get_line_number "Outer after inline"] > + > +set dwarf_asm [standard_output_file $srcfile2] > +Dwarf::assemble $dwarf_asm { > + global srcdir subdir srcfile > + global outer_call_line inline_line outer_after_line > + > + declare_labels lines_label inline_subprogram > + > + cu {} { > + compile_unit { > + DW_AT_language @DW_LANG_C > + DW_AT_name $srcfile > + DW_AT_stmt_list $lines_label DW_FORM_sec_offset > + DW_AT_low_pc main addr > + DW_AT_high_pc program_end addr > + } { > + inline_subprogram: subprogram { > + DW_AT_name inline_func > + DW_AT_inline 3 data1 > + } > + subprogram { > + DW_AT_name outer > + DW_AT_low_pc outer addr > + DW_AT_high_pc outer_end addr > + } { > + inlined_subroutine { > + DW_AT_abstract_origin %$inline_subprogram > + DW_AT_low_pc inline_low addr > + DW_AT_high_pc inline_high addr > + DW_AT_call_file 1 data1 > + DW_AT_call_line $outer_call_line data1 > + } > + } > + } > + } > + > + lines {version 2} lines_label { > + include_dir "$srcdir/$subdir" > + file_name "$srcfile" 1 > + > + program { > + DW_LNE_set_address outer > + line $outer_call_line > + DW_LNS_copy > + # Describe the inline call site before the inline function's body. > + DW_LNE_set_address inline_low > + line $outer_call_line > + DW_LNS_copy > + DW_LNE_set_address inline_low > + line $inline_line > + DW_LNS_copy > + DW_LNE_set_address inline_high > + line $outer_after_line > + DW_LNS_copy > + DW_LNE_set_address outer_end > + DW_LNE_end_sequence > + } > + } > +} > + > +if { [prepare_for_testing "failed to prepare" $testfile \ > + [list $srcfile $dwarf_asm] {nodebug nopie}] } { > + return > +} > + > +foreach_with_prefix command {next finish} { > + if { ![runto_main] } { > + return > + } > + > + gdb_breakpoint "*inline_low" > + gdb_continue_to_breakpoint "inline function" > + > + gdb_test "bt" "#0 inline_func.*#1 outer.*#2 .*main.*" \ > + "backtrace in inline function" > + gdb_test $command "Outer after inline.*" "step through erratum veneer" > + gdb_test {p $pc == (void *) &inline_high} " = 1" \ > + "stopped after inline function" > +} > > base-commit: 4ba6bd8393418b63dc3efa0ec6f934903a10f140