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