Index: ELF/Relocations.cpp =================================================================== --- ELF/Relocations.cpp +++ ELF/Relocations.cpp @@ -792,17 +792,18 @@ continue; if (Body.isGnuIFunc() && !Preemptible) { - In::Iplt->addEntry(Body); + Body.IsInIplt = true; In::IgotPlt->addEntry(Body); - In::RelaIplt->addReloc({Target->IRelativeRel, In::IgotPlt, - Body.getGotPltOffset(), !Preemptible, - &Body, 0}); + unsigned RelOff = In::RelaIplt->addReloc( + {Target->IRelativeRel, In::IgotPlt, Body.getGotPltOffset(), + !Preemptible, &Body, 0}); + In::Iplt->addEntry(Body, RelOff); } else { - In::Plt->addEntry(Body); In::GotPlt->addEntry(Body); - In::RelaPlt->addReloc({Target->PltRel, In::GotPlt, - Body.getGotPltOffset(), !Preemptible, - &Body, 0}); + unsigned RelOff = In::RelaPlt->addReloc( + {Target->PltRel, In::GotPlt, Body.getGotPltOffset(), + !Preemptible, &Body, 0}); + In::Plt->addEntry(Body, RelOff); } continue; } Index: ELF/SyntheticSections.h =================================================================== --- ELF/SyntheticSections.h +++ ELF/SyntheticSections.h @@ -384,7 +384,7 @@ public: RelocationSection(StringRef Name, bool Sort); - void addReloc(const DynamicReloc &Reloc); + unsigned addReloc(const DynamicReloc &Reloc); unsigned getRelocOffset(); void finalizeContents() override; void writeTo(uint8_t *Buf) override; @@ -475,12 +475,12 @@ // header as its first entry that is used at run-time to resolve lazy binding. // The latter is used for GNU Ifunc symbols, that will be subject to a // Target->IRelativeRel. -template class PltSection : public SyntheticSection { +class PltSection : public SyntheticSection { public: PltSection(size_t HeaderSize); void writeTo(uint8_t *Buf) override; size_t getSize() const override; - void addEntry(SymbolBody &Sym); + void addEntry(SymbolBody &Sym, unsigned RelOff); bool empty() const override { return Entries.empty(); } void addSymbols(); @@ -760,6 +760,8 @@ static GotPltSection *GotPlt; static IgotPltSection *IgotPlt; static MipsRldMapSection *MipsRldMap; + static PltSection *Plt; + static PltSection *Iplt; static StringTableSection *ShStrTab; static StringTableSection *StrTab; }; @@ -775,8 +777,6 @@ static EhFrameSection *EhFrame; static MipsGotSection *MipsGot; static HashTableSection *HashTab; - static PltSection *Plt; - static PltSection *Iplt; static RelocationSection *RelaDyn; static RelocationSection *RelaPlt; static RelocationSection *RelaIplt; @@ -796,8 +796,6 @@ template EhFrameSection *In::EhFrame; template MipsGotSection *In::MipsGot; template HashTableSection *In::HashTab; -template PltSection *In::Plt; -template PltSection *In::Iplt; template RelocationSection *In::RelaDyn; template RelocationSection *In::RelaPlt; template RelocationSection *In::RelaIplt; Index: ELF/SyntheticSections.cpp =================================================================== --- ELF/SyntheticSections.cpp +++ ELF/SyntheticSections.cpp @@ -1220,10 +1220,12 @@ } template -void RelocationSection::addReloc(const DynamicReloc &Reloc) { +unsigned RelocationSection::addReloc(const DynamicReloc &Reloc) { + unsigned Off = getRelocOffset(); if (Reloc.Type == Target->RelativeRel) ++NumRelativeRelocs; Relocs.push_back(Reloc); + return Off; } template @@ -1642,12 +1644,11 @@ } } -template -PltSection::PltSection(size_t S) +PltSection::PltSection(size_t S) : SyntheticSection(SHF_ALLOC | SHF_EXECINSTR, SHT_PROGBITS, 16, ".plt"), HeaderSize(S) {} -template void PltSection::writeTo(uint8_t *Buf) { +void PltSection::writeTo(uint8_t *Buf) { // At beginning of PLT but not the IPLT, we have code to call the dynamic // linker to resolve dynsyms at runtime. Write such code. if (HeaderSize != 0) @@ -1666,24 +1667,18 @@ } } -template void PltSection::addEntry(SymbolBody &Sym) { +void PltSection::addEntry(SymbolBody &Sym, unsigned RelOff) { Sym.PltIndex = Entries.size(); - RelocationSection *PltRelocSection = In::RelaPlt; - if (HeaderSize == 0) { - PltRelocSection = In::RelaIplt; - Sym.IsInIplt = true; - } - unsigned RelOff = PltRelocSection->getRelocOffset(); Entries.push_back(std::make_pair(&Sym, RelOff)); } -template size_t PltSection::getSize() const { +size_t PltSection::getSize() const { return HeaderSize + Entries.size() * Target->PltEntrySize; } // Some architectures such as additional symbols in the PLT section. For // example ARM uses mapping symbols to aid disassembly -template void PltSection::addSymbols() { +void PltSection::addSymbols() { // The PLT may have symbols defined for the Header, the IPLT has no header if (HeaderSize != 0) Target->addPltHeaderSymbols(this); @@ -1694,8 +1689,8 @@ } } -template unsigned PltSection::getPltRelocOff() const { - return (HeaderSize == 0) ? In::Plt->getSize() : 0; +unsigned PltSection::getPltRelocOff() const { + return (HeaderSize == 0) ? InX::Plt->getSize() : 0; } template @@ -2266,6 +2261,8 @@ GotPltSection *InX::GotPlt; IgotPltSection *InX::IgotPlt; MipsRldMapSection *InX::MipsRldMap; +PltSection *InX::Plt; +PltSection *InX::Iplt; StringTableSection *InX::ShStrTab; StringTableSection *InX::StrTab; @@ -2352,11 +2349,6 @@ template class elf::HashTableSection; template class elf::HashTableSection; -template class elf::PltSection; -template class elf::PltSection; -template class elf::PltSection; -template class elf::PltSection; - template class elf::GdbIndexSection; template class elf::GdbIndexSection; template class elf::GdbIndexSection; Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -449,9 +449,9 @@ false /*Sort*/); Add(In::RelaIplt); - In::Plt = make>(Target->PltHeaderSize); + In::Plt = make(Target->PltHeaderSize); Add(In::Plt); - In::Iplt = make>(0); + In::Iplt = make(0); Add(In::Iplt); if (!Config->Relocatable) {