From owner-svn-src-vendor@freebsd.org Wed May 17 20:23:15 2017 Return-Path: Delivered-To: svn-src-vendor@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5DCD5D7163C; Wed, 17 May 2017 20:23:15 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 29D061ED2; Wed, 17 May 2017 20:23:15 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v4HKNEE4015679; Wed, 17 May 2017 20:23:14 GMT (envelope-from dim@FreeBSD.org) Received: (from dim@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v4HKNDNd015674; Wed, 17 May 2017 20:23:13 GMT (envelope-from dim@FreeBSD.org) Message-Id: <201705172023.v4HKNDNd015674@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dim set sender to dim@FreeBSD.org using -f From: Dimitry Andric Date: Wed, 17 May 2017 20:23:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-vendor@freebsd.org Subject: svn commit: r318422 - vendor/lld/dist/ELF X-SVN-Group: vendor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-vendor@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the vendor work area tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 May 2017 20:23:15 -0000 Author: dim Date: Wed May 17 20:23:13 2017 New Revision: 318422 URL: https://svnweb.freebsd.org/changeset/base/318422 Log: Vendor import of lld trunk r303291: https://llvm.org/svn/llvm-project/lld/trunk@303291 Modified: vendor/lld/dist/ELF/Relocations.cpp vendor/lld/dist/ELF/Relocations.h vendor/lld/dist/ELF/Thunks.cpp vendor/lld/dist/ELF/Thunks.h vendor/lld/dist/ELF/Writer.cpp Modified: vendor/lld/dist/ELF/Relocations.cpp ============================================================================== --- vendor/lld/dist/ELF/Relocations.cpp Wed May 17 20:23:11 2017 (r318421) +++ vendor/lld/dist/ELF/Relocations.cpp Wed May 17 20:23:13 2017 (r318422) @@ -963,9 +963,8 @@ template void elf::scanRelo // in the Sections vector, and recalculate the InputSection output section // offsets. // This may invalidate any output section offsets stored outside of InputSection -template -void ThunkCreator::mergeThunks(OutputSection *OS, - std::vector &Thunks) { +void ThunkCreator::mergeThunks(OutputSection *OS, + std::vector &Thunks) { // Order Thunks in ascending OutSecOff auto ThunkCmp = [](const ThunkSection *A, const ThunkSection *B) { return A->OutSecOff < B->OutSecOff; @@ -993,9 +992,8 @@ void ThunkCreator::mergeThunks(Out OS->assignOffsets(); } -template -ThunkSection *ThunkCreator::getOSThunkSec(ThunkSection *&TS, - OutputSection *OS) { +ThunkSection *ThunkCreator::getOSThunkSec(ThunkSection *&TS, + OutputSection *OS) { if (TS == nullptr) { uint32_t Off = 0; for (auto *IS : OS->Sections) { @@ -1009,9 +1007,7 @@ ThunkSection *ThunkCreator::getOST return TS; } -template -ThunkSection *ThunkCreator::getISThunkSec(InputSection *IS, - OutputSection *OS) { +ThunkSection *ThunkCreator::getISThunkSec(InputSection *IS, OutputSection *OS) { ThunkSection *TS = ThunkedSections.lookup(IS); if (TS) return TS; @@ -1022,12 +1018,11 @@ ThunkSection *ThunkCreator::getIST return TS; } -template -std::pair ThunkCreator::getThunk(SymbolBody &Body, - uint32_t Type) { +std::pair ThunkCreator::getThunk(SymbolBody &Body, + uint32_t Type) { auto res = ThunkedSymbols.insert({&Body, nullptr}); if (res.second) - res.first->second = addThunk(Type, Body); + res.first->second = addThunk(Type, Body); return std::make_pair(res.first->second, res.second); } @@ -1041,9 +1036,7 @@ std::pair ThunkCreator -bool ThunkCreator::createThunks( - ArrayRef OutputSections) { +bool ThunkCreator::createThunks(ArrayRef OutputSections) { // Create all the Thunks and insert them into synthetic ThunkSections. The // ThunkSections are later inserted back into the OutputSection. @@ -1086,8 +1079,3 @@ template void elf::scanRelocations(InputSectionBase &); template void elf::scanRelocations(InputSectionBase &); template void elf::scanRelocations(InputSectionBase &); - -template class elf::ThunkCreator; -template class elf::ThunkCreator; -template class elf::ThunkCreator; -template class elf::ThunkCreator; Modified: vendor/lld/dist/ELF/Relocations.h ============================================================================== --- vendor/lld/dist/ELF/Relocations.h Wed May 17 20:23:11 2017 (r318421) +++ vendor/lld/dist/ELF/Relocations.h Wed May 17 20:23:13 2017 (r318422) @@ -119,7 +119,7 @@ template void scanRelocatio class ThunkSection; class Thunk; -template class ThunkCreator { +class ThunkCreator { public: // Return true if Thunks have been added to OutputSections bool createThunks(ArrayRef OutputSections); Modified: vendor/lld/dist/ELF/Thunks.cpp ============================================================================== --- vendor/lld/dist/ELF/Thunks.cpp Wed May 17 20:23:11 2017 (r318421) +++ vendor/lld/dist/ELF/Thunks.cpp Wed May 17 20:23:13 2017 (r318422) @@ -50,7 +50,7 @@ namespace { // Specific ARM Thunk implementations. The naming convention is: // Source State, TargetState, Target Requirement, ABS or PI, Range -template 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 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 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 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 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 return SignExtend64<32>(V); } -template -void ARMV7ABSLongThunk::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 -void ARMV7ABSLongThunk::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 -void ThumbV7ABSLongThunk::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 -void ThumbV7ABSLongThunk::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 -void ARMV7PILongThunk::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 -void ARMV7PILongThunk::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 -void ThumbV7PILongThunk::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 -void ThumbV7PILongThunk::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 -void MipsThunk::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(Buf, 0x3c190000); // lui $25, %hi(func) - write32(Buf + 4, 0x08000000 | (S >> 2)); // j func - write32(Buf + 8, 0x27390000); // addiu $25, $25, %lo(func) - write32(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 void MipsThunk::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 -InputSection *MipsThunk::getTargetInputSection() const { - auto *DR = dyn_cast(&this->Destination); +InputSection *MipsThunk::getTargetInputSection() const { + auto *DR = dyn_cast(&Destination); return dyn_cast(DR->Section); } @@ -228,7 +216,7 @@ Thunk::Thunk(const SymbolBody &D) : Dest Thunk::~Thunk() = default; // Creates a thunk for Thumb-ARM interworking. -template 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 static Thunk *addT case R_ARM_PLT32: case R_ARM_JUMP24: if (Config->Pic) - return make>(S); - return make>(S); + return make(S); + return make(S); case R_ARM_THM_JUMP19: case R_ARM_THM_JUMP24: if (Config->Pic) - return make>(S); - return make>(S); + return make(S); + return make(S); } fatal("unrecognized relocation type"); } -template static Thunk *addThunkMips(SymbolBody &S) { - return make>(S); +static Thunk *addThunkMips(SymbolBody &S) { + return make(S); } -template Thunk *addThunk(uint32_t RelocType, SymbolBody &S) { +Thunk *addThunk(uint32_t RelocType, SymbolBody &S) { if (Config->EMachine == EM_ARM) - return addThunkArm(RelocType, S); + return addThunkArm(RelocType, S); else if (Config->EMachine == EM_MIPS) - return addThunkMips(S); + return addThunkMips(S); llvm_unreachable("add Thunk only supported for ARM and Mips"); return nullptr; } -template Thunk *addThunk(uint32_t, SymbolBody &); -template Thunk *addThunk(uint32_t, SymbolBody &); -template Thunk *addThunk(uint32_t, SymbolBody &); -template Thunk *addThunk(uint32_t, SymbolBody &); } // end namespace elf } // end namespace lld Modified: vendor/lld/dist/ELF/Thunks.h ============================================================================== --- vendor/lld/dist/ELF/Thunks.h Wed May 17 20:23:11 2017 (r318421) +++ vendor/lld/dist/ELF/Thunks.h Wed May 17 20:23:13 2017 (r318422) @@ -51,7 +51,7 @@ public: // For a Relocation to symbol S create a Thunk to be added to a synthetic // ThunkSection. At present there are implementations for ARM and Mips Thunks. -template Thunk *addThunk(uint32_t RelocType, SymbolBody &S); +Thunk *addThunk(uint32_t RelocType, SymbolBody &S); } // namespace elf } // namespace lld Modified: vendor/lld/dist/ELF/Writer.cpp ============================================================================== --- vendor/lld/dist/ELF/Writer.cpp Wed May 17 20:23:11 2017 (r318421) +++ vendor/lld/dist/ELF/Writer.cpp Wed May 17 20:23:13 2017 (r318422) @@ -1223,7 +1223,7 @@ template void Writer: // we need to assign addresses so that we can tell if jump instructions // are out of range. This will need to turn into a loop that converges // when no more Thunks are added - ThunkCreator TC; + ThunkCreator TC; if (TC.createThunks(OutputSections)) applySynthetic({InX::MipsGot}, [](SyntheticSection *SS) { SS->updateAllocSize(); });