[lld] r298071 - [ELF] - Detemplate SymbolBody::getVA and SymbolBody::getPltVA. NFC.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 17 04:56:55 PDT 2017
Author: grimar
Date: Fri Mar 17 06:56:54 2017
New Revision: 298071
URL: http://llvm.org/viewvc/llvm-project?rev=298071&view=rev
Log:
[ELF] - Detemplate SymbolBody::getVA and SymbolBody::getPltVA. NFC.
Modified:
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/MapFile.cpp
lld/trunk/ELF/Symbols.cpp
lld/trunk/ELF/Symbols.h
lld/trunk/ELF/SyntheticSections.cpp
lld/trunk/ELF/Target.cpp
lld/trunk/ELF/Thunks.cpp
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=298071&r1=298070&r2=298071&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Fri Mar 17 06:56:54 2017
@@ -272,7 +272,7 @@ void InputSection::copyRelocations(uint8
}
if (Config->isRela()) {
- P->r_addend += Body.getVA<ELFT>() - 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
return getAArch64Page(In<ELFT>::Got->getGlobalDynAddr(Body) + A) -
getAArch64Page(P);
case R_PLT:
- return Body.getPltVA<ELFT>() + A;
+ return Body.getPltVA() + A;
case R_PLT_PC:
case R_PPC_PLT_OPD:
- return Body.getPltVA<ELFT>() + A - P;
+ return Body.getPltVA() + A - P;
case R_SIZE:
return Body.getSize<ELFT>() + A;
case R_GOTREL:
- return Body.getVA<ELFT>(A) - In<ELFT>::Got->getVA();
+ return Body.getVA(A) - In<ELFT>::Got->getVA();
case R_GOTREL_FROM_END:
- return Body.getVA<ELFT>(A) - In<ELFT>::Got->getVA() -
- In<ELFT>::Got->getSize();
+ return Body.getVA(A) - In<ELFT>::Got->getVA() - In<ELFT>::Got->getSize();
case R_RELAX_TLS_GD_TO_IE_END:
case R_GOT_FROM_END:
return Body.getGotOffset<ELFT>() + A - In<ELFT>::Got->getSize();
@@ -384,15 +383,14 @@ getRelocTargetVA(uint32_t Type, int64_t
Body.symbol()->isWeak())
return 0;
if (Target->TcbSize)
- return Body.getVA<ELFT>(A) +
- alignTo(Target->TcbSize, Out::TlsPhdr->p_align);
- return Body.getVA<ELFT>(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<ELFT>(A);
+ return Out::TlsPhdr->p_memsz - Body.getVA(A);
case R_ABS:
case R_RELAX_GOT_PC_NOPIC:
- return Body.getVA<ELFT>(A);
+ return Body.getVA(A);
case R_GOT_OFF:
return Body.getGotOffset<ELFT>() + A;
case R_MIPS_GOT_LOCAL_PAGE:
@@ -411,7 +409,7 @@ getRelocTargetVA(uint32_t Type, int64_t
In<ELFT>::MipsGot->getBodyEntryOffset(Body, A) -
In<ELFT>::MipsGot->getGp();
case R_MIPS_GOTREL:
- return Body.getVA<ELFT>(A) - In<ELFT>::MipsGot->getGp();
+ return Body.getVA(A) - In<ELFT>::MipsGot->getGp();
case R_MIPS_TLSGD:
return In<ELFT>::MipsGot->getVA() + In<ELFT>::MipsGot->getTlsOffset() +
In<ELFT>::MipsGot->getGlobalDynOffset(Body) -
@@ -420,7 +418,7 @@ getRelocTargetVA(uint32_t Type, int64_t
return In<ELFT>::MipsGot->getVA() + In<ELFT>::MipsGot->getTlsOffset() +
In<ELFT>::MipsGot->getTlsIndexOff() - In<ELFT>::MipsGot->getGp();
case R_PPC_OPD: {
- uint64_t SymVA = Body.getVA<ELFT>(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
return getAArch64UndefinedRelativeWeakVA(Type, A, P);
}
case R_RELAX_GOT_PC:
- return Body.getVA<ELFT>(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<ELFT>(A)) - getAArch64Page(P);
+ return getAArch64Page(Body.getVA(A)) - getAArch64Page(P);
}
llvm_unreachable("Invalid expression");
}
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=298071&r1=298070&r2=298071&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Fri Mar 17 06:56:54 2017
@@ -916,7 +916,7 @@ uint64_t LinkerScript<ELFT>::getSymbolVa
if (S == ".")
return Dot;
if (SymbolBody *B = Symtab<ELFT>::X->find(S))
- return B->getVA<ELFT>();
+ return B->getVA();
error(Loc + ": symbol not found: " + S);
return 0;
}
Modified: lld/trunk/ELF/MapFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MapFile.cpp?rev=298071&r1=298070&r2=298071&view=diff
==============================================================================
--- lld/trunk/ELF/MapFile.cpp (original)
+++ lld/trunk/ELF/MapFile.cpp Fri Mar 17 06:56:54 2017
@@ -87,7 +87,7 @@ static void writeInputSection(raw_fd_ost
continue;
if (DR->isSection())
continue;
- writeSymbolLine(OS, Width, Sym->getVA<ELFT>(), Sym->getSize<ELFT>(),
+ writeSymbolLine(OS, Width, Sym->getVA(), Sym->getSize<ELFT>(),
toString(*Sym));
OS << '\n';
}
Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=298071&r1=298070&r2=298071&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Fri Mar 17 06:56:54 2017
@@ -38,8 +38,7 @@ DefinedRegular *ElfSym::MipsGpDisp;
DefinedRegular *ElfSym::MipsLocalGp;
DefinedRegular *ElfSym::MipsGp;
-template <class ELFT>
-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<DefinedRegular>(Body);
@@ -101,7 +100,7 @@ static typename ELFT::uint getSymVA(cons
case SymbolBody::DefinedCommonKind:
if (!Config->DefineCommon)
return 0;
- return In<ELFT>::Common->OutSec->Addr + In<ELFT>::Common->OutSecOff +
+ return InX::Common->OutSec->Addr + InX::Common->OutSecOff +
cast<DefinedCommon>(Body).Offset;
case SymbolBody::SharedKind: {
auto &SS = cast<SharedSymbol>(Body);
@@ -109,7 +108,7 @@ static typename ELFT::uint getSymVA(cons
return SS.CopyRelSec->OutSec->Addr + SS.CopyRelSec->OutSecOff +
SS.CopyRelSecOff;
if (SS.NeedsPltAddr)
- return Body.getPltVA<ELFT>();
+ return Body.getPltVA();
return 0;
}
case SymbolBody::UndefinedKind:
@@ -158,9 +157,8 @@ bool SymbolBody::isPreemptible() const {
return true;
}
-template <class ELFT>
-typename ELFT::uint SymbolBody::getVA(int64_t Addend) const {
- typename ELFT::uint OutVA = getSymVA<ELFT>(*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() c
return GotPltIndex * Target->GotPltEntrySize;
}
-template <class ELFT> typename ELFT::uint SymbolBody::getPltVA() const {
+uint64_t SymbolBody::getPltVA() const {
if (this->IsInIplt)
- return In<ELFT>::Iplt->getVA() + PltIndex * Target->PltEntrySize;
- return In<ELFT>::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 SymbolBo
return B.getName();
}
-template uint32_t SymbolBody::template getVA<ELF32LE>(int64_t) const;
-template uint32_t SymbolBody::template getVA<ELF32BE>(int64_t) const;
-template uint64_t SymbolBody::template getVA<ELF64LE>(int64_t) const;
-template uint64_t SymbolBody::template getVA<ELF64BE>(int64_t) const;
-
template uint32_t SymbolBody::template getGotVA<ELF32LE>() const;
template uint32_t SymbolBody::template getGotVA<ELF32BE>() const;
template uint64_t SymbolBody::template getGotVA<ELF64LE>() const;
@@ -392,11 +385,6 @@ template uint32_t SymbolBody::template g
template uint64_t SymbolBody::template getGotOffset<ELF64LE>() const;
template uint64_t SymbolBody::template getGotOffset<ELF64BE>() const;
-template uint32_t SymbolBody::template getPltVA<ELF32LE>() const;
-template uint32_t SymbolBody::template getPltVA<ELF32BE>() const;
-template uint64_t SymbolBody::template getPltVA<ELF64LE>() const;
-template uint64_t SymbolBody::template getPltVA<ELF64BE>() const;
-
template uint32_t SymbolBody::template getSize<ELF32LE>() const;
template uint32_t SymbolBody::template getSize<ELF32BE>() const;
template uint64_t SymbolBody::template getSize<ELF64LE>() const;
Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=298071&r1=298070&r2=298071&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Fri Mar 17 06:56:54 2017
@@ -75,13 +75,13 @@ public:
bool isInGot() const { return GotIndex != -1U; }
bool isInPlt() const { return PltIndex != -1U; }
- template <class ELFT> typename ELFT::uint getVA(int64_t Addend = 0) const;
+ uint64_t getVA(int64_t Addend = 0) const;
template <class ELFT> typename ELFT::uint getGotOffset() const;
template <class ELFT> typename ELFT::uint getGotVA() const;
uint64_t getGotPltOffset() const;
uint64_t getGotPltVA() const;
- template <class ELFT> typename ELFT::uint getPltVA() const;
+ uint64_t getPltVA() const;
template <class ELFT> typename ELFT::uint getSize() const;
OutputSection *getOutputSection() const;
Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=298071&r1=298070&r2=298071&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Fri Mar 17 06:56:54 2017
@@ -790,7 +790,7 @@ MipsGotSection<ELFT>::getPageEntryOffset
const OutputSection *OutSec =
cast<DefinedRegular>(&B)->Section->getOutputSection();
uintX_t SecAddr = getMipsPageAddr(OutSec->Addr);
- uintX_t SymAddr = getMipsPageAddr(B.getVA<ELFT>(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 <class ELFT> bool MipsGotSectio
template <class ELFT>
typename MipsGotSection<ELFT>::uintX_t MipsGotSection<ELFT>::getGp() const {
- return ElfSym::MipsGp->template getVA<ELFT>(0);
+ return ElfSym::MipsGp->getVA(0);
}
template <class ELFT>
@@ -911,7 +911,7 @@ template <class ELFT> void MipsGotSectio
uint8_t *Entry = Buf;
Buf += sizeof(uintX_t);
const SymbolBody *Body = SA.first;
- uintX_t VA = Body->template getVA<ELFT>(SA.second);
+ uintX_t VA = Body->getVA(SA.second);
writeUint<ELFT>(Entry, VA);
};
std::for_each(std::begin(LocalEntries), std::end(LocalEntries), AddEntry);
@@ -927,7 +927,7 @@ template <class ELFT> void MipsGotSectio
for (const SymbolBody *B : TlsEntries) {
if (!B || B->isPreemptible())
continue;
- uintX_t VA = B->getVA<ELFT>();
+ uintX_t VA = B->getVA();
if (B->GotIndex != -1U) {
uint8_t *Entry = Buf + B->GotIndex * sizeof(uintX_t);
writeUint<ELFT>(Entry, VA - 0x7000);
@@ -1187,7 +1187,7 @@ template <class ELFT> void DynamicSectio
P->d_un.d_val = E.OutSec->Size;
break;
case Entry::SymAddr:
- P->d_un.d_ptr = E.Sym->template getVA<ELFT>();
+ 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<ELFT>::getOffset()
template <class ELFT> int64_t DynamicReloc<ELFT>::getAddend() const {
if (UseSymVA)
- return Sym->getVA<ELFT>(Addend);
+ return Sym->getVA(Addend);
return Addend;
}
@@ -1405,7 +1405,7 @@ template <class ELFT> void SymbolTableSe
if (!Config->DefineCommon && isa<DefinedCommon>(Body))
ESym->st_value = cast<DefinedCommon>(Body)->Alignment;
else
- ESym->st_value = Body->getVA<ELFT>();
+ ESym->st_value = Body->getVA();
++ESym;
}
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=298071&r1=298070&r2=298071&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Fri Mar 17 06:56:54 2017
@@ -415,12 +415,12 @@ void X86TargetInfo::writeGotPltHeader(ui
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<ELF32LE>() + 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<ELF32LE>());
+ write32le(Buf, S.getVA());
}
uint32_t X86TargetInfo::getDynRel(uint32_t Type) const {
@@ -704,7 +704,7 @@ template <class ELFT>
void X86_64TargetInfo<ELFT>::writeGotPlt(uint8_t *Buf,
const SymbolBody &S) const {
// See comments in X86TargetInfo::writeGotPlt.
- write32le(Buf, S.getPltVA<ELFT>() + 6);
+ write32le(Buf, S.getPltVA() + 6);
}
template <class ELFT>
@@ -1743,7 +1743,7 @@ void ARMTargetInfo::writeGotPlt(uint8_t
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<ELF32LE>());
+ write32le(Buf, S.getVA());
}
void ARMTargetInfo::writePltHeader(uint8_t *Buf) const {
@@ -1807,14 +1807,14 @@ bool ARMTargetInfo::needsThunk(RelExpr E
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<ELF32LE>() & 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<ELF32LE>() & 1) == 0))
+ if (Expr == R_PLT_PC || ((S.getVA() & 1) == 0))
return true;
break;
}
Modified: lld/trunk/ELF/Thunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Thunks.cpp?rev=298071&r1=298070&r2=298071&view=diff
==============================================================================
--- lld/trunk/ELF/Thunks.cpp (original)
+++ lld/trunk/ELF/Thunks.cpp Fri Mar 17 06:56:54 2017
@@ -104,8 +104,8 @@ public:
} // end anonymous namespace
// ARM Target Thunks
-template <class ELFT> static uint64_t getARMThunkDestVA(const SymbolBody &S) {
- uint64_t V = S.isInPlt() ? S.getPltVA<ELFT>() : S.getVA<ELFT>();
+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<ELFT>::wri
0x00, 0xc0, 0x40, 0xe3, // movt ip,:upper16:S
0x1c, 0xff, 0x2f, 0xe1, // bx ip
};
- uint64_t S = getARMThunkDestVA<ELFT>(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<ELFT>::wri
0xc0, 0xf2, 0x00, 0x0c, // movt ip, :upper16:S
0x60, 0x47, // bx ip
};
- uint64_t S = getARMThunkDestVA<ELFT>(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<ELFT>::writ
0x0f, 0xc0, 0x8c, 0xe0, // L1: add ip, ip, pc
0x1c, 0xff, 0x2f, 0xe1, // bx r12
};
- uint64_t S = getARMThunkDestVA<ELFT>(this->Destination);
- uint64_t P = this->ThunkSym->template getVA<ELFT>();
+ 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<ELFT>::writ
0xfc, 0x44, // L1: add r12, pc
0x60, 0x47, // bx r12
};
- uint64_t S = getARMThunkDestVA<ELFT>(this->Destination);
- uint64_t P = this->ThunkSym->template getVA<ELFT>();
+ 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 <class ELFT>
void MipsThunk<ELFT>::writeTo(uint8_t *Buf, ThunkSection &) const {
const endianness E = ELFT::TargetEndianness;
- uint64_t S = this->Destination.template getVA<ELFT>();
+ uint64_t S = this->Destination.getVA();
write32<E>(Buf, 0x3c190000); // lui $25, %hi(func)
write32<E>(Buf + 4, 0x08000000 | (S >> 2)); // j func
write32<E>(Buf + 8, 0x27390000); // addiu $25, $25, %lo(func)
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=298071&r1=298070&r2=298071&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Mar 17 06:56:54 2017
@@ -1612,7 +1612,7 @@ template <class ELFT> typename ELFT::uin
// 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<ELFT>::X->find(Config->Entry))
- return B->getVA<ELFT>();
+ return B->getVA();
uint64_t Addr;
if (!Config->Entry.getAsInteger(0, Addr))
return Addr;
More information about the llvm-commits
mailing list