mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-19 13:26:45 +00:00
[ELF] - Detemplate StringTableSection.
StringTableSection was <ELFT> templated previously, It disallow to de-template code that uses it, for example LinkerScript<ELFT>::discard uses it as: if (S == In<ELFT>::ShStrTab) error("discarding .shstrtab section is not allowed"); It seems we can try to detemplate some of synthetic sections and somehow make them available for non-templated calls. (move out of In<ELFT> struct probably). Differential revision: https://reviews.llvm.org/D30933 llvm-svn: 297815
This commit is contained in:
parent
22e3e7d165
commit
49648004ed
@ -987,9 +987,8 @@ void IgotPltSection::writeTo(uint8_t *Buf) {
|
||||
}
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
StringTableSection<ELFT>::StringTableSection(StringRef Name, bool Dynamic)
|
||||
: SyntheticSection(Dynamic ? (uintX_t)SHF_ALLOC : 0, SHT_STRTAB, 1, Name),
|
||||
StringTableSection::StringTableSection(StringRef Name, bool Dynamic)
|
||||
: SyntheticSection(Dynamic ? (uint64_t)SHF_ALLOC : 0, SHT_STRTAB, 1, Name),
|
||||
Dynamic(Dynamic) {
|
||||
// ELF string tables start with a NUL byte.
|
||||
addString("");
|
||||
@ -999,8 +998,7 @@ StringTableSection<ELFT>::StringTableSection(StringRef Name, bool Dynamic)
|
||||
// duplicates. It is optional because the name of global symbols are already
|
||||
// uniqued and hashing them again has a big cost for a small value: uniquing
|
||||
// them with some other string that happens to be the same.
|
||||
template <class ELFT>
|
||||
unsigned StringTableSection<ELFT>::addString(StringRef S, bool HashIt) {
|
||||
unsigned StringTableSection::addString(StringRef S, bool HashIt) {
|
||||
if (HashIt) {
|
||||
auto R = StringMap.insert(std::make_pair(S, this->Size));
|
||||
if (!R.second)
|
||||
@ -1012,7 +1010,7 @@ unsigned StringTableSection<ELFT>::addString(StringRef S, bool HashIt) {
|
||||
return Ret;
|
||||
}
|
||||
|
||||
template <class ELFT> void StringTableSection<ELFT>::writeTo(uint8_t *Buf) {
|
||||
void StringTableSection::writeTo(uint8_t *Buf) {
|
||||
for (StringRef S : Strings) {
|
||||
memcpy(Buf, S.data(), S.size());
|
||||
Buf += S.size() + 1;
|
||||
@ -1281,8 +1279,7 @@ template <class ELFT> void RelocationSection<ELFT>::finalizeContents() {
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
SymbolTableSection<ELFT>::SymbolTableSection(
|
||||
StringTableSection<ELFT> &StrTabSec)
|
||||
SymbolTableSection<ELFT>::SymbolTableSection(StringTableSection &StrTabSec)
|
||||
: SyntheticSection(StrTabSec.isDynamic() ? (uintX_t)SHF_ALLOC : 0,
|
||||
StrTabSec.isDynamic() ? SHT_DYNSYM : SHT_SYMTAB,
|
||||
sizeof(uintX_t),
|
||||
@ -2320,11 +2317,6 @@ template class elf::MipsGotSection<ELF32BE>;
|
||||
template class elf::MipsGotSection<ELF64LE>;
|
||||
template class elf::MipsGotSection<ELF64BE>;
|
||||
|
||||
template class elf::StringTableSection<ELF32LE>;
|
||||
template class elf::StringTableSection<ELF32BE>;
|
||||
template class elf::StringTableSection<ELF64LE>;
|
||||
template class elf::StringTableSection<ELF64BE>;
|
||||
|
||||
template class elf::DynamicSection<ELF32LE>;
|
||||
template class elf::DynamicSection<ELF32BE>;
|
||||
template class elf::DynamicSection<ELF64LE>;
|
||||
|
@ -296,9 +296,8 @@ private:
|
||||
std::vector<const SymbolBody *> Entries;
|
||||
};
|
||||
|
||||
template <class ELFT> class StringTableSection final : public SyntheticSection {
|
||||
class StringTableSection final : public SyntheticSection {
|
||||
public:
|
||||
typedef typename ELFT::uint uintX_t;
|
||||
StringTableSection(StringRef Name, bool Dynamic);
|
||||
unsigned addString(StringRef S, bool HashIt = true);
|
||||
void writeTo(uint8_t *Buf) override;
|
||||
@ -308,7 +307,7 @@ public:
|
||||
private:
|
||||
const bool Dynamic;
|
||||
|
||||
uintX_t Size = 0;
|
||||
uint64_t Size = 0;
|
||||
|
||||
llvm::DenseMap<StringRef, unsigned> StringMap;
|
||||
std::vector<StringRef> Strings;
|
||||
@ -415,7 +414,7 @@ public:
|
||||
typedef typename ELFT::Sym Elf_Sym;
|
||||
typedef typename ELFT::uint uintX_t;
|
||||
|
||||
SymbolTableSection(StringTableSection<ELFT> &StrTabSec);
|
||||
SymbolTableSection(StringTableSection &StrTabSec);
|
||||
|
||||
void finalizeContents() override;
|
||||
void postThunkContents() override;
|
||||
@ -430,7 +429,7 @@ private:
|
||||
// A vector of symbols and their string table offsets.
|
||||
std::vector<SymbolTableEntry> Symbols;
|
||||
|
||||
StringTableSection<ELFT> &StrTabSec;
|
||||
StringTableSection &StrTabSec;
|
||||
};
|
||||
|
||||
// Outputs GNU Hash section. For detailed explanation see:
|
||||
@ -766,7 +765,7 @@ template <class ELFT> struct In {
|
||||
static BssSection *BssRelRo;
|
||||
static InputSection *Common;
|
||||
static DynamicSection<ELFT> *Dynamic;
|
||||
static StringTableSection<ELFT> *DynStrTab;
|
||||
static StringTableSection *DynStrTab;
|
||||
static SymbolTableSection<ELFT> *DynSymTab;
|
||||
static EhFrameHeader<ELFT> *EhFrameHdr;
|
||||
static GnuHashTableSection<ELFT> *GnuHashTab;
|
||||
@ -784,8 +783,8 @@ template <class ELFT> struct In {
|
||||
static RelocationSection<ELFT> *RelaDyn;
|
||||
static RelocationSection<ELFT> *RelaPlt;
|
||||
static RelocationSection<ELFT> *RelaIplt;
|
||||
static StringTableSection<ELFT> *ShStrTab;
|
||||
static StringTableSection<ELFT> *StrTab;
|
||||
static StringTableSection *ShStrTab;
|
||||
static StringTableSection *StrTab;
|
||||
static SymbolTableSection<ELFT> *SymTab;
|
||||
static VersionDefinitionSection<ELFT> *VerDef;
|
||||
static VersionTableSection<ELFT> *VerSym;
|
||||
@ -798,7 +797,7 @@ template <class ELFT> BssSection *In<ELFT>::BssRelRo;
|
||||
template <class ELFT> BuildIdSection<ELFT> *In<ELFT>::BuildId;
|
||||
template <class ELFT> InputSection *In<ELFT>::Common;
|
||||
template <class ELFT> DynamicSection<ELFT> *In<ELFT>::Dynamic;
|
||||
template <class ELFT> StringTableSection<ELFT> *In<ELFT>::DynStrTab;
|
||||
template <class ELFT> StringTableSection *In<ELFT>::DynStrTab;
|
||||
template <class ELFT> SymbolTableSection<ELFT> *In<ELFT>::DynSymTab;
|
||||
template <class ELFT> EhFrameHeader<ELFT> *In<ELFT>::EhFrameHdr;
|
||||
template <class ELFT> GdbIndexSection<ELFT> *In<ELFT>::GdbIndex;
|
||||
@ -816,8 +815,8 @@ template <class ELFT> PltSection<ELFT> *In<ELFT>::Iplt;
|
||||
template <class ELFT> RelocationSection<ELFT> *In<ELFT>::RelaDyn;
|
||||
template <class ELFT> RelocationSection<ELFT> *In<ELFT>::RelaPlt;
|
||||
template <class ELFT> RelocationSection<ELFT> *In<ELFT>::RelaIplt;
|
||||
template <class ELFT> StringTableSection<ELFT> *In<ELFT>::ShStrTab;
|
||||
template <class ELFT> StringTableSection<ELFT> *In<ELFT>::StrTab;
|
||||
template <class ELFT> StringTableSection *In<ELFT>::ShStrTab;
|
||||
template <class ELFT> StringTableSection *In<ELFT>::StrTab;
|
||||
template <class ELFT> SymbolTableSection<ELFT> *In<ELFT>::SymTab;
|
||||
template <class ELFT> VersionDefinitionSection<ELFT> *In<ELFT>::VerDef;
|
||||
template <class ELFT> VersionTableSection<ELFT> *In<ELFT>::VerSym;
|
||||
|
@ -330,11 +330,11 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
|
||||
|
||||
auto Add = [](InputSectionBase *Sec) { InputSections.push_back(Sec); };
|
||||
|
||||
In<ELFT>::DynStrTab = make<StringTableSection<ELFT>>(".dynstr", true);
|
||||
In<ELFT>::DynStrTab = make<StringTableSection>(".dynstr", true);
|
||||
In<ELFT>::Dynamic = make<DynamicSection<ELFT>>();
|
||||
In<ELFT>::RelaDyn = make<RelocationSection<ELFT>>(
|
||||
Config->isRela() ? ".rela.dyn" : ".rel.dyn", Config->ZCombreloc);
|
||||
In<ELFT>::ShStrTab = make<StringTableSection<ELFT>>(".shstrtab", false);
|
||||
In<ELFT>::ShStrTab = make<StringTableSection>(".shstrtab", false);
|
||||
|
||||
Out::ElfHeader = make<OutputSection>("", 0, SHF_ALLOC);
|
||||
Out::ElfHeader->Size = sizeof(Elf_Ehdr);
|
||||
@ -352,7 +352,7 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
|
||||
Add(createCommentSection<ELFT>());
|
||||
|
||||
if (Config->Strip != StripPolicy::All) {
|
||||
In<ELFT>::StrTab = make<StringTableSection<ELFT>>(".strtab", false);
|
||||
In<ELFT>::StrTab = make<StringTableSection>(".strtab", false);
|
||||
In<ELFT>::SymTab = make<SymbolTableSection<ELFT>>(*In<ELFT>::StrTab);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user