Skip to content

[DWARF Import] Update object to 0.41 to read Xtensa debug relocations - #8728

Merged
ElykDeer merged 1 commit into
Vector35:devfrom
jrozner:dwarf-object-0.41
Nov 19, 2026
Merged

ElykDeer merged 1 commit into
Vector35:devfrom
jrozner:dwarf-object-0.41

Conversation

@jrozner

@jrozner jrozner commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Loading an Xtensa relocatable object built with -g imports no debug info. The DWARF importer logs:

[DWARF Import error] Failed to parse DWARF: Failed to load DWARF info: Unsupported relocation type

ESP-IDF builds with -ggdb by default, so this affects nearly every object built for the ESP32, ESP32-S2, ESP32-S3 and ESP8266. Linked ELFs are unaffected because they have no relocations.

GNU as emits R_XTENSA_PDIFF8/16/32 (or DIFF*/NDIFF*) relocations for symbol differences in .debug_info, .debug_line, .debug_frame, .debug_aranges, .debug_loclists and .debug_rnglists, which object 0.36 maps to RelocationKind::Unknown, so RelocationMap::add rejects them. R_XTENSA_32 is also partial-inplace in binutils even though Xtensa uses RELA, so a DW_FORM_strp emitted as R_XTENSA_32 .debug_str + 0 would read as offset 0.

object 0.41.0 fixes both (gimli-rs/object#1010): the difference relocations return RelocationKind::None, which RelocationMap skips, and R_XTENSA_32 has an implicit addend.

Changes

object 0.36 → 0.41 in plugins/dwarf/shared and plugins/dwarf/dwarf_import. No source changes are needed. dwarf_export stays on 0.32.

The other change between 0.36 and 0.41 that touches this code: RelocationMap::add now rejects relocations with a subtractor (object#1012). 0.36 already rejected Mach-O SUBTRACTOR pairs, as Unknown relocations, so they still fail, just with a different message.

Testing

Built dwarf_import from this branch and loaded it headless into Binary Ninja 6.1.11155-dev (same core ABI as dev), in place of the bundled importer (corePlugins.dwarfImport: false, with the built .so in a throwaway user plugin directory). An Xtensa/ESP32 architecture plugin with an ELF relocation handler was loaded alongside it. The test files are corpus.c built with Espressif GCC 14.2 for the ESP32 (-O2 -ggdb and -Og -ggdb, -c; 177 R_XTENSA_32, 164 R_XTENSA_PDIFF16 and 53 R_XTENSA_PDIFF32 relocations) and the ESP32-C3, plus x86-64 objects and binaries.

  • ESP32 objects: dev fails with the error above. This branch imports 13 functions, 1 of the 2 data variables, and 4 types. Both data variables are at offset 0 of their sections (.data and .bss), so they get the same address and one replaces the other. An x86-64 object loses one the same way on dev. The function signatures and types are identical to the import of the same object linked with ld.
  • Everything else gives exactly the same output as dev (DWARF functions, data variables and types, and the view's function types and variables): the linked ESP32 ELF, the ESP32-C3 objects (-O2, -Og, which still fail on RISC-V relocations; [DWARF Import] Place relocatable object addresses where the view put their sections, and import RISC-V objects #8731 fixes that) and linked ELF, an x86-64 object, and linked x86-64 PIE and non-PIE binaries.
  • With [DWARF Import] Place relocatable object addresses where the view put their sections, and import RISC-V objects #8731 applied as well: all 12 functions with an address and both data variables of the ESP32 objects land on their ELF symbols (e.g. add3 at 0x10020), and the view's function types and local variables are identical to the import of the linked object.
  • Clippy reports the same warnings in dwarfreader/dwarf_import as on dev. cargo fmt --check reports two diffs in dwarfdebuginfo.rs, which comes from dev and isn't changed here.

Loading an Xtensa relocatable object built with -g failed with "Failed to
load DWARF info: Unsupported relocation type", so no debug info was
imported. ESP-IDF builds with -ggdb by default, so this affected nearly
every object built for the ESP32, ESP32-S2, ESP32-S3 and ESP8266.

object 0.41 handles these relocations itself (gimli-rs/object#1010): it
skips the R_XTENSA_DIFF*/PDIFF*/NDIFF* label-difference relocations,
whose result GNU as has already stored, and gives R_XTENSA_32 an
implicit addend, since binutils treats it as partial-inplace even though
Xtensa uses RELA. Without that, a DW_FORM_strp emitted as
R_XTENSA_32 .debug_str + 0 would read as offset 0.
@ElykDeer
ElykDeer self-requested a review November 19, 2026 19:32

@ElykDeer ElykDeer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just have wait for tests to pass, and this should be good. Thank you!

@ElykDeer
ElykDeer merged commit 73acda8 into Vector35:dev Nov 19, 2026
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants