m4b/faerie

DWARF support

philipc opened this issue · 3 comments

I'm looking into adding DWARF support. This will be used in conjunction with gimli. I need the ability to:

  • provide multiple named DWARF sections. These will be blocks of data that faerie doesn't need to interpret which are stored in a section with a given name (eg .debug_info section for ELF, and __DWARF segment and __debug_info section for Mach).
  • provide relocations for values in those sections. The relocations can be links to functions, data, or DWARF sections. These need to be associated with the section it is providing relocations for (eg .rela.debug_info with a sh_info pointing to .debug_info for ELF).

After a brief look at the code, I think this can be achieved by adding a DebugSection variant to Decl. I'm going to start trying to implement this, but any input on the direction to take is welcome.

m4b commented

This sounds great !

So you’re going to have one uninterpreted byte blob which faerie doesn’t understand the semantics of, but you’ll be using the existing relocation machinery to create proper relocations, yes?

If the current relocation machinery isn’t sufficient I’d recommend either:

  1. using the raw api
  2. Creating a new link debug type ?

Ideally I’d like to see faerie understand the semantics of the debug byte blob (similar to how it understands the semantics of other sections, module code / data, which is obviously beyond its scope)

Is that something in the foreseeable future, or will the debug section(s) always be a black box from faeries perspective?

Just some food for thought :)

Also does gimli have a writer for the various debug structs/components/dies ?

There will be one blob for each debug section (.debug_info, .debug_abbrev, .debug_line etc).

Yes I'll use the existing relocation machinery. I think I'll be able to decide which relocation type to use based on whether it is linking to function/data/another debug section. The Decl::DebugSection might need to include a 32/64-bit flag so that I can determine which relocation size to use.

I'm not sure how faerie could usefully understand their semantics. That's gimli's job. Can you elaborate on what you mean?

gimli doesn't have a writer yet, but it will.

The existing reloc machinery won't work because I need addends. Maybe it could be extended to handle them, but that seems like a large breaking change that doesn't actually gain much. DWARF relocations are simple enough that using overrides is easy enough.