[PATCH] D15965: Add support for dumping relocations in non-relocatable files

It sounds like what you’re asking is, rather that universally calling RelocationRef::getOffset inside llvm-objdump.cpp

I should:

· Check if Obj “isRelocatableObject”

· If it is, call RelocationRef::getOffset()

· If it isn’t

o Call RelocationRef::getAddress()

o Build an ordered map of all sections and their bounds, check if the relocation lands within a section

o Subtract the section address from the relocation address

Since getAddress isn’t in RelocationRef at the moment, this is going to have to be getAddress for MachO and COFF.

COFFObjectFile::getRelocationOffset returns R->VirtualAddress, so inside here I’m going to have to find the section it belongs to, add it to the result so it can later be subtracted off by llvm-objdump

MachOObjectFile::getRelocationOffset also returns getAnyRelocationAddress so I’ll have to also find its containing section and add this in just so llvm-objdump can later subtract it.

Can you detail why this is a better plan?

That is the overall structure, yes. You do have to handle the case of
there being no section that covers the address.

I will take a look at the updated patch.