addr2line: Fix DWARF5 line table parsing and DW_FORM_ref_addr handling
Improves addr2line's accuracy with DWARF5 line tables and clang-generated code.
This change corrects two issues in addr2line’s DWARF parsing. First, it ensures that compilation units referenced via DW_FORM_ref_addr are properly queued and processed, preventing them from being skipped when generated by clang. Second, it adjusts the DWARF5 line table parsing to correctly handle cases where the first file entry is missing, preventing errors with single-file line tables.
In Details
This commit modifies bfd/dwarf2.c to address two distinct problems in DWARF processing within addr2line. The first addresses a scenario where clang-generated objects might skip later compilation units if an earlier CU is parsed using DW_FORM_ref_addr or DW_FORM_GNU_ref_alt. These units are now stashed in unsearched_units and processed after the primary scan. The second issue concerns DWARF5 line tables where the initial file index (normally 1) might be absent. The code now correctly falls back to file index 0 for single-entry tables, or preserves the index 1 if it exists.
- addr2line
- A utility that translates object code addresses into line numbers and function names, using DWARF debugging information.
- DWARF
- Debugging With Attributed Record Formats, a standard file format for debugging information within compiled programs.
- DW_FORM_ref_addr
- A DWARF debugging information form that indicates a reference to a location using an address.
- Compilation Unit (CU)
- A translation unit (e.g., a source file) for which debugging information is generated.
- DWARF5
- The fifth version of the DWARF debugging information standard, introducing new features and revisions.
- line table
- A data structure within DWARF that maps addresses in the executable code to source code line numbers.