diff options
Diffstat (limited to 'ELF/Thunks.cpp')
-rw-r--r-- | ELF/Thunks.cpp | 128 |
1 files changed, 56 insertions, 72 deletions
diff --git a/ELF/Thunks.cpp b/ELF/Thunks.cpp index 80ea69663c01..da2b13677513 100644 --- a/ELF/Thunks.cpp +++ b/ELF/Thunks.cpp @@ -50,7 +50,7 @@ namespace { // Specific ARM Thunk implementations. The naming convention is: // Source State, TargetState, Target Requirement, ABS or PI, Range -template <class ELFT> class ARMV7ABSLongThunk final : public Thunk { +class ARMV7ABSLongThunk final : public Thunk { public: ARMV7ABSLongThunk(const SymbolBody &Dest) : Thunk(Dest) {} @@ -59,7 +59,7 @@ public: void addSymbols(ThunkSection &IS) override; }; -template <class ELFT> class ARMV7PILongThunk final : public Thunk { +class ARMV7PILongThunk final : public Thunk { public: ARMV7PILongThunk(const SymbolBody &Dest) : Thunk(Dest) {} @@ -68,7 +68,7 @@ public: void addSymbols(ThunkSection &IS) override; }; -template <class ELFT> class ThumbV7ABSLongThunk final : public Thunk { +class ThumbV7ABSLongThunk final : public Thunk { public: ThumbV7ABSLongThunk(const SymbolBody &Dest) : Thunk(Dest) { this->alignment = 2; @@ -79,7 +79,7 @@ public: void addSymbols(ThunkSection &IS) override; }; -template <class ELFT> class ThumbV7PILongThunk final : public Thunk { +class ThumbV7PILongThunk final : public Thunk { public: ThumbV7PILongThunk(const SymbolBody &Dest) : Thunk(Dest) { this->alignment = 2; @@ -91,7 +91,7 @@ public: }; // MIPS LA25 thunk -template <class ELFT> class MipsThunk final : public Thunk { +class MipsThunk final : public Thunk { public: MipsThunk(const SymbolBody &Dest) : Thunk(Dest) {} @@ -109,117 +109,105 @@ static uint64_t getARMThunkDestVA(const SymbolBody &S) { return SignExtend64<32>(V); } -template <class ELFT> -void ARMV7ABSLongThunk<ELFT>::writeTo(uint8_t *Buf, ThunkSection &IS) const { +void ARMV7ABSLongThunk::writeTo(uint8_t *Buf, ThunkSection &IS) const { const uint8_t Data[] = { 0x00, 0xc0, 0x00, 0xe3, // movw ip,:lower16:S 0x00, 0xc0, 0x40, 0xe3, // movt ip,:upper16:S 0x1c, 0xff, 0x2f, 0xe1, // bx ip }; - uint64_t S = getARMThunkDestVA(this->Destination); + uint64_t S = getARMThunkDestVA(Destination); memcpy(Buf, Data, sizeof(Data)); Target->relocateOne(Buf, R_ARM_MOVW_ABS_NC, S); Target->relocateOne(Buf + 4, R_ARM_MOVT_ABS, S); } -template <class ELFT> -void ARMV7ABSLongThunk<ELFT>::addSymbols(ThunkSection &IS) { - this->ThunkSym = addSyntheticLocal( - Saver.save("__ARMv7ABSLongThunk_" + this->Destination.getName()), - STT_FUNC, this->Offset, size(), &IS); - addSyntheticLocal("$a", STT_NOTYPE, this->Offset, 0, &IS); +void ARMV7ABSLongThunk::addSymbols(ThunkSection &IS) { + ThunkSym = addSyntheticLocal( + Saver.save("__ARMv7ABSLongThunk_" + Destination.getName()), STT_FUNC, + Offset, size(), &IS); + addSyntheticLocal("$a", STT_NOTYPE, Offset, 0, &IS); } -template <class ELFT> -void ThumbV7ABSLongThunk<ELFT>::writeTo(uint8_t *Buf, ThunkSection &IS) const { +void ThumbV7ABSLongThunk::writeTo(uint8_t *Buf, ThunkSection &IS) const { const uint8_t Data[] = { 0x40, 0xf2, 0x00, 0x0c, // movw ip, :lower16:S 0xc0, 0xf2, 0x00, 0x0c, // movt ip, :upper16:S 0x60, 0x47, // bx ip }; - uint64_t S = getARMThunkDestVA(this->Destination); + uint64_t S = getARMThunkDestVA(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); } -template <class ELFT> -void ThumbV7ABSLongThunk<ELFT>::addSymbols(ThunkSection &IS) { - this->ThunkSym = addSyntheticLocal( - Saver.save("__Thumbv7ABSLongThunk_" + this->Destination.getName()), - STT_FUNC, this->Offset, size(), &IS); - addSyntheticLocal("$t", STT_NOTYPE, this->Offset, 0, &IS); +void ThumbV7ABSLongThunk::addSymbols(ThunkSection &IS) { + ThunkSym = addSyntheticLocal( + Saver.save("__Thumbv7ABSLongThunk_" + Destination.getName()), STT_FUNC, + Offset, size(), &IS); + addSyntheticLocal("$t", STT_NOTYPE, Offset, 0, &IS); } -template <class ELFT> -void ARMV7PILongThunk<ELFT>::writeTo(uint8_t *Buf, ThunkSection &IS) const { +void ARMV7PILongThunk::writeTo(uint8_t *Buf, ThunkSection &IS) const { const uint8_t Data[] = { 0xf0, 0xcf, 0x0f, 0xe3, // P: movw ip,:lower16:S - (P + (L1-P) +8) 0x00, 0xc0, 0x40, 0xe3, // movt ip,:upper16:S - (P + (L1-P+4) +8) 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->getVA(); + uint64_t S = getARMThunkDestVA(Destination); + uint64_t P = 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); } -template <class ELFT> -void ARMV7PILongThunk<ELFT>::addSymbols(ThunkSection &IS) { - this->ThunkSym = addSyntheticLocal( - Saver.save("__ARMV7PILongThunk_" + this->Destination.getName()), STT_FUNC, - this->Offset, size(), &IS); - addSyntheticLocal("$a", STT_NOTYPE, this->Offset, 0, &IS); +void ARMV7PILongThunk::addSymbols(ThunkSection &IS) { + ThunkSym = addSyntheticLocal( + Saver.save("__ARMV7PILongThunk_" + Destination.getName()), STT_FUNC, + Offset, size(), &IS); + addSyntheticLocal("$a", STT_NOTYPE, Offset, 0, &IS); } -template <class ELFT> -void ThumbV7PILongThunk<ELFT>::writeTo(uint8_t *Buf, ThunkSection &IS) const { +void ThumbV7PILongThunk::writeTo(uint8_t *Buf, ThunkSection &IS) const { const uint8_t Data[] = { 0x4f, 0xf6, 0xf4, 0x7c, // P: movw ip,:lower16:S - (P + (L1-P) + 4) 0xc0, 0xf2, 0x00, 0x0c, // movt ip,:upper16:S - (P + (L1-P+4) + 4) 0xfc, 0x44, // L1: add r12, pc 0x60, 0x47, // bx r12 }; - uint64_t S = getARMThunkDestVA(this->Destination); - uint64_t P = this->ThunkSym->getVA(); + uint64_t S = getARMThunkDestVA(Destination); + uint64_t P = 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); } -template <class ELFT> -void ThumbV7PILongThunk<ELFT>::addSymbols(ThunkSection &IS) { - this->ThunkSym = addSyntheticLocal( - Saver.save("__ThumbV7PILongThunk_" + this->Destination.getName()), - STT_FUNC, this->Offset, size(), &IS); - addSyntheticLocal("$t", STT_NOTYPE, this->Offset, 0, &IS); +void ThumbV7PILongThunk::addSymbols(ThunkSection &IS) { + ThunkSym = addSyntheticLocal( + Saver.save("__ThumbV7PILongThunk_" + Destination.getName()), STT_FUNC, + Offset, size(), &IS); + addSyntheticLocal("$t", STT_NOTYPE, Offset, 0, &IS); } // Write MIPS LA25 thunk code to call PIC function from the non-PIC one. -template <class ELFT> -void MipsThunk<ELFT>::writeTo(uint8_t *Buf, ThunkSection &) const { - const endianness E = ELFT::TargetEndianness; - +void MipsThunk::writeTo(uint8_t *Buf, ThunkSection &) const { 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) - write32<E>(Buf + 12, 0x00000000); // nop + write32(Buf, 0x3c190000, Config->Endianness); // lui $25, %hi(func) + write32(Buf + 4, 0x08000000 | (S >> 2), Config->Endianness); // j func + write32(Buf + 8, 0x27390000, Config->Endianness); // addiu $25, $25, %lo(func) + write32(Buf + 12, 0x00000000, Config->Endianness); // nop Target->relocateOne(Buf, R_MIPS_HI16, S); Target->relocateOne(Buf + 8, R_MIPS_LO16, S); } -template <class ELFT> void MipsThunk<ELFT>::addSymbols(ThunkSection &IS) { - this->ThunkSym = addSyntheticLocal( - Saver.save("__LA25Thunk_" + this->Destination.getName()), STT_FUNC, - this->Offset, size(), &IS); +void MipsThunk::addSymbols(ThunkSection &IS) { + ThunkSym = + addSyntheticLocal(Saver.save("__LA25Thunk_" + Destination.getName()), + STT_FUNC, Offset, size(), &IS); } -template <class ELFT> -InputSection *MipsThunk<ELFT>::getTargetInputSection() const { - auto *DR = dyn_cast<DefinedRegular>(&this->Destination); +InputSection *MipsThunk::getTargetInputSection() const { + auto *DR = dyn_cast<DefinedRegular>(&Destination); return dyn_cast<InputSection>(DR->Section); } @@ -228,7 +216,7 @@ Thunk::Thunk(const SymbolBody &D) : Destination(D), Offset(0) {} Thunk::~Thunk() = default; // Creates a thunk for Thumb-ARM interworking. -template <class ELFT> static Thunk *addThunkArm(uint32_t Reloc, SymbolBody &S) { +static Thunk *addThunkArm(uint32_t Reloc, SymbolBody &S) { // ARM relocations need ARM to Thumb interworking Thunks. // Thumb relocations need Thumb to ARM relocations. // Use position independent Thunks if we require position independent code. @@ -237,33 +225,29 @@ template <class ELFT> static Thunk *addThunkArm(uint32_t Reloc, SymbolBody &S) { case R_ARM_PLT32: case R_ARM_JUMP24: if (Config->Pic) - return make<ARMV7PILongThunk<ELFT>>(S); - return make<ARMV7ABSLongThunk<ELFT>>(S); + return make<ARMV7PILongThunk>(S); + return make<ARMV7ABSLongThunk>(S); case R_ARM_THM_JUMP19: case R_ARM_THM_JUMP24: if (Config->Pic) - return make<ThumbV7PILongThunk<ELFT>>(S); - return make<ThumbV7ABSLongThunk<ELFT>>(S); + return make<ThumbV7PILongThunk>(S); + return make<ThumbV7ABSLongThunk>(S); } fatal("unrecognized relocation type"); } -template <class ELFT> static Thunk *addThunkMips(SymbolBody &S) { - return make<MipsThunk<ELFT>>(S); +static Thunk *addThunkMips(SymbolBody &S) { + return make<MipsThunk>(S); } -template <class ELFT> Thunk *addThunk(uint32_t RelocType, SymbolBody &S) { +Thunk *addThunk(uint32_t RelocType, SymbolBody &S) { if (Config->EMachine == EM_ARM) - return addThunkArm<ELFT>(RelocType, S); + return addThunkArm(RelocType, S); else if (Config->EMachine == EM_MIPS) - return addThunkMips<ELFT>(S); + return addThunkMips(S); llvm_unreachable("add Thunk only supported for ARM and Mips"); return nullptr; } -template Thunk *addThunk<ELF32LE>(uint32_t, SymbolBody &); -template Thunk *addThunk<ELF32BE>(uint32_t, SymbolBody &); -template Thunk *addThunk<ELF64LE>(uint32_t, SymbolBody &); -template Thunk *addThunk<ELF64BE>(uint32_t, SymbolBody &); } // end namespace elf } // end namespace lld |