Index: ELF/Config.h =================================================================== --- ELF/Config.h +++ ELF/Config.h @@ -162,6 +162,9 @@ unsigned Optimize; unsigned ThinLTOJobs; + // Returns true if target is 64 bit. + bool is64() const { return EKind == ELF64LEKind || EKind == ELF64BEKind; } + // The ELF spec defines two types of relocation table entries, RELA and // REL. RELA is a triplet of (offset, info, addend) while REL is a // tuple of (offset, info). Addends for REL are implicit and read from @@ -177,9 +180,8 @@ // As far as we know, all 64-bit ABIs are using RELA. A few 32-bit ABIs // are using RELA too. bool isRela() const { - bool is64 = (EKind == ELF64LEKind || EKind == ELF64BEKind); bool isX32Abi = (EKind == ELF32LEKind && EMachine == llvm::ELF::EM_X86_64); - return is64 || isX32Abi || MipsN32Abi; + return is64() || isX32Abi || MipsN32Abi; } // Returns true if we need to pass through relocations in input Index: ELF/SyntheticSections.h =================================================================== --- ELF/SyntheticSections.h +++ ELF/SyntheticSections.h @@ -265,9 +265,7 @@ uintX_t Size = 0; }; -template class GotPltSection final : public SyntheticSection { - typedef typename ELFT::uint uintX_t; - +class GotPltSection final : public SyntheticSection { public: GotPltSection(); void addEntry(SymbolBody &Sym); @@ -283,9 +281,7 @@ // Symbols that will be relocated by Target->IRelativeRel. // On most Targets the IgotPltSection will immediately follow the GotPltSection // on ARM the IgotPltSection will immediately follow the GotSection. -template class IgotPltSection final : public SyntheticSection { - typedef typename ELFT::uint uintX_t; - +class IgotPltSection final : public SyntheticSection { public: IgotPltSection(); void addEntry(SymbolBody &Sym); @@ -773,8 +769,8 @@ static GotSection *Got; static EhFrameSection *EhFrame; static MipsGotSection *MipsGot; - static GotPltSection *GotPlt; - static IgotPltSection *IgotPlt; + static GotPltSection *GotPlt; + static IgotPltSection *IgotPlt; static HashTableSection *HashTab; static InputSection *Interp; static MipsRldMapSection *MipsRldMap; @@ -803,8 +799,8 @@ template GotSection *In::Got; template EhFrameSection *In::EhFrame; template MipsGotSection *In::MipsGot; -template GotPltSection *In::GotPlt; -template IgotPltSection *In::IgotPlt; +template GotPltSection *In::GotPlt; +template IgotPltSection *In::IgotPlt; template HashTableSection *In::HashTab; template InputSection *In::Interp; template MipsRldMapSection *In::MipsRldMap; Index: ELF/SyntheticSections.cpp =================================================================== --- ELF/SyntheticSections.cpp +++ ELF/SyntheticSections.cpp @@ -937,52 +937,50 @@ } } -template -GotPltSection::GotPltSection() +GotPltSection::GotPltSection() : SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS, Target->GotPltEntrySize, ".got.plt") {} -template void GotPltSection::addEntry(SymbolBody &Sym) { +void GotPltSection::addEntry(SymbolBody &Sym) { Sym.GotPltIndex = Target->GotPltHeaderEntriesNum + Entries.size(); Entries.push_back(&Sym); } -template size_t GotPltSection::getSize() const { +size_t GotPltSection::getSize() const { return (Target->GotPltHeaderEntriesNum + Entries.size()) * Target->GotPltEntrySize; } -template void GotPltSection::writeTo(uint8_t *Buf) { +void GotPltSection::writeTo(uint8_t *Buf) { Target->writeGotPltHeader(Buf); Buf += Target->GotPltHeaderEntriesNum * Target->GotPltEntrySize; for (const SymbolBody *B : Entries) { Target->writeGotPlt(Buf, *B); - Buf += sizeof(uintX_t); + Buf += Config->is64() ? 8 : 4; } } // On ARM the IgotPltSection is part of the GotSection, on other Targets it is // part of the .got.plt -template -IgotPltSection::IgotPltSection() +IgotPltSection::IgotPltSection() : SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS, Target->GotPltEntrySize, Config->EMachine == EM_ARM ? ".got" : ".got.plt") {} -template void IgotPltSection::addEntry(SymbolBody &Sym) { +void IgotPltSection::addEntry(SymbolBody &Sym) { Sym.IsInIgot = true; Sym.GotPltIndex = Entries.size(); Entries.push_back(&Sym); } -template size_t IgotPltSection::getSize() const { +size_t IgotPltSection::getSize() const { return Entries.size() * Target->GotPltEntrySize; } -template void IgotPltSection::writeTo(uint8_t *Buf) { +void IgotPltSection::writeTo(uint8_t *Buf) { for (const SymbolBody *B : Entries) { Target->writeIgotPlt(Buf, *B); - Buf += sizeof(uintX_t); + Buf += Config->is64() ? 8 : 4; } } @@ -2324,16 +2322,6 @@ template class elf::MipsGotSection; template class elf::MipsGotSection; -template class elf::GotPltSection; -template class elf::GotPltSection; -template class elf::GotPltSection; -template class elf::GotPltSection; - -template class elf::IgotPltSection; -template class elf::IgotPltSection; -template class elf::IgotPltSection; -template class elf::IgotPltSection; - template class elf::StringTableSection; template class elf::StringTableSection; template class elf::StringTableSection; Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -427,9 +427,9 @@ Add(In::Got); } - In::GotPlt = make>(); + In::GotPlt = make(); Add(In::GotPlt); - In::IgotPlt = make>(); + In::IgotPlt = make(); Add(In::IgotPlt); if (Config->GdbIndex) {