[PATCH] D43161: Rename DynamicReloc::getAddend() to getRelaAddend(). NFC

Alexander Richardson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 10 10:17:52 PST 2018


arichardson created this revision.
arichardson added reviewers: ruiu, rafael.
Herald added subscribers: llvm-commits, emaste.

Before the name of the function sounded like it was just a getter for the
class member Addend. However, it actually calculates the value of the
r_addend field in Elf_Rela that is used when writing the .rela.dyn section.
I also added a comment to the UseSymVA member to explain how it interacts
with getRelaAdded().


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D43161

Files:
  ELF/SyntheticSections.cpp
  ELF/SyntheticSections.h


Index: ELF/SyntheticSections.h
===================================================================
--- ELF/SyntheticSections.h
+++ ELF/SyntheticSections.h
@@ -316,16 +316,25 @@
         UseSymVA(UseSymVA), Addend(Addend) {}
 
   uint64_t getOffset() const;
-  int64_t getAddend() const;
   uint32_t getSymIndex() const;
   const InputSectionBase *getInputSec() const { return InputSec; }
 
+  // Return the value that should be written to the Elf_Rela r_addend field.
+  // This is not the same as the addend used when creating this dynamic
+  // relocation since we may have converted a static relocation against a
+  // non-preemptible symbol into a relocation against the load address. In that
+  // case we write the virtual address of the symbol plus the addend into the
+  // r_addend field.
+  int64_t getRelaAddend() const;
+
   RelType Type;
 
 private:
   Symbol *Sym;
   const InputSectionBase *InputSec = nullptr;
   uint64_t OffsetInSec;
+  // If this member is true, the dynamic relocation is against the load address
+  // and therefore the symbol virtual address will be used as the addend value
   bool UseSymVA;
   int64_t Addend;
 };
Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -1184,7 +1184,7 @@
   return InputSec->getOutputSection()->Addr + InputSec->getOffset(OffsetInSec);
 }
 
-int64_t DynamicReloc::getAddend() const {
+int64_t DynamicReloc::getRelaAddend() const {
   if (UseSymVA)
     return Sym->getVA(Addend);
   return Addend;
@@ -1236,7 +1236,7 @@
 static void encodeDynamicReloc(typename ELFT::Rela *P,
                                const DynamicReloc &Rel) {
   if (Config->IsRela)
-    P->r_addend = Rel.getAddend();
+    P->r_addend = Rel.getRelaAddend();
   P->r_offset = Rel.getOffset();
   if (Config->EMachine == EM_MIPS && Rel.getInputSec() == InX::MipsGot)
     // The MIPS GOT section contains dynamic relocations that correspond to TLS


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43161.133756.patch
Type: text/x-patch
Size: 2003 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180210/94068ec5/attachment.bin>


More information about the llvm-commits mailing list