Index: lld/trunk/ELF/SyntheticSections.h =================================================================== --- lld/trunk/ELF/SyntheticSections.h +++ lld/trunk/ELF/SyntheticSections.h @@ -464,7 +464,7 @@ size_t Size = 0; }; -template class HashTableSection final : public SyntheticSection { +class HashTableSection final : public SyntheticSection { public: HashTableSection(); void finalizeContents() override; @@ -804,6 +804,7 @@ static StringTableSection *DynStrTab; static SymbolTableBaseSection *DynSymTab; static GnuHashTableSection *GnuHashTab; + static HashTableSection *HashTab; static InputSection *Interp; static GdbIndexSection *GdbIndex; static GotSection *Got; @@ -821,7 +822,6 @@ template struct In : public InX { static EhFrameHeader *EhFrameHdr; static EhFrameSection *EhFrame; - static HashTableSection *HashTab; static RelocationSection *RelaDyn; static RelocationSection *RelaPlt; static RelocationSection *RelaIplt; @@ -832,7 +832,6 @@ template EhFrameHeader *In::EhFrameHdr; template EhFrameSection *In::EhFrame; -template HashTableSection *In::HashTab; template RelocationSection *In::RelaDyn; template RelocationSection *In::RelaPlt; template RelocationSection *In::RelaIplt; Index: lld/trunk/ELF/SyntheticSections.cpp =================================================================== --- lld/trunk/ELF/SyntheticSections.cpp +++ lld/trunk/ELF/SyntheticSections.cpp @@ -1119,8 +1119,8 @@ add({DT_TEXTREL, (uint64_t)0}); if (InX::GnuHashTab) add({DT_GNU_HASH, InX::GnuHashTab}); - if (In::HashTab) - add({DT_HASH, In::HashTab}); + if (InX::HashTab) + add({DT_HASH, InX::HashTab}); if (Out::PreinitArray) { add({DT_PREINIT_ARRAY, Out::PreinitArray}); @@ -1612,13 +1612,12 @@ V.push_back({Ent.Body, Ent.StrTabOffset}); } -template -HashTableSection::HashTableSection() +HashTableSection::HashTableSection() : SyntheticSection(SHF_ALLOC, SHT_HASH, 4, ".hash") { this->Entsize = 4; } -template void HashTableSection::finalizeContents() { +void HashTableSection::finalizeContents() { getParent()->Link = InX::DynSymTab->getParent()->SectionIndex; unsigned NumEntries = 2; // nbucket and nchain. @@ -1631,18 +1630,15 @@ this->Size = NumEntries * 4; } -template void HashTableSection::writeTo(uint8_t *Buf) { - // A 32-bit integer type in the target endianness. - typedef typename ELFT::Word Elf_Word; - +void HashTableSection::writeTo(uint8_t *Buf) { unsigned NumSymbols = InX::DynSymTab->getNumSymbols(); - auto *P = reinterpret_cast(Buf); - *P++ = NumSymbols; // nbucket - *P++ = NumSymbols; // nchain + uint32_t *P = reinterpret_cast(Buf); + write32(P++, NumSymbols, Config->Endianness); // nbucket + write32(P++, NumSymbols, Config->Endianness); // nchain - Elf_Word *Buckets = P; - Elf_Word *Chains = P + NumSymbols; + uint32_t *Buckets = P; + uint32_t *Chains = P + NumSymbols; for (const SymbolTableEntry &S : InX::DynSymTab->getSymbols()) { SymbolBody *Body = S.Symbol; @@ -1650,7 +1646,7 @@ unsigned I = Body->DynsymIndex; uint32_t Hash = hashSysV(Name) % NumSymbols; Chains[I] = Buckets[Hash]; - Buckets[Hash] = I; + write32(Buckets + Hash, I, Config->Endianness); } } @@ -2362,6 +2358,7 @@ GotSection *InX::Got; GotPltSection *InX::GotPlt; GnuHashTableSection *InX::GnuHashTab; +HashTableSection *InX::HashTab; IgotPltSection *InX::IgotPlt; MipsGotSection *InX::MipsGot; MipsRldMapSection *InX::MipsRldMap; @@ -2416,11 +2413,6 @@ template class elf::SymbolTableSection; template class elf::SymbolTableSection; -template class elf::HashTableSection; -template class elf::HashTableSection; -template class elf::HashTableSection; -template class elf::HashTableSection; - template class elf::EhFrameHeader; template class elf::EhFrameHeader; template class elf::EhFrameHeader; Index: lld/trunk/ELF/Writer.cpp =================================================================== --- lld/trunk/ELF/Writer.cpp +++ lld/trunk/ELF/Writer.cpp @@ -333,8 +333,8 @@ } if (Config->SysvHash) { - In::HashTab = make>(); - Add(In::HashTab); + InX::HashTab = make(); + Add(InX::HashTab); } Add(InX::Dynamic); @@ -1353,7 +1353,7 @@ // symbol table section (DynSymTab) must be the first one. applySynthetic({InX::DynSymTab, InX::Bss, InX::BssRelRo, InX::GnuHashTab, - In::HashTab, InX::SymTab, + InX::HashTab, InX::SymTab, InX::ShStrTab, InX::StrTab, In::VerDef, InX::DynStrTab, InX::Got, InX::MipsGot,