diff options
Diffstat (limited to 'lld/ELF')
| -rw-r--r-- | lld/ELF/InputSection.cpp | 28 | ||||
| -rw-r--r-- | lld/ELF/LinkerScript.cpp | 2 | ||||
| -rw-r--r-- | lld/ELF/MapFile.cpp | 2 | ||||
| -rw-r--r-- | lld/ELF/Symbols.cpp | 28 | ||||
| -rw-r--r-- | lld/ELF/Symbols.h | 4 | ||||
| -rw-r--r-- | lld/ELF/SyntheticSections.cpp | 14 | ||||
| -rw-r--r-- | lld/ELF/Target.cpp | 12 | ||||
| -rw-r--r-- | lld/ELF/Thunks.cpp | 18 | ||||
| -rw-r--r-- | 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 79a04fc3441..b1d10e70542 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -272,7 +272,7 @@ void InputSection::copyRelocations(uint8_t *Buf, ArrayRef<RelTy> Rels) { } 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 A, typename ELFT::uint P, 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 A, typename ELFT::uint P, 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 A, typename ELFT::uint P, 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 A, typename ELFT::uint P, 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 A, typename ELFT::uint P, 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"); } diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 99a041988d6..36dbb7a10ec 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -916,7 +916,7 @@ uint64_t LinkerScript<ELFT>::getSymbolValue(const Twine &Loc, StringRef S) { 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; } diff --git a/lld/ELF/MapFile.cpp b/lld/ELF/MapFile.cpp index e1194b5bf41..31c8091bb6a 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<ELFT>(), Sym->getSize<ELFT>(), + writeSymbolLine(OS, Width, Sym->getVA(), Sym->getSize<ELFT>(), toString(*Sym)); OS << '\n'; } diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp index 4b9186557d9..74626344090 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 <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(const SymbolBody &Body, int64_t &Addend) { 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(const SymbolBody &Body, int64_t &Addend) { 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() const { 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 SymbolBody &B) { 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 getGotOffset<ELF32BE>() const; 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; diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h index e53dacacd50..ae4cfae3547 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 <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; diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 6cd104abe14..a952a2047ec 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -790,7 +790,7 @@ MipsGotSection<ELFT>::getPageEntryOffset(const SymbolBody &B, 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 MipsGotSection<ELFT>::empty() const { 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 MipsGotSection<ELFT>::writeTo(uint8_t *Buf) { 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 MipsGotSection<ELFT>::writeTo(uint8_t *Buf) { 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 DynamicSection<ELFT>::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<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() const { 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 SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) { 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; } diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index 6b25840a7c7..57cb6430061 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<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 *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<ELF32LE>()); + 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<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; } diff --git a/lld/ELF/Thunks.cpp b/lld/ELF/Thunks.cpp index 3204ae8a4a9..45de4ddae90 100644 --- a/lld/ELF/Thunks.cpp +++ b/lld/ELF/Thunks.cpp @@ -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>::writeTo(uint8_t *Buf, 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>::writeTo(uint8_t *Buf, 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>::writeTo(uint8_t *Buf, 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>::writeTo(uint8_t *Buf, 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) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 94b9e229b58..34ad49f61fa 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1612,7 +1612,7 @@ template <class ELFT> typename ELFT::uint Writer<ELFT>::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<ELFT>::X->find(Config->Entry)) - return B->getVA<ELFT>(); + return B->getVA(); uint64_t Addr; if (!Config->Entry.getAsInteger(0, Addr)) return Addr; |

