xoofx / LibObjectFile

LibObjectFile is a .NET library to read, manipulate and write linker and executable object files (e.g ELF, PE, DWARF, ar...)
BSD 2-Clause "Simplified" License
159 stars 11 forks source link

Add support for encoding location lists #22

Closed filipnavara closed 2 years ago

filipnavara commented 2 years ago

One of my experiments uses the LibObjectFile library to generate DWARF debugging info for the .NET NativeAOT compiler. I am missing support for the location list when emitting information about variable locations. Here's a minimal viable implementation to add such support. It's missing error handling at the moment but I am posting it for some early review to get feedback on the general API shape.

xoofx commented 2 years ago

Looks good, I can't help in the details as it would require to dig into the specs.

filipnavara commented 2 years ago

There's couple of things that I need to fix:

From the specification point of view, in DWARF 4 the structure is pretty simple. You either have start/end/expression entry, or a base address entry (start = MaxValue, end = base address, expression is omitted). I didn't take extra care to represent the base address entry but it's round trip-able at least. With DWARF 5 it gets more complicated because there's a new section to represent the same thing using much more flexible format (eg. using start/length instead of start/end, and other formats). I didn't look much into it but there's a risk that the API shape may need some tweaks if DWARF 5 support is added.

The DWARF 5 format is more friendly to relocatable object files. I didn't realise the need for relocations at first since I prototyped this on Mach-O object files which don't relocate the debug information. Instead the linker produces a map in the linked executable that points to the DWARF information in the original .o files.

filipnavara commented 2 years ago

Fixed the remaining issues.

xoofx commented 2 years ago

Thanks!