Colin LeMahieu via llvm-dev
2016-Mar-24 20:35 UTC
[llvm-dev] [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? From: Rafael Espíndola [mailto:rafael.espindola at gmail.com] Sent: Thursday, March 24, 2016 3:13 PM To: Colin LeMahieu <colinl at codeaurora.org> Cc: llvm-commits <llvm-commits at lists.llvm.org>; Shankar Easwaran <shankare at codeaurora.org>; Hemant Kulkarni <khemant at codeaurora.org>; reviews+D15965+public+319b19c852e3c4e3 at reviews.llvm.org Subject: RE: [PATCH] D15965: Add support for dumping relocations in non-relocatable files On Mar 24, 2016 4:08 PM, "Colin LeMahieu" <colinl at codeaurora.org <mailto:colinl at codeaurora.org> > wrote:> > llvm-objdump wants to print the relocationOffset, so it calls RelocationRef::relocationOffset which calls ELFObjectFile::getRelocationOffset > > Since objdump wants the relocation offset, and this pipes down to ELFObjectFile::getRelocationOffset, at what point is the address supposed to be asked for? >In llvm-objdump. It can then search the sections to see if one happens to include that address.> -----Original Message----- > From: Rafael Espíndola [mailto:rafael.espindola at gmail.com <mailto:rafael.espindola at gmail.com> ] > Sent: Thursday, March 24, 2016 2:45 PM > To: reviews+D15965+public+319b19c852e3c4e3 at reviews.llvm.org <mailto:reviews%2BD15965%2Bpublic%2B319b19c852e3c4e3 at reviews.llvm.org> > Cc: colinl at codeaurora.org <mailto:colinl at codeaurora.org> ; Hemant Kulkarni <khemant at codeaurora.org <mailto:khemant at codeaurora.org> >; Shankar Easwaran <shankare at codeaurora.org <mailto:shankare at codeaurora.org> >; llvm-commits <llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org> > > Subject: Re: [PATCH] D15965: Add support for dumping relocations in non-relocatable files > > On 24 March 2016 at 15:35, Shankar Easwaran <shankare at codeaurora.org <mailto:shankare at codeaurora.org> > wrote: > > shankare added a reviewer: shankare. > > shankare added a comment. > > > > http://www.sco.com/developers/gabi/latest/ch4.reloc.html > > > > r_offset > > This member gives the location at which to apply the relocation action. For a relocatable file, the value is the byte offset from the beginning of the section to the storage unit affected by the relocation. For an executable file or a shared object, the value is the virtual address of the storage unit affected by the relocation. > > > > This shows that the assertion is incorrect, as the ELF ABI suggests reading relocation records is valid in Executables as well. > > > > While relocation offset is not looked up for shared libraries from > > .rela.dyn and .rela.plt sections, there is a usecase where relocation > > sections are generated with the linker switch **--emit-relocs** > > And those records have addresses, not offsets. Therefore the assertion is correct and you may *NOT* remove it. > > CHeers, > Rafael >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160324/328587eb/attachment.html>
Rafael Espíndola via llvm-dev
2016-Mar-28 17:25 UTC
[llvm-dev] [PATCH] D15965: Add support for dumping relocations in non-relocatable files
On 24 March 2016 at 16:35, Colin LeMahieu <colinl at codeaurora.org> wrote:> 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 >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. Cheers, Rafael
Seemingly Similar Threads
- [llvm] r263971 - [llvm-objdump] Printing relocations in executable and shared object files. This partially reverts r215844 by removing test objdump-reloc-shared.test which stated GNU objdump doesn't print relocations, it does.
- [LLVMdev] Moving towards a singular pointer type
- [DebugInfo] DWARF C API
- Re: How to use unicorn server on Rails 3 [Solved]
- Problem using rvm in bash script