forked from OSchip/llvm-project
[ELF] - Detemplate of HashTableSection<ELFT>
Detemplation of one more synthetic section. Differential revision: https://reviews.llvm.org/D38241 llvm-svn: 314283
This commit is contained in:
parent
5d6efd100b
commit
aaf5471429
|
@ -1119,8 +1119,8 @@ template <class ELFT> void DynamicSection<ELFT>::finalizeContents() {
|
|||
add({DT_TEXTREL, (uint64_t)0});
|
||||
if (InX::GnuHashTab)
|
||||
add({DT_GNU_HASH, InX::GnuHashTab});
|
||||
if (In<ELFT>::HashTab)
|
||||
add({DT_HASH, In<ELFT>::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<SymbolTableEntry> &V) {
|
|||
V.push_back({Ent.Body, Ent.StrTabOffset});
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
HashTableSection<ELFT>::HashTableSection()
|
||||
HashTableSection::HashTableSection()
|
||||
: SyntheticSection(SHF_ALLOC, SHT_HASH, 4, ".hash") {
|
||||
this->Entsize = 4;
|
||||
}
|
||||
|
||||
template <class ELFT> void HashTableSection<ELFT>::finalizeContents() {
|
||||
void HashTableSection::finalizeContents() {
|
||||
getParent()->Link = InX::DynSymTab->getParent()->SectionIndex;
|
||||
|
||||
unsigned NumEntries = 2; // nbucket and nchain.
|
||||
|
@ -1631,18 +1630,15 @@ template <class ELFT> void HashTableSection<ELFT>::finalizeContents() {
|
|||
this->Size = NumEntries * 4;
|
||||
}
|
||||
|
||||
template <class ELFT> void HashTableSection<ELFT>::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<Elf_Word *>(Buf);
|
||||
*P++ = NumSymbols; // nbucket
|
||||
*P++ = NumSymbols; // nchain
|
||||
uint32_t *P = reinterpret_cast<uint32_t *>(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 <class ELFT> void HashTableSection<ELFT>::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<ELF32BE>;
|
|||
template class elf::SymbolTableSection<ELF64LE>;
|
||||
template class elf::SymbolTableSection<ELF64BE>;
|
||||
|
||||
template class elf::HashTableSection<ELF32LE>;
|
||||
template class elf::HashTableSection<ELF32BE>;
|
||||
template class elf::HashTableSection<ELF64LE>;
|
||||
template class elf::HashTableSection<ELF64BE>;
|
||||
|
||||
template class elf::EhFrameHeader<ELF32LE>;
|
||||
template class elf::EhFrameHeader<ELF32BE>;
|
||||
template class elf::EhFrameHeader<ELF64LE>;
|
||||
|
|
|
@ -464,7 +464,7 @@ private:
|
|||
size_t Size = 0;
|
||||
};
|
||||
|
||||
template <class ELFT> 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 <class ELFT> struct In : public InX {
|
||||
static EhFrameHeader<ELFT> *EhFrameHdr;
|
||||
static EhFrameSection<ELFT> *EhFrame;
|
||||
static HashTableSection<ELFT> *HashTab;
|
||||
static RelocationSection<ELFT> *RelaDyn;
|
||||
static RelocationSection<ELFT> *RelaPlt;
|
||||
static RelocationSection<ELFT> *RelaIplt;
|
||||
|
@ -832,7 +832,6 @@ template <class ELFT> struct In : public InX {
|
|||
|
||||
template <class ELFT> EhFrameHeader<ELFT> *In<ELFT>::EhFrameHdr;
|
||||
template <class ELFT> EhFrameSection<ELFT> *In<ELFT>::EhFrame;
|
||||
template <class ELFT> HashTableSection<ELFT> *In<ELFT>::HashTab;
|
||||
template <class ELFT> RelocationSection<ELFT> *In<ELFT>::RelaDyn;
|
||||
template <class ELFT> RelocationSection<ELFT> *In<ELFT>::RelaPlt;
|
||||
template <class ELFT> RelocationSection<ELFT> *In<ELFT>::RelaIplt;
|
||||
|
|
|
@ -333,8 +333,8 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
|
|||
}
|
||||
|
||||
if (Config->SysvHash) {
|
||||
In<ELFT>::HashTab = make<HashTableSection<ELFT>>();
|
||||
Add(In<ELFT>::HashTab);
|
||||
InX::HashTab = make<HashTableSection>();
|
||||
Add(InX::HashTab);
|
||||
}
|
||||
|
||||
Add(InX::Dynamic);
|
||||
|
@ -1353,7 +1353,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
|
|||
// symbol table section (DynSymTab) must be the first one.
|
||||
applySynthetic({InX::DynSymTab, InX::Bss,
|
||||
InX::BssRelRo, InX::GnuHashTab,
|
||||
In<ELFT>::HashTab, InX::SymTab,
|
||||
InX::HashTab, InX::SymTab,
|
||||
InX::ShStrTab, InX::StrTab,
|
||||
In<ELFT>::VerDef, InX::DynStrTab,
|
||||
InX::Got, InX::MipsGot,
|
||||
|
|
Loading…
Reference in New Issue