Bug 28915 - dwarf2.c doesn't correctly parse DW_UT_skeleton
Summary: dwarf2.c doesn't correctly parse DW_UT_skeleton
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.39
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-02-21 10:06 UTC by Jakub Jelinek
Modified: 2023-05-13 01:14 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2022-02-21 10:06:29 UTC
In https://bugzilla.redhat.com/show_bug.cgi?id=2052228 ld reports weird
/usr/bin/ld: /usr/bin/ld: DWARF error: could not find abbrev number 62
diagnostics.  The object file in question uses -gsplit-dwarf and 
readelf -wi obj/third_party/swiftshader/src/Reactor/swiftshader_subzero/IceTargetLoweringX8664.o
Contents of the .debug_info section:

  Compilation Unit @ offset 0x0:
   Length:        0x2d (32-bit)
   Version:       5
   Unit Type:     DW_UT_skeleton (4)
   Abbrev Offset: 0x0
   Pointer Size:  8
   DWO ID:        0xaff01133f289df3e
 <0><14>: Abbrev Number: 1 (DW_TAG_skeleton_unit)
    <15>   DW_AT_ranges      : 0xc
    <19>   DW_AT_low_pc      : 0x0
    <21>   DW_AT_stmt_list   : 0x0
    <25>   DW_AT_dwo_name    : (indirect string, offset: 0x39): obj/third_party/swiftshader/src/Reactor/swiftshader_subzero/IceTargetLoweringX8664.dwo
    <29>   DW_AT_comp_dir    : (indirect string, offset: 0x0): /builddir/build/BUILD/chromium-98.0.4758.80/out/Headless
    <2d>   DW_AT_GNU_pubnames: 1
    <2d>   DW_AT_addr_base   : 0x8
62 is equal to 0x3e, i.e. the first byte of DWO ID.
So, this seems to be a bug in bfd/dwarf2.c (parse_comp_unit) which for DW_UT_type does:
  if (unit_type == DW_UT_type)
    {
      /* Skip type signature.  */
      info_ptr += 8;

      /* Skip type offset.  */
      info_ptr += offset_size;
    }
but should at least also:
  else if (unit_type == DW_UT_skeleton || unit_type == DW_UT_split_compile)
    /* Skip DWO ID.  */
    info_ptr += 8;
at minimum.

Minimal reproducer would be something like:
cat > test.c <<\EOF
int foo (void);

int
main ()
{
  return foo ();
}
EOF
gcc -gdwarf-5 -gsplit-dwarf -o test{,.c}

The above will just avoid interpreting bytes in the DWO ID as abbrev number followed by its attribute values etc., for reallly supporting split DWARF more work would be needed (actually reading the DWO ID, read DW_AT_dwo_name and DW_AT_comp_dir in the DW_TAG_skeleton_unit, try to find the dwo file and read it in addition to the skeleton stuff (some sections remain in the .o file like .debug_addr, others are in the dwo file and others are in both).
Comment 1 Alan Modra 2023-05-13 01:14:11 UTC
The minimal fix of skipping over the DWO id was committed in 09fbd1cf93ba.