From aaf54714296a93334bd95d4b609a5176a8308f3b Mon Sep 17 00:00:00 2001 From: George Rimar Date: Wed, 27 Sep 2017 09:14:59 +0000 Subject: [PATCH] [ELF] - Detemplate of HashTableSection Detemplation of one more synthetic section. Differential revision: https://reviews.llvm.org/D38241 llvm-svn: 314283 --- lld/ELF/SyntheticSections.cpp | 32 ++++++++++++-------------------- lld/ELF/SyntheticSections.h | 5 ++--- lld/ELF/Writer.cpp | 6 +++--- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index f633e87..ec3b9b7 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -1119,8 +1119,8 @@ template void DynamicSection::finalizeContents() { 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 @@ void GnuHashTableSection::addSymbols(std::vector &V) { 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 @@ template void HashTableSection::finalizeContents() { 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 @@ template void HashTableSection::writeTo(uint8_t *Buf) { 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 @@ GdbIndexSection *InX::GdbIndex; 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::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; diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index c494dc3..b807408 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -464,7 +464,7 @@ private: size_t Size = 0; }; -template class HashTableSection final : public SyntheticSection { +class HashTableSection final : public SyntheticSection { public: HashTableSection(); void finalizeContents() override; @@ -804,6 +804,7 @@ struct InX { 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 @@ struct InX { 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 struct In : public InX { template EhFrameHeader *In::EhFrameHdr; template EhFrameSection *In::EhFrame; -template HashTableSection *In::HashTab; template RelocationSection *In::RelaDyn; template RelocationSection *In::RelaPlt; template RelocationSection *In::RelaIplt; diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 0e27bc9..4442f44 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -333,8 +333,8 @@ template void Writer::createSyntheticSections() { } if (Config->SysvHash) { - In::HashTab = make>(); - Add(In::HashTab); + InX::HashTab = make(); + Add(InX::HashTab); } Add(InX::Dynamic); @@ -1353,7 +1353,7 @@ template void Writer::finalizeSections() { // 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, -- 2.7.4