From f64618a621f4da195a6e7e3ab1a5ea062f81dbcb Mon Sep 17 00:00:00 2001 From: George Rimar Date: Fri, 17 Mar 2017 11:56:54 +0000 Subject: [PATCH] [ELF] - Detemplate SymbolBody::getVA and SymbolBody::getPltVA. NFC. llvm-svn: 298071 --- lld/ELF/InputSection.cpp | 28 +++++++++++++--------------- lld/ELF/LinkerScript.cpp | 2 +- lld/ELF/MapFile.cpp | 2 +- lld/ELF/Symbols.cpp | 28 ++++++++-------------------- lld/ELF/Symbols.h | 4 ++-- lld/ELF/SyntheticSections.cpp | 14 +++++++------- lld/ELF/Target.cpp | 12 ++++++------ lld/ELF/Thunks.cpp | 18 +++++++++--------- lld/ELF/Writer.cpp | 2 +- 9 files changed, 48 insertions(+), 62 deletions(-) diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 79a04fc3441c..b1d10e70542e 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -272,7 +272,7 @@ void InputSection::copyRelocations(uint8_t *Buf, ArrayRef Rels) { } if (Config->isRela()) { - P->r_addend += Body.getVA() - Section->getOutputSection()->Addr; + P->r_addend += Body.getVA() - Section->getOutputSection()->Addr; } else if (Config->Relocatable) { const uint8_t *BufLoc = RelocatedSection->Data.begin() + Rel.r_offset; RelocatedSection->Relocations.push_back( @@ -344,17 +344,16 @@ getRelocTargetVA(uint32_t Type, int64_t A, typename ELFT::uint P, return getAArch64Page(In::Got->getGlobalDynAddr(Body) + A) - getAArch64Page(P); case R_PLT: - return Body.getPltVA() + A; + return Body.getPltVA() + A; case R_PLT_PC: case R_PPC_PLT_OPD: - return Body.getPltVA() + A - P; + return Body.getPltVA() + A - P; case R_SIZE: return Body.getSize() + A; case R_GOTREL: - return Body.getVA(A) - In::Got->getVA(); + return Body.getVA(A) - In::Got->getVA(); case R_GOTREL_FROM_END: - return Body.getVA(A) - In::Got->getVA() - - In::Got->getSize(); + return Body.getVA(A) - In::Got->getVA() - In::Got->getSize(); case R_RELAX_TLS_GD_TO_IE_END: case R_GOT_FROM_END: return Body.getGotOffset() + A - In::Got->getSize(); @@ -384,15 +383,14 @@ getRelocTargetVA(uint32_t Type, int64_t A, typename ELFT::uint P, Body.symbol()->isWeak()) return 0; if (Target->TcbSize) - return Body.getVA(A) + - alignTo(Target->TcbSize, Out::TlsPhdr->p_align); - return Body.getVA(A) - Out::TlsPhdr->p_memsz; + return Body.getVA(A) + alignTo(Target->TcbSize, Out::TlsPhdr->p_align); + return Body.getVA(A) - Out::TlsPhdr->p_memsz; case R_RELAX_TLS_GD_TO_LE_NEG: case R_NEG_TLS: - return Out::TlsPhdr->p_memsz - Body.getVA(A); + return Out::TlsPhdr->p_memsz - Body.getVA(A); case R_ABS: case R_RELAX_GOT_PC_NOPIC: - return Body.getVA(A); + return Body.getVA(A); case R_GOT_OFF: return Body.getGotOffset() + A; case R_MIPS_GOT_LOCAL_PAGE: @@ -411,7 +409,7 @@ getRelocTargetVA(uint32_t Type, int64_t A, typename ELFT::uint P, In::MipsGot->getBodyEntryOffset(Body, A) - In::MipsGot->getGp(); case R_MIPS_GOTREL: - return Body.getVA(A) - In::MipsGot->getGp(); + return Body.getVA(A) - In::MipsGot->getGp(); case R_MIPS_TLSGD: return In::MipsGot->getVA() + In::MipsGot->getTlsOffset() + In::MipsGot->getGlobalDynOffset(Body) - @@ -420,7 +418,7 @@ getRelocTargetVA(uint32_t Type, int64_t A, typename ELFT::uint P, return In::MipsGot->getVA() + In::MipsGot->getTlsOffset() + In::MipsGot->getTlsIndexOff() - In::MipsGot->getGp(); case R_PPC_OPD: { - uint64_t SymVA = Body.getVA(A); + uint64_t SymVA = Body.getVA(A); // If we have an undefined weak symbol, we might get here with a symbol // address of zero. That could overflow, but the code must be unreachable, // so don't bother doing anything at all. @@ -447,12 +445,12 @@ getRelocTargetVA(uint32_t Type, int64_t A, typename ELFT::uint P, return getAArch64UndefinedRelativeWeakVA(Type, A, P); } case R_RELAX_GOT_PC: - return Body.getVA(A) - P; + return Body.getVA(A) - P; case R_PLT_PAGE_PC: case R_PAGE_PC: if (Body.isUndefined() && !Body.isLocal() && Body.symbol()->isWeak()) return getAArch64Page(A); - return getAArch64Page(Body.getVA(A)) - getAArch64Page(P); + return getAArch64Page(Body.getVA(A)) - getAArch64Page(P); } llvm_unreachable("Invalid expression"); } diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 99a041988d60..36dbb7a10ec8 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -916,7 +916,7 @@ uint64_t LinkerScript::getSymbolValue(const Twine &Loc, StringRef S) { if (S == ".") return Dot; if (SymbolBody *B = Symtab::X->find(S)) - return B->getVA(); + return B->getVA(); error(Loc + ": symbol not found: " + S); return 0; } diff --git a/lld/ELF/MapFile.cpp b/lld/ELF/MapFile.cpp index e1194b5bf411..31c8091bb6a1 100644 --- a/lld/ELF/MapFile.cpp +++ b/lld/ELF/MapFile.cpp @@ -87,7 +87,7 @@ static void writeInputSection(raw_fd_ostream &OS, const InputSection *IS, continue; if (DR->isSection()) continue; - writeSymbolLine(OS, Width, Sym->getVA(), Sym->getSize(), + writeSymbolLine(OS, Width, Sym->getVA(), Sym->getSize(), toString(*Sym)); OS << '\n'; } diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp index 4b9186557d9e..746263440900 100644 --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -38,8 +38,7 @@ DefinedRegular *ElfSym::MipsGpDisp; DefinedRegular *ElfSym::MipsLocalGp; DefinedRegular *ElfSym::MipsGp; -template -static typename ELFT::uint getSymVA(const SymbolBody &Body, int64_t &Addend) { +static uint64_t getSymVA(const SymbolBody &Body, int64_t &Addend) { switch (Body.kind()) { case SymbolBody::DefinedRegularKind: { auto &D = cast(Body); @@ -101,7 +100,7 @@ static typename ELFT::uint getSymVA(const SymbolBody &Body, int64_t &Addend) { case SymbolBody::DefinedCommonKind: if (!Config->DefineCommon) return 0; - return In::Common->OutSec->Addr + In::Common->OutSecOff + + return InX::Common->OutSec->Addr + InX::Common->OutSecOff + cast(Body).Offset; case SymbolBody::SharedKind: { auto &SS = cast(Body); @@ -109,7 +108,7 @@ static typename ELFT::uint getSymVA(const SymbolBody &Body, int64_t &Addend) { return SS.CopyRelSec->OutSec->Addr + SS.CopyRelSec->OutSecOff + SS.CopyRelSecOff; if (SS.NeedsPltAddr) - return Body.getPltVA(); + return Body.getPltVA(); return 0; } case SymbolBody::UndefinedKind: @@ -158,9 +157,8 @@ bool SymbolBody::isPreemptible() const { return true; } -template -typename ELFT::uint SymbolBody::getVA(int64_t Addend) const { - typename ELFT::uint OutVA = getSymVA(*this, Addend); +uint64_t SymbolBody::getVA(int64_t Addend) const { + uint64_t OutVA = getSymVA(*this, Addend); return OutVA + Addend; } @@ -182,10 +180,10 @@ uint64_t SymbolBody::getGotPltOffset() const { return GotPltIndex * Target->GotPltEntrySize; } -template typename ELFT::uint SymbolBody::getPltVA() const { +uint64_t SymbolBody::getPltVA() const { if (this->IsInIplt) - return In::Iplt->getVA() + PltIndex * Target->PltEntrySize; - return In::Plt->getVA() + Target->PltHeaderSize + + return InX::Iplt->getVA() + PltIndex * Target->PltEntrySize; + return InX::Plt->getVA() + Target->PltHeaderSize + PltIndex * Target->PltEntrySize; } @@ -377,11 +375,6 @@ std::string lld::toString(const SymbolBody &B) { return B.getName(); } -template uint32_t SymbolBody::template getVA(int64_t) const; -template uint32_t SymbolBody::template getVA(int64_t) const; -template uint64_t SymbolBody::template getVA(int64_t) const; -template uint64_t SymbolBody::template getVA(int64_t) const; - template uint32_t SymbolBody::template getGotVA() const; template uint32_t SymbolBody::template getGotVA() const; template uint64_t SymbolBody::template getGotVA() const; @@ -392,11 +385,6 @@ template uint32_t SymbolBody::template getGotOffset() const; template uint64_t SymbolBody::template getGotOffset() const; template uint64_t SymbolBody::template getGotOffset() const; -template uint32_t SymbolBody::template getPltVA() const; -template uint32_t SymbolBody::template getPltVA() const; -template uint64_t SymbolBody::template getPltVA() const; -template uint64_t SymbolBody::template getPltVA() const; - template uint32_t SymbolBody::template getSize() const; template uint32_t SymbolBody::template getSize() const; template uint64_t SymbolBody::template getSize() const; diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h index e53dacacd500..ae4cfae35476 100644 --- a/lld/ELF/Symbols.h +++ b/lld/ELF/Symbols.h @@ -75,13 +75,13 @@ public: bool isInGot() const { return GotIndex != -1U; } bool isInPlt() const { return PltIndex != -1U; } - template typename ELFT::uint getVA(int64_t Addend = 0) const; + uint64_t getVA(int64_t Addend = 0) const; template typename ELFT::uint getGotOffset() const; template typename ELFT::uint getGotVA() const; uint64_t getGotPltOffset() const; uint64_t getGotPltVA() const; - template typename ELFT::uint getPltVA() const; + uint64_t getPltVA() const; template typename ELFT::uint getSize() const; OutputSection *getOutputSection() const; diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 6cd104abe14f..a952a2047ec0 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -790,7 +790,7 @@ MipsGotSection::getPageEntryOffset(const SymbolBody &B, const OutputSection *OutSec = cast(&B)->Section->getOutputSection(); uintX_t SecAddr = getMipsPageAddr(OutSec->Addr); - uintX_t SymAddr = getMipsPageAddr(B.getVA(Addend)); + uintX_t SymAddr = getMipsPageAddr(B.getVA(Addend)); uintX_t Index = PageIndexMap.lookup(OutSec) + (SymAddr - SecAddr) / 0xffff; assert(Index < PageEntriesNum); return (HeaderEntriesNum + Index) * sizeof(uintX_t); @@ -870,7 +870,7 @@ template bool MipsGotSection::empty() const { template typename MipsGotSection::uintX_t MipsGotSection::getGp() const { - return ElfSym::MipsGp->template getVA(0); + return ElfSym::MipsGp->getVA(0); } template @@ -911,7 +911,7 @@ template void MipsGotSection::writeTo(uint8_t *Buf) { uint8_t *Entry = Buf; Buf += sizeof(uintX_t); const SymbolBody *Body = SA.first; - uintX_t VA = Body->template getVA(SA.second); + uintX_t VA = Body->getVA(SA.second); writeUint(Entry, VA); }; std::for_each(std::begin(LocalEntries), std::end(LocalEntries), AddEntry); @@ -927,7 +927,7 @@ template void MipsGotSection::writeTo(uint8_t *Buf) { for (const SymbolBody *B : TlsEntries) { if (!B || B->isPreemptible()) continue; - uintX_t VA = B->getVA(); + uintX_t VA = B->getVA(); if (B->GotIndex != -1U) { uint8_t *Entry = Buf + B->GotIndex * sizeof(uintX_t); writeUint(Entry, VA - 0x7000); @@ -1187,7 +1187,7 @@ template void DynamicSection::writeTo(uint8_t *Buf) { P->d_un.d_val = E.OutSec->Size; break; case Entry::SymAddr: - P->d_un.d_ptr = E.Sym->template getVA(); + P->d_un.d_ptr = E.Sym->getVA(); break; case Entry::PlainInt: P->d_un.d_val = E.Val; @@ -1204,7 +1204,7 @@ uint64_t DynamicReloc::getOffset() const { template int64_t DynamicReloc::getAddend() const { if (UseSymVA) - return Sym->getVA(Addend); + return Sym->getVA(Addend); return Addend; } @@ -1405,7 +1405,7 @@ template void SymbolTableSection::writeTo(uint8_t *Buf) { if (!Config->DefineCommon && isa(Body)) ESym->st_value = cast(Body)->Alignment; else - ESym->st_value = Body->getVA(); + ESym->st_value = Body->getVA(); ++ESym; } diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index 6b25840a7c7b..57cb64300617 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -415,12 +415,12 @@ void X86TargetInfo::writeGotPltHeader(uint8_t *Buf) const { void X86TargetInfo::writeGotPlt(uint8_t *Buf, const SymbolBody &S) const { // Entries in .got.plt initially points back to the corresponding // PLT entries with a fixed offset to skip the first instruction. - write32le(Buf, S.getPltVA() + 6); + write32le(Buf, S.getPltVA() + 6); } void X86TargetInfo::writeIgotPlt(uint8_t *Buf, const SymbolBody &S) const { // An x86 entry is the address of the ifunc resolver function. - write32le(Buf, S.getVA()); + write32le(Buf, S.getVA()); } uint32_t X86TargetInfo::getDynRel(uint32_t Type) const { @@ -704,7 +704,7 @@ template void X86_64TargetInfo::writeGotPlt(uint8_t *Buf, const SymbolBody &S) const { // See comments in X86TargetInfo::writeGotPlt. - write32le(Buf, S.getPltVA() + 6); + write32le(Buf, S.getPltVA() + 6); } template @@ -1743,7 +1743,7 @@ void ARMTargetInfo::writeGotPlt(uint8_t *Buf, const SymbolBody &) const { void ARMTargetInfo::writeIgotPlt(uint8_t *Buf, const SymbolBody &S) const { // An ARM entry is the address of the ifunc resolver function. - write32le(Buf, S.getVA()); + write32le(Buf, S.getVA()); } void ARMTargetInfo::writePltHeader(uint8_t *Buf) const { @@ -1807,14 +1807,14 @@ bool ARMTargetInfo::needsThunk(RelExpr Expr, uint32_t RelocType, case R_ARM_JUMP24: // Source is ARM, all PLT entries are ARM so no interworking required. // Otherwise we need to interwork if Symbol has bit 0 set (Thumb). - if (Expr == R_PC && ((S.getVA() & 1) == 1)) + if (Expr == R_PC && ((S.getVA() & 1) == 1)) return true; break; case R_ARM_THM_JUMP19: case R_ARM_THM_JUMP24: // Source is Thumb, all PLT entries are ARM so interworking is required. // Otherwise we need to interwork if Symbol has bit 0 clear (ARM). - if (Expr == R_PLT_PC || ((S.getVA() & 1) == 0)) + if (Expr == R_PLT_PC || ((S.getVA() & 1) == 0)) return true; break; } diff --git a/lld/ELF/Thunks.cpp b/lld/ELF/Thunks.cpp index 3204ae8a4a99..45de4ddae902 100644 --- a/lld/ELF/Thunks.cpp +++ b/lld/ELF/Thunks.cpp @@ -104,8 +104,8 @@ public: } // end anonymous namespace // ARM Target Thunks -template static uint64_t getARMThunkDestVA(const SymbolBody &S) { - uint64_t V = S.isInPlt() ? S.getPltVA() : S.getVA(); +static uint64_t getARMThunkDestVA(const SymbolBody &S) { + uint64_t V = S.isInPlt() ? S.getPltVA() : S.getVA(); return SignExtend64<32>(V); } @@ -117,7 +117,7 @@ void ARMToThumbV7ABSLongThunk::writeTo(uint8_t *Buf, 0x00, 0xc0, 0x40, 0xe3, // movt ip,:upper16:S 0x1c, 0xff, 0x2f, 0xe1, // bx ip }; - uint64_t S = getARMThunkDestVA(this->Destination); + uint64_t S = getARMThunkDestVA(this->Destination); memcpy(Buf, Data, sizeof(Data)); Target->relocateOne(Buf, R_ARM_MOVW_ABS_NC, S); Target->relocateOne(Buf + 4, R_ARM_MOVT_ABS, S); @@ -139,7 +139,7 @@ void ThumbToARMV7ABSLongThunk::writeTo(uint8_t *Buf, 0xc0, 0xf2, 0x00, 0x0c, // movt ip, :upper16:S 0x60, 0x47, // bx ip }; - uint64_t S = getARMThunkDestVA(this->Destination); + uint64_t S = getARMThunkDestVA(this->Destination); memcpy(Buf, Data, sizeof(Data)); Target->relocateOne(Buf, R_ARM_THM_MOVW_ABS_NC, S); Target->relocateOne(Buf + 4, R_ARM_THM_MOVT_ABS, S); @@ -162,8 +162,8 @@ void ARMToThumbV7PILongThunk::writeTo(uint8_t *Buf, 0x0f, 0xc0, 0x8c, 0xe0, // L1: add ip, ip, pc 0x1c, 0xff, 0x2f, 0xe1, // bx r12 }; - uint64_t S = getARMThunkDestVA(this->Destination); - uint64_t P = this->ThunkSym->template getVA(); + uint64_t S = getARMThunkDestVA(this->Destination); + uint64_t P = this->ThunkSym->getVA(); memcpy(Buf, Data, sizeof(Data)); Target->relocateOne(Buf, R_ARM_MOVW_PREL_NC, S - P - 16); Target->relocateOne(Buf + 4, R_ARM_MOVT_PREL, S - P - 12); @@ -186,8 +186,8 @@ void ThumbToARMV7PILongThunk::writeTo(uint8_t *Buf, 0xfc, 0x44, // L1: add r12, pc 0x60, 0x47, // bx r12 }; - uint64_t S = getARMThunkDestVA(this->Destination); - uint64_t P = this->ThunkSym->template getVA(); + uint64_t S = getARMThunkDestVA(this->Destination); + uint64_t P = this->ThunkSym->getVA(); memcpy(Buf, Data, sizeof(Data)); Target->relocateOne(Buf, R_ARM_THM_MOVW_PREL_NC, S - P - 12); Target->relocateOne(Buf + 4, R_ARM_THM_MOVT_PREL, S - P - 8); @@ -206,7 +206,7 @@ template void MipsThunk::writeTo(uint8_t *Buf, ThunkSection &) const { const endianness E = ELFT::TargetEndianness; - uint64_t S = this->Destination.template getVA(); + uint64_t S = this->Destination.getVA(); write32(Buf, 0x3c190000); // lui $25, %hi(func) write32(Buf + 4, 0x08000000 | (S >> 2)); // j func write32(Buf + 8, 0x27390000); // addiu $25, $25, %lo(func) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 94b9e229b587..34ad49f61fa9 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1612,7 +1612,7 @@ template typename ELFT::uint Writer::getEntryAddr() { // Case 1, 2 or 3. As a special case, if the symbol is actually // a number, we'll use that number as an address. if (SymbolBody *B = Symtab::X->find(Config->Entry)) - return B->getVA(); + return B->getVA(); uint64_t Addr; if (!Config->Entry.getAsInteger(0, Addr)) return Addr;