From 048e2508ad289da30008863bbb104419f8dbfe6f Mon Sep 17 00:00:00 2001 From: Alexander Richardson Date: Mon, 19 Feb 2018 11:00:15 +0000 Subject: [PATCH] Rename DynamicReloc::getAddend() to computeAddend(). NFC Summary: Before the name of the function sounded like it was just a getter for the private class member Addend. However, it actually calculates the final value for 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 computeAddend(). Differential Revision: https://reviews.llvm.org/D43161 llvm-svn: 325485 --- lld/ELF/SyntheticSections.cpp | 4 ++-- lld/ELF/SyntheticSections.h | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 19f6e41eb5c0..f699e415f7eb 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -1184,7 +1184,7 @@ uint64_t DynamicReloc::getOffset() const { return InputSec->getOutputSection()->Addr + InputSec->getOffset(OffsetInSec); } -int64_t DynamicReloc::getAddend() const { +int64_t DynamicReloc::computeAddend() const { if (UseSymVA) return Sym->getVA(Addend); return Addend; @@ -1239,7 +1239,7 @@ template static void encodeDynamicReloc(typename ELFT::Rela *P, const DynamicReloc &Rel) { if (Config->IsRela) - P->r_addend = Rel.getAddend(); + P->r_addend = Rel.computeAddend(); 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 diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index 30658aed5af4..855b91d6c442 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -316,16 +316,24 @@ public: UseSymVA(UseSymVA), Addend(Addend) {} uint64_t getOffset() const; - int64_t getAddend() const; uint32_t getSymIndex() const; const InputSectionBase *getInputSec() const { return InputSec; } + // Computes the addend of the dynamic relocation. Note that this is not the + // same as the Addend member variable as it also includes the symbol address + // if UseSymVA is true. + int64_t computeAddend() const; + RelType Type; private: Symbol *Sym; const InputSectionBase *InputSec = nullptr; uint64_t OffsetInSec; + // If this member is true, the dynamic relocation will not be against the + // symbol but will instead be a relative relocation that simply adds the + // load address. This means we need to write the symbol virtual address + // plus the original addend as the final relocation addend. bool UseSymVA; int64_t Addend; };