[PATCH] [ELF]: Initial implementation for ARM static linking

Simon Atanasyan simon at atanasyan.com
Sun Nov 30 05:41:51 PST 2014


================
Comment at: lib/ReaderWriter/ELF/ARM/ARMELFFile.h:103-108
@@ +102,8 @@
+      return readAddend_THM_CALL(ap);
+    case llvm::ELF::R_ARM_CALL:
+    case llvm::ELF::R_ARM_JUMP24:
+      return readAddend_ARM_CALL(ap);
+    case llvm::ELF::R_ARM_THM_MOVW_ABS_NC:
+    case llvm::ELF::R_ARM_THM_MOVT_ABS:
+      return readAddend_THM_MOV(ap);
+    case llvm::ELF::R_ARM_THM_JUMP11:
----------------
shankarke wrote:
> atanasyan wrote:
> > shankarke wrote:
> > > All of the above would need to be done in the relocation  handler. We should not interpret the bits in the Reader, this way the Reader is agnostic to the symbol value.
> > > 
> > > 
> > But the relocation handler does not know about used relocation section format (.rel/.rela) so it cannot decide how and where to read an addendum. So I think it is a good approach to read addendums here, construct `Reference` objects, and call the `Reference::addend()` method further.
> I have two concerns (a), (b) :-
> 
> a) Doing this in the Reader may not be idempotent (Need to consider cases like partial linking and ELF to yam conversions and back to atoms).
> b) We may be losing some data because of the transformation in the Reader too, to preserve what was in the object file.
> 
> ELFLinkingContext::isRelaOutputFormat() can be used to figure out if the Target is using Rela/Rel. In addition the Target knows the relocation types that it handles.
> 
> 
In general, I agree with you. As far as I can see ARM relocation addendums can be read in the `ARMRelocationHandler` class.

MIPS has some unusual relocations like `R_MIPS_HI16` / `R_MIPS_LO16`.  These relocations form pairs and to apply each of such relocation we need to know addendums from both paired relocations. The bad thing is that the paired relocations can belong to different atoms. So it is difficult to search a paired relocation in the `applyRelocation` method. That is why I have to read addendums for MIPS target in the `MipsELFFile` class. I think Denis’ implementation is inspired by this code.

By the way, if anybody knows a better solution I would be happy to hear it.

http://reviews.llvm.org/D6446






More information about the llvm-commits mailing list