[PATCH] D105214: [ARM] RELA relocations for 32bit ARM ignore the addend.

Wolfgang Pieb via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 1 09:42:51 PDT 2021


wolfgangp added a comment.

In D105214#2852339 <https://reviews.llvm.org/D105214#2852339>, @peter.smith wrote:

> I've not seen SHT_RELA used for debug data before and I think all of the other LLVM tools assume SHT_REL. Are you planning to add SHT_RELA support to the other LLVM tools?

We have at least one internal test case generated by a proprietary ARM compiler that is using RELA relocations, which is handled just fine by dwarfdump (David Anderson's dwarfdump, that is), so there is some incentive for us to handle it. Also, the code I'm planning to change is used by all llvm tools, so all tools should benefit. From what I'm seeing there is SHT_RELA awareness in the other tools as well.



================
Comment at: llvm/lib/Object/RelocationResolver.cpp:314
 
 static uint64_t resolveARM(uint64_t Type, uint64_t Offset, uint64_t S,
+                           uint64_t LocData, int64_t Addend) {
----------------
peter.smith wrote:
> MaskRay wrote:
> > MaskRay wrote:
> > > The code is written in the assumption that targets preferring RELA always have Addend while targets preferring REL always have LocData.
> > > 
> > > Are you trying to add RELA support to ARM? I think it is unpopular but maybe you have specific needs which are not specified.
> > > 
> > > No objection, but a comment is needed.
> > I think adding LocData and Addend is wrong. When RELA is used, LocData (implicit addend) should be ignored.
> Agreed. The ELF spec says in http://www.sco.com/developers/gabi/latest/ch4.reloc.html
> "As specified previously, only Elf32_Rela and Elf64_Rela entries contain an explicit addend. Entries of type Elf32_Rel and Elf64_Rel store an implicit addend in the location to be modified. Depending on the processor architecture, one form or the other might be necessary or more convenient. Consequently, an implementation for a particular machine may use one form exclusively or either form depending on context."
> 
> "The typical application of an ELF relocation is to determine the referenced symbol value, extract the addend (either from the field to be relocated or from the addend field contained in the relocation record, as appropriate for the type of relocation record), apply the expression implied by the relocation type to the symbol and addend, extract the desired part of the expression result, and place it in the field to be relocated."
Ah, thanks for pointing that out. It is curious, though, because some RISCV relocations clearly seem to use both addend and location data ([[ https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md | see here ]]). 
Accordingly, when I zero out LocData for RELA relocations, some RISCV test cases start failing. I may have to restrict zeroing out LocData to ARM platforms, which I don't particularly like.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105214/new/

https://reviews.llvm.org/D105214



More information about the llvm-commits mailing list