[binutils-gdb] bfd: Fix addr2line for skipped DW_FORM_ref_addr CUs and DWARF5 one-file line tables
Jan Beulich
jbeulich@sourceware.org
Fri Nov 6 13:16:11 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0e00e431608f6d5bf79348471b321ec35f318ee6
commit 0e00e431608f6d5bf79348471b321ec35f318ee6
Author: bhkumarn <Bhuvanendra.KumarN@amd.com>
Date: Fri Nov 6 14:14:05 2026 +0100
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.
Diff:
---
bfd/dwarf2.c | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c
index 084a1c5d8cc..aed2c36f023 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. */
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. */
@@ -3563,6 +3573,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;
@@ -3574,6 +3586,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;
@@ -6017,6 +6031,19 @@ _bfd_dwarf2_find_nearest_line_with_alt
break;
}
+ /* Search CUs parsed via DW_FORM_ref_addr. */
+ if (!do_line)
+ while (!found && 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));
+ }
+
done:
if (functionname_ptr && function && function->is_linkage)
{
More information about the Binutils-cvs
mailing list