bfd: Fix addr2line for skipped DW_FORM_ref_addr CUs and DWARF5 one-file line tables
| Message ID | CY8PR12MB734051E88B8DF63612A2EA8F87692@CY8PR12MB7340.namprd12.prod.outlook.com |
|---|---|
| State | New |
| Headers |
Return-Path: <binutils-bounces~patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D12514BA2E3E for <patchwork@sourceware.org>; Tue, 3 Nov 2026 16:51:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D12514BA2E3E Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=JRRVwicv X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from SN4PR0501CU005.outbound.protection.outlook.com (mail-southcentralusazon11011018.outbound.protection.outlook.com [40.93.194.18]) by sourceware.org (Postfix) with ESMTPS id 768F44BA7991 for <binutils@sourceware.org>; Tue, 3 Nov 2026 16:50:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 768F44BA7991 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=amd.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 768F44BA7991 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=40.93.194.18 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1793724627; cv=pass; b=atWXj1cZ61OybvNBvp78qCPUbKwrbus+9O+2bzshCnfUmSOr2aKLTP7LE7Q3ztZXlfzrbYocHtgANicpax5vAhY8pH/V6ZVYa9QiK533hEHkk1yTZue58i/JK3hUL8IUw4GZlkNNlsKT5taikuZBSfdkzFD8EwFW4Xj00GX80K0= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1793724627; c=relaxed/simple; bh=AvqkNAmh9elwljSEBdw6c5o8ln1LCo4LaNWt2Hv3psQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=InNxLFNXqv+yMDDxa8k197PAyzf7aqUfMqg0XoSnj2FmFggsKUpMXOthFbmMhRbP4J1DqKR+mEC4IRi9mUpVs/1Owgdfe6zEo7OX5nTsmR6L/233H3Tz1NSH2LEhjBYSEuMCPKLtk6dRcCVnkPE58QhYttqREH69gMQ0xHs1TQg= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=JRRVwicv DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 768F44BA7991 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Duc76ehqm1eWop39Nr9Ntw02kJ8VRdyf2wWOTeEsxsR9IktUvayO42L3UgUPjiOsLyo1CmYAI0TfY8YADVEelCpXI2CBkU/ZM+fSnHF8WKJF/p/BgilJSkJMS0nNUhUn2wz7Lxv+/26e5V0S/ZdNA7rDWbFedj3/WgTk6HN/QjqaoIMHeg/CSiNj9Ts3zs7alo7Alr1pBrcpHFcyXZI/LNEkIzXDRc9SOFZSe74hBfktJ+0tIiBZ+OCzDnoKEqETENhrz4/DlSeSuHuCgaC7+/n5oCg2NFPn2ae+cbEBDfEx1mL4uUiBQ/Rp13zl+XNKd+u+TnTAPu9GCtgyqb+viQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=m91uprahb+KUOpvnXwZo/l4yvvYnoWWctcmXPJKAodk=; b=lUrb/h5HQWYZWoaKmCjTFpbnFkrT7NjNTuB/LXMjko4QRziVzdUr2Oke+V2URsEO6nG1Q4bARSDGQrf4GeuN8OtvIe+bqtM/gCd6H4f9rD1oktJeDIObbqPf4hwTIrqeAzfC5kKC08C7Oq27lNulz4eOcv0Dr407BQD+jaVGc5mm98xe2D9k1YtyKNNECjGy//JUf4068nLh/C6HGGqwDo2nlZxYZWcbH+/2FdqljdRlbtzLSIZRK3aZUrgGxAB1LZJ9rcmQRnw4/ZdwFLg66tnc+y19GmkJW8QRm4c8Wu4E9J/mRWseY/ZAw8/nV/sSju1Lf+70ETsG8spTx2hGtw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=m91uprahb+KUOpvnXwZo/l4yvvYnoWWctcmXPJKAodk=; b=JRRVwicvFm8UyirdfLARgRHrvlGhydkxh1apb3AFgcg/nnvFPBkCdvrpnY/NJWeTZxu4SjtToAsF1oebea9Ev6UexascIj6hqB81dLWq2tvAm30z8xvEp+DXQFFJJs037DcZg0KjMg1Jh4S+SN3N3CwMPP6VzdMR2W1+HCVB85U= Received: from CY8PR12MB7340.namprd12.prod.outlook.com (2603:10b6:930:50::16) by DM4PR12MB6109.namprd12.prod.outlook.com (2603:10b6:8:ae::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.546.16; Tue, 3 Nov 2026 16:50:23 +0000 Received: from CY8PR12MB7340.namprd12.prod.outlook.com ([fe80::aa7b:2158:b9ed:d2a]) by CY8PR12MB7340.namprd12.prod.outlook.com ([fe80::aa7b:2158:b9ed:d2a%6]) with mapi id 15.21.0592.007; Tue, 3 Nov 2026 16:50:22 +0000 From: "Kumar N, Bhuvanendra" <Bhuvanendra.KumarN@amd.com> To: "binutils@sourceware.org" <binutils@sourceware.org> CC: "George, Jini Susan" <JiniSusan.George@amd.com> Subject: [PATCH] bfd: Fix addr2line for skipped DW_FORM_ref_addr CUs and DWARF5 one-file line tables Thread-Topic: [PATCH] bfd: Fix addr2line for skipped DW_FORM_ref_addr CUs and DWARF5 one-file line tables Thread-Index: Ad1rsghiWntc7X8UQ9etbFls1GyC2A== Date: Tue, 3 Nov 2026 16:50:22 +0000 Message-ID: <CY8PR12MB734051E88B8DF63612A2EA8F87692@CY8PR12MB7340.namprd12.prod.outlook.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: msip_labels: MSIP_Label_198e8dea-a4f3-4850-b16a-fd6d2b1302b4_Enabled=True; MSIP_Label_198e8dea-a4f3-4850-b16a-fd6d2b1302b4_SiteId=3dd8961f-e488-4e60-8e11-a82d994e183d; MSIP_Label_198e8dea-a4f3-4850-b16a-fd6d2b1302b4_SetDate=2026-11-03T16:06:36.0000000Z; MSIP_Label_198e8dea-a4f3-4850-b16a-fd6d2b1302b4_Name=AMD General v26; MSIP_Label_198e8dea-a4f3-4850-b16a-fd6d2b1302b4_ContentBits=3; MSIP_Label_198e8dea-a4f3-4850-b16a-fd6d2b1302b4_Method=Standard authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: CY8PR12MB7340:EE_|DM4PR12MB6109:EE_ x-ms-office365-filtering-correlation-id: c064dd0a-93e5-42f3-d4f2-08df39ca8d5a x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230040|6049299003|366016|1800799024|23010399003|376014|8096899003|18002099003|261026140227099003|10067099003|261028144727099003|3023799007|4053099003|38070700021|261026121527099003|261102123227099003|261022075727099003|261022105027099003|56012099006|11063799006|261009223027099003|261021123027099003|261021121427099003; x-microsoft-antispam-message-info: MUthcC+XMfIYEAjMmY7UY0270nGLxaG8yCXBoI1QlBZH3vTDY7Zc7qfn/5+kJQqMnafCDGpyetuNDij3NoyjQmQOrmUVoJakZ0HtPoWUrvuyUipn79K/tm4wfY70ucq7nsgmqRnNM9+N3/TMjgPlFzk8sbETZJgfa+L5qvHQ7n6Zj80DKLNQiEB4UYHpKlMHkBeJyB0dK7GwL76wIbIu8zQjLitYNSF88RhTCJFtvKYvPtfWUyn6l3YSbDeEL9z2X6KAWUDnqKv4PJUKYJIG349+h3mc78Q4M9OIoWJXvsr0+/kM7A0YzcbWHiuiYhtaitm0zY06vL4Yi4k6eVmJQwsc9YcsXGDTy0CHAn89fjO17k9a2jLVJs/RXNZVthfqKqQuhCOEXgHZbLEWPCwqToJx4rxUrugdjW4in7F9rjNglniBa5Lt6qptJRRp5reDihAzRaedX6PIuwUdG+J+jmn/tqoHKYPJF4mbf/TdpVF6vpXTQqwiakiOrP03FCTRFN4A6iYtlQsgAlqYwumfOQVUMAPHOwusiFahyh63NxRi/27wjIOfY3e/E5G3cqz7oT8KE3J7Y4QAIdRcSgjxr9L+5GPZgI4sKoGf5C0M5tQzifxQByRHPCjATj8q2vsqvmFXH4rcZAOVgRM5gbHT42e4Vknru74q6I3x0DL4JNsxUVzb1NX/UO6N3XAxt6upWL0ya3x3J5F8gcMf6j3KV+iQXLxJs0cU0F8t1tKeZwM= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CY8PR12MB7340.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(6049299003)(366016)(1800799024)(23010399003)(376014)(8096899003)(18002099003)(261026140227099003)(10067099003)(261028144727099003)(3023799007)(4053099003)(38070700021)(261026121527099003)(261102123227099003)(261022075727099003)(261022105027099003)(56012099006)(11063799006)(261009223027099003)(261021123027099003)(261021121427099003); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: ij5n4cdmcXUK4CzExzwv22Z91AnJjJunWMHkOTLdl+2F/o0CjzgGnmCHhOCdpOvXDc7GHZJKXveZiDMALOSELDE5F/TtXBpbjato9ABzFRybkvVvZAfSo8BzGfMZz8LYgDHz+msF0x+r5qZR3tjtf+MRmQO50J/mMD6OUCEC/iGJ7ZHQi1c0lyWQmqbvtVluhwuj5nRhQ67L++A8D1OVCPfKl+Su9ypXQ//HiTUutVqoa+XjzJ7T0B2N6zMCtkIcaDiapE+3djSNSDWvp7VR7LGZH+1afznc8ThJtztDtQJrSYqT3ie+AmP1+d9vF2pnmDGs4NtnVYvzs1CKl1/Jjuw49pnKpqR77kv7GdsbmxB7XVZ3UJdn4Wj8DWAE5m4uAyGbRmLf7ODptNnvA/Akm3GT9tODmyO0P0YCeH/bnU0sTkZMUfFjmREVCf+Q0mctrPrt77q8WqQ7I8hBhV9EXD8HKt/2H1Bc8TPttS9aBjLLYJ7HCIUcj39HgtztstYvQKbLkDlzgCAL0+QNp1WpZI0wU/QoTErzCrYWwJurU+LWjhj3BIF9wjT/IBrhHs6LH26cQUf3RqbQDLBYZjmvZQ8vGwCJsDyw3QxCWn6hFLqIbzqucJk02nvdD5TkJOb+XgUGycDH5u50qSm229+CTxmpt41AUojOyIL+CXuHKWwTG+yxClkAFubZXvn/ETJMJNR1FasPPattIbYxfM1eWKxJmE3+B2N+fc5Yye3ovyiVotvgF7pnyOw+y549iVFUbMpmJSMpmYi2uIdphwugBfZgBnDx2lvwZQZCC4dkYLGE4Ha1Y5EDQYhXGaqRqsrmoFZUzS4neChjQcU6O/gLAfa2/r6qBSWxZKLMed0MfkZGpx/cPO9qh6Bq0hzBP20ZqjNcJ/gAmzyikAxInAmTmdkvVjX9Jitm1+3Sv5zCDflUsj9I4PhGsJOVUTgtyud2GoQ002VxjkVvoQfvft5yTdcPlw3ig9O+GIOhjBLeQJgy5NoLRDg/xteUw5wsx9qjH8LQTPkrHrUgxZKFjZb2LszFhtUnFQ/REH5OaB6ti6CIo0mi7ARyScZWes13R4NeHC+Eb4CBJ0+dSk93L5deN7P+Aj3JUAFU+3fsx2O34ZdM7xEONrdUvHSwJ8h9YeGcvx+/qhsw5KAhh4uY7VPy+Q+WsutFfKZ+CaodU+Qwk79hMAy/Ykr73lROVc6yekv3cgYmnpCqmPVo+IxV6hJzCftHhok0fUmn4GntJNxw2ytBTz8SBAX0FAOKUIoVAwNkXwW7quhow006MZQuvVhmY9IY3NyDpDRKxBQoVOcE+7sEUJYvoNme8MsQ998dt/kJYL+tsE2sl5qVgb8qKiEA4cNEm1Kz5IdogrB/X0A/7ZsEcmHpVn0Rv6NkgAOn5y0aNyvuHX/qSmqMelG5ccwcz59JhbtgUGwValB182aaIvsCT9X3KF8Tv0jI9Pa6C6OnbCE231CzCBVuRMlNKL6RNrDIV3DKeqh14oRYy2SsxX12nytj/TifnsluCbhbWQTexSPuThtDXJ4bZnb8L6mHT1xk/hvGKHgY5GscoCR6DK3Zv4txq3CCaB4KgIB79KJqdSMZYoq7kOURgoiNbZwAhwDD0bDzrsKtv+Z9vbPI7L7hOcDsmCd7G7YwX3AEAdRx9uGZn0LsjW1OX6hAmPeNDTvMnxQO7PcefIKHEG6SFJIbK3jPjUXPVXUqKYiKiPH2 Content-Type: multipart/mixed; boundary="_004_CY8PR12MB734051E88B8DF63612A2EA8F87692CY8PR12MB7340namp_" MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CY8PR12MB7340.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c064dd0a-93e5-42f3-d4f2-08df39ca8d5a X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Nov 2026 16:50:22.6747 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 11J+gX+3dCT1EEfNZT0XSjHHqfGdKJ0q3/3aVMNu7OjytgkxbGKiqv44LosbQYgVxNFQeVS/n2zviv6kKwbimQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6109 X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GB_MSAUTHSOURCE_NORTHAM, GIT_PATCH_0, HTML_MESSAGE, LOCAL_AUTHENTICATION_FAIL_SPF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list <binutils.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/binutils>, <mailto:binutils-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/binutils/> List-Post: <mailto:binutils@sourceware.org> List-Help: <mailto:binutils-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/binutils>, <mailto:binutils-request@sourceware.org?subject=subscribe> Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org |
| Series |
bfd: Fix addr2line for skipped DW_FORM_ref_addr CUs and DWARF5 one-file line tables
|
|
Checks
| Context | Check | Description |
|---|---|---|
| linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 | fail | Patch failed to apply |
| linaro-tcwg-bot/tcwg_binutils_build--master-arm | fail | Patch failed to apply |
Commit Message
Kumar N, Bhuvanendra
Nov. 3, 2026, 4:50 p.m. UTC
AMD General
Hi,
I am requesting review of this BFD patch. It fixes binutils addr2line for clang LTO objects. The patch is inlined below and attached to this email.
For clang LTO objects, binutils addr2line can miss a later compilation unit when an earlier CU is scanned and DW_FORM_ref_addr causes stash_comp_unit to parse ahead. Those units never go through the sequential reader. Queue them on unsearched_units in find_abstract_instance and search only that small set in _bfd_dwarf2_find_nearest_line_with_alt after the sequential scan.
Separately, PR 30783 starts the DWARF5 line state machine at file index 1. A table that contains only file 0 then reports a bad file number. Keep the initial index at 1 when that slot exists; fall back to file 0 only for a one-entry DWARF5 table.
NOTE: This reduced test fails with clang LTO and passes with GCC LTO.
Reduced test case sources:
a.c:
__attribute__((always_inline)) int inner(int x);
__attribute__((noinline)) int first(int x)
{
return inner(x);
}
b.c:
__attribute__((always_inline)) int inner(int x)
{
return x + 1;
}
__attribute__((noinline)) int outer(int x)
{
return x + 5;
}
main.c:
int first(int);
int outer(int);
int main(void)
{
return first(1) + outer(4);
}
Test scenario 1: clang LTO, DWARF-5 (clang's default for -g)
clang -g -O2 -flto -c a.c -o a.o
clang -g -O2 -flto -c b.c -o b.o
clang -g -O2 -c main.c -o main.o
clang -flto a.o b.o main.o -o repro
addr2line -e repro -f <address of outer>
Before fix:
addr2line: DWARF error: mangled line number section (bad file number)
addr2line: DWARF error: mangled line number section (bad file number)
outer
??:?
After fix:
outer
b.c:8
Test scenario 2: same commands with -gdwarf-4 on every clang invocation
Before fix:
outer
??:?
After fix:
outer
b.c:8
regards,
Bhuvan
Patch inlined:
From d2dc62e51066cdc4fade93446c813f19fa158b54 Mon Sep 17 00:00:00 2001
From: bhkumarn Bhuvanendra.KumarN@amd.com<mailto:Bhuvanendra.KumarN@amd.com>
Date: Tue, 3 Nov 2026 16:00:28 +0000
Subject: [PATCH] bfd: Fix addr2line for skipped DW_FORM_ref_addr CUs and
DWARF5 one-file line tables
For clang compiled objects, addr2line can miss a later compilation unit
when an earlier CU is scanned and DW_FORM_ref_addr causes stash_comp_unit
to parse ahead. Those units never go through the sequential reader.
Queue them on unsearched_units and search only that small set.
Separately, PR 30783 starts the DWARF5 line state machine at file
index 1. A table that contains only file 0 then reports a bad file
number. Keep the initial index at 1 when that slot exists; fall back
to file 0 only for a one-entry DWARF5 table.
bfd/
* dwarf2.c (struct dwarf2_debug_file): Add unsearched_units.
(struct comp_unit): Add next_unsearched.
(decode_line_info): Fall back to file 0 when a DWARF5 line
table has no file 1.
(find_abstract_instance): Queue CUs parsed via DW_FORM_ref_addr
or DW_FORM_GNU_ref_alt.
(_bfd_dwarf2_find_nearest_line_with_alt): Drain unsearched_units
as a work queue after the sequential scan.
---
bfd/dwarf2.c | 37 +++++++++++++++++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)
struct comp_unit *next_unit_without_ranges;
+ /* Chain of CUs parsed via DW_FORM_ref_addr. */
+ struct comp_unit *next_unsearched;
+
/* Likewise, chain the compilation unit read after this one.
The comp units are stored in reversed reading order. */
struct comp_unit *prev_unit;
@@ -2924,8 +2930,12 @@ decode_line_info (struct comp_unit *unit)
if (table->num_files)
{
/* PR 30783: Always start with a file index of 1, even
- for DWARF-5. */
- filename = concat_filename (table, 1);
+ for DWARF-5. Use file 0 if file 1 is absent. */
+ unsigned int file_index = 1;
+
+ if (table->use_dir_and_file_0 && file_index >= table->num_files)
+ file_index = 0;
+ filename = concat_filename (table, file_index);
}
/* Decode the table. */
@@ -3562,6 +3572,8 @@ find_abstract_instance (struct comp_unit *unit,
u = stash_comp_unit (unit->stash, &unit->stash->f);
if (u == NULL)
break;
+ u->next_unsearched = unit->file->unsearched_units;
+ unit->file->unsearched_units = u;
if (info_ptr >= u->info_ptr_unit && info_ptr < u->end_ptr)
break;
u = NULL;
@@ -3573,6 +3585,8 @@ find_abstract_instance (struct comp_unit *unit,
u = stash_comp_unit (unit->stash, &unit->stash->alt);
if (u == NULL)
break;
+ u->next_unsearched = unit->stash->alt.unsearched_units;
+ unit->stash->alt.unsearched_units = u;
if (info_ptr >= u->info_ptr_unit && info_ptr < u->end_ptr)
break;
u = NULL;
@@ -6016,6 +6030,25 @@ _bfd_dwarf2_find_nearest_line_with_alt
break;
}
+ /* Search CUs parsed via DW_FORM_ref_addr. */
+ if (!found && !do_line)
+ {
+ while (stash->f.unsearched_units != NULL)
+ {
+ each = stash->f.unsearched_units;
+ stash->f.unsearched_units = each->next_unsearched;
+ each->next_unsearched = NULL;
+ found = (comp_unit_may_contain_address (each, addr)
+ && comp_unit_find_nearest_line (each, addr,
+ filename_ptr,
+ &function,
+ linenumber_ptr,
+ discriminator_ptr));
+ if (found)
+ break;
+ }
+ }
+
done:
if (functionname_ptr && function && function->is_linkage)
{
--
2.43.0
Comments
On 03.11.2026 17:50, Kumar N, Bhuvanendra wrote: > From: bhkumarn Bhuvanendra.KumarN@amd.com<mailto:Bhuvanendra.KumarN@amd.com> > Date: Tue, 3 Nov 2026 16:00:28 +0000 > Subject: [PATCH] bfd: Fix addr2line for skipped DW_FORM_ref_addr CUs and > DWARF5 one-file line tables > > For clang compiled objects, addr2line can miss a later compilation unit > when an earlier CU is scanned and DW_FORM_ref_addr causes stash_comp_unit > to parse ahead. Those units never go through the sequential reader. > Queue them on unsearched_units and search only that small set. > > Separately, PR 30783 starts the DWARF5 line state machine at file > index 1. A table that contains only file 0 then reports a bad file > number. Keep the initial index at 1 when that slot exists; fall back > to file 0 only for a one-entry DWARF5 table. > > bfd/ > * dwarf2.c (struct dwarf2_debug_file): Add unsearched_units. > (struct comp_unit): Add next_unsearched. > (decode_line_info): Fall back to file 0 when a DWARF5 line > table has no file 1. > (find_abstract_instance): Queue CUs parsed via DW_FORM_ref_addr > or DW_FORM_GNU_ref_alt. > (_bfd_dwarf2_find_nearest_line_with_alt): Drain unsearched_units > as a work queue after the sequential scan. Okay, albeit I think I'll ... > @@ -6016,6 +6030,25 @@ _bfd_dwarf2_find_nearest_line_with_alt > break; > } > + /* Search CUs parsed via DW_FORM_ref_addr. */ > + if (!found && !do_line) > + { > + while (stash->f.unsearched_units != NULL) > + { > + each = stash->f.unsearched_units; > + stash->f.unsearched_units = each->next_unsearched; > + each->next_unsearched = NULL; > + found = (comp_unit_may_contain_address (each, addr) > + && comp_unit_find_nearest_line (each, addr, > + filename_ptr, > + &function, > + linenumber_ptr, > + discriminator_ptr)); > + if (found) > + break; > + } > + } > + > done: > if (functionname_ptr && function && function->is_linkage) > { ... shrink this hunk some before committing. Jan
diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c index 61473a50..2ed9e2b6 100644 --- a/bfd/dwarf2.c +++ b/bfd/dwarf2.c @@ -271,6 +271,9 @@ struct dwarf2_debug_file /* Last comp unit in list above. */ struct comp_unit *last_comp_unit; + /* Unsearched CUs parsed via DW_FORM_ref_addr. */ + struct comp_unit *unsearched_units; + /* Line table at line_offset zero. */ struct line_info_table *line_table; @@ -357,6 +360,9 @@ struct comp_unit Unused if arange.high != 0. */