aclements / libelfin

C++11 ELF/DWARF parser
MIT License
317 stars 99 forks source link

Support for relocation sections #24

Open paulreimer opened 6 years ago

paulreimer commented 6 years ago

Hi there,

Awesome library, it worked great and easy to integrate onto my embedded target.

However, I don't see how to read the entries in the relocation sections?

aclements commented 6 years ago

Thanks. I'm glad you like it.

You're right that there's currently no specific support for parsing relocation sections. Patches welcome. :) It should be relatively easy to add generic support for reading the Elf32/64_Rel and Elf32/64_Rela structures. The actual relocation types would be a bit of a chore, since they're spread out across the processor supplements.

paulreimer commented 6 years ago

OK thanks! I was able to get the reloc info by using those structs from Linux elf.h header. I wasn't sure how to select the right struct (rel vs rela) other than by comparing entsize to sizeof(Elf32_Rela) but I suspect there is a better way and/or hoped this library could do that. As to the various reloc types, I can handle that. But it would be nice to have some sort of iterator over reloc sections, with the right type of reloc struct (or other way of having access to the fields).

aclements commented 6 years ago

I wasn't sure how to select the right struct (rel vs rela) other than by comparing entsize to sizeof(Elf32_Rela) but I suspect there is a better way and/or hoped this library could do that.

The Shdr.type field will be either sht::rel or sht::rela depending on which relocation type it contains. Using the entsize should work too, but Shdr.type is probably more reliable. I've never really figured out what entsize is good for, so it wouldn't surprise me if some tools get it wrong. :)

deadly-platypus commented 5 years ago

Has there been any development on this? I would also like this feature, and can work on it if development has been dropped