From a2b1f45dedeb585ac2296e045c5773df5157e06f Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 17 Feb 2016 06:08:42 +0000 Subject: [PATCH] Make getOffset a member function of DynamicReloc. Logically it belongs to DynamicReloc, and it is more readable to be a member of the class. llvm-svn: 261069 --- lld/ELF/OutputSections.cpp | 26 +++++++++++--------------- lld/ELF/OutputSections.h | 2 ++ 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 7c8d2ab..013f091 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -225,25 +225,21 @@ void RelocationSection::addReloc(const DynamicReloc &Reloc) { } template -static typename ELFFile::uintX_t -getOffset(const DynamicReloc &Rel) { - typedef typename ELFFile::uintX_t uintX_t; - SymbolBody *Sym = Rel.Sym; - switch (Rel.OKind) { - case DynamicReloc::Off_GTlsIndex: +typename ELFFile::uintX_t DynamicReloc::getOffset() const { + switch (OKind) { + case Off_GTlsIndex: return Out::Got->getGlobalDynAddr(*Sym); - case DynamicReloc::Off_GTlsOffset: + case Off_GTlsOffset: return Out::Got->getGlobalDynAddr(*Sym) + sizeof(uintX_t); - case DynamicReloc::Off_LTlsIndex: + case Off_LTlsIndex: return Out::Got->getTlsIndexVA(); - case DynamicReloc::Off_Sec: - return Rel.OffsetSec->getOffset(Rel.OffsetInSec) + - Rel.OffsetSec->OutSec->getVA(); - case DynamicReloc::Off_Bss: + case Off_Sec: + return OffsetSec->getOffset(OffsetInSec) + OffsetSec->OutSec->getVA(); + case Off_Bss: return cast>(Sym)->OffsetInBss + Out::Bss->getVA(); - case DynamicReloc::Off_Got: + case Off_Got: return Sym->getGotVA(); - case DynamicReloc::Off_GotPlt: + case Off_GotPlt: return Sym->getGotPltVA(); } llvm_unreachable("Invalid offset kind"); @@ -265,7 +261,7 @@ template void RelocationSection::writeTo(uint8_t *Buf) { reinterpret_cast(P)->r_addend = Rel.Addend + VA; } - P->r_offset = getOffset(Rel); + P->r_offset = Rel.getOffset(); uint32_t SymIdx = (!Rel.UseSymVA && Sym) ? Sym->DynsymIndex : 0; P->setSymbolAndType(SymIdx, Rel.Type, Config->Mips64EL); } diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h index 13c78e8..6d5ef35 100644 --- a/lld/ELF/OutputSections.h +++ b/lld/ELF/OutputSections.h @@ -212,6 +212,8 @@ template struct DynamicReloc { : Type(Type), OKind(Off_Sec), OffsetSec(OffsetSec), OffsetInSec(OffsetInSec), TargetSec(TargetSec), OffsetInTargetSec(OffsetInTargetSec), Addend(Addend) {} + + uintX_t getOffset() const; }; template -- 2.7.4