eliben / pyelftools

Parsing ELF and DWARF in Python
Other
1.99k stars 507 forks source link

Support for XC16/PIC phantom bytes #522

Closed sevaa closed 9 months ago

sevaa commented 9 months ago

Addresses #518 and #473.

This is a weird flavor of DWARF, emitted by the XC16 compiler for PIC microcontrollers, that looks completely alien on its face but can be trivially supported if one discards every odd numbered byte ("phantom bytes") in every DWARF section.

We don't know where does this transform fit between two decompression hooks and relocations. Relocations are explicitly shorted out for now, the compression logic is left as-is, seeing as the compiler doesn't seem to support it.

This peculiarity adds nothing to the format of DWARF proper, it can be seen as merely an unusual way to store DWARF data in the binary. So a case for a proper readelf test is not as strong as I originally thought; a unit test with an XC16/PIC binary should suffice. Before the patch, parsing those binaries would crash on the first CU accessing call.