Skip to content

Commit 4964800

Browse files
author
George Rimar
committedMar 15, 2017
[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
1 parent 22e3e7d commit 4964800

File tree

3 files changed

+18
-27
lines changed

3 files changed

+18
-27
lines changed
 

‎lld/ELF/SyntheticSections.cpp

+5-13
Original file line numberDiff line numberDiff line change
@@ -987,9 +987,8 @@ void IgotPltSection::writeTo(uint8_t *Buf) {
987987
}
988988
}
989989

990-
template <class ELFT>
991-
StringTableSection<ELFT>::StringTableSection(StringRef Name, bool Dynamic)
992-
: SyntheticSection(Dynamic ? (uintX_t)SHF_ALLOC : 0, SHT_STRTAB, 1, Name),
990+
StringTableSection::StringTableSection(StringRef Name, bool Dynamic)
991+
: SyntheticSection(Dynamic ? (uint64_t)SHF_ALLOC : 0, SHT_STRTAB, 1, Name),
993992
Dynamic(Dynamic) {
994993
// ELF string tables start with a NUL byte.
995994
addString("");
@@ -999,8 +998,7 @@ StringTableSection<ELFT>::StringTableSection(StringRef Name, bool Dynamic)
999998
// duplicates. It is optional because the name of global symbols are already
1000999
// uniqued and hashing them again has a big cost for a small value: uniquing
10011000
// them with some other string that happens to be the same.
1002-
template <class ELFT>
1003-
unsigned StringTableSection<ELFT>::addString(StringRef S, bool HashIt) {
1001+
unsigned StringTableSection::addString(StringRef S, bool HashIt) {
10041002
if (HashIt) {
10051003
auto R = StringMap.insert(std::make_pair(S, this->Size));
10061004
if (!R.second)
@@ -1012,7 +1010,7 @@ unsigned StringTableSection<ELFT>::addString(StringRef S, bool HashIt) {
10121010
return Ret;
10131011
}
10141012

1015-
template <class ELFT> void StringTableSection<ELFT>::writeTo(uint8_t *Buf) {
1013+
void StringTableSection::writeTo(uint8_t *Buf) {
10161014
for (StringRef S : Strings) {
10171015
memcpy(Buf, S.data(), S.size());
10181016
Buf += S.size() + 1;
@@ -1281,8 +1279,7 @@ template <class ELFT> void RelocationSection<ELFT>::finalizeContents() {
12811279
}
12821280

12831281
template <class ELFT>
1284-
SymbolTableSection<ELFT>::SymbolTableSection(
1285-
StringTableSection<ELFT> &StrTabSec)
1282+
SymbolTableSection<ELFT>::SymbolTableSection(StringTableSection &StrTabSec)
12861283
: SyntheticSection(StrTabSec.isDynamic() ? (uintX_t)SHF_ALLOC : 0,
12871284
StrTabSec.isDynamic() ? SHT_DYNSYM : SHT_SYMTAB,
12881285
sizeof(uintX_t),
@@ -2320,11 +2317,6 @@ template class elf::MipsGotSection<ELF32BE>;
23202317
template class elf::MipsGotSection<ELF64LE>;
23212318
template class elf::MipsGotSection<ELF64BE>;
23222319

2323-
template class elf::StringTableSection<ELF32LE>;
2324-
template class elf::StringTableSection<ELF32BE>;
2325-
template class elf::StringTableSection<ELF64LE>;
2326-
template class elf::StringTableSection<ELF64BE>;
2327-
23282320
template class elf::DynamicSection<ELF32LE>;
23292321
template class elf::DynamicSection<ELF32BE>;
23302322
template class elf::DynamicSection<ELF64LE>;

‎lld/ELF/SyntheticSections.h

+10-11
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,8 @@ class IgotPltSection final : public SyntheticSection {
296296
std::vector<const SymbolBody *> Entries;
297297
};
298298

299-
template <class ELFT> class StringTableSection final : public SyntheticSection {
299+
class StringTableSection final : public SyntheticSection {
300300
public:
301-
typedef typename ELFT::uint uintX_t;
302301
StringTableSection(StringRef Name, bool Dynamic);
303302
unsigned addString(StringRef S, bool HashIt = true);
304303
void writeTo(uint8_t *Buf) override;
@@ -308,7 +307,7 @@ template <class ELFT> class StringTableSection final : public SyntheticSection {
308307
private:
309308
const bool Dynamic;
310309

311-
uintX_t Size = 0;
310+
uint64_t Size = 0;
312311

313312
llvm::DenseMap<StringRef, unsigned> StringMap;
314313
std::vector<StringRef> Strings;
@@ -415,7 +414,7 @@ template <class ELFT> class SymbolTableSection final : public SyntheticSection {
415414
typedef typename ELFT::Sym Elf_Sym;
416415
typedef typename ELFT::uint uintX_t;
417416

418-
SymbolTableSection(StringTableSection<ELFT> &StrTabSec);
417+
SymbolTableSection(StringTableSection &StrTabSec);
419418

420419
void finalizeContents() override;
421420
void postThunkContents() override;
@@ -430,7 +429,7 @@ template <class ELFT> class SymbolTableSection final : public SyntheticSection {
430429
// A vector of symbols and their string table offsets.
431430
std::vector<SymbolTableEntry> Symbols;
432431

433-
StringTableSection<ELFT> &StrTabSec;
432+
StringTableSection &StrTabSec;
434433
};
435434

436435
// Outputs GNU Hash section. For detailed explanation see:
@@ -766,7 +765,7 @@ template <class ELFT> struct In {
766765
static BssSection *BssRelRo;
767766
static InputSection *Common;
768767
static DynamicSection<ELFT> *Dynamic;
769-
static StringTableSection<ELFT> *DynStrTab;
768+
static StringTableSection *DynStrTab;
770769
static SymbolTableSection<ELFT> *DynSymTab;
771770
static EhFrameHeader<ELFT> *EhFrameHdr;
772771
static GnuHashTableSection<ELFT> *GnuHashTab;
@@ -784,8 +783,8 @@ template <class ELFT> struct In {
784783
static RelocationSection<ELFT> *RelaDyn;
785784
static RelocationSection<ELFT> *RelaPlt;
786785
static RelocationSection<ELFT> *RelaIplt;
787-
static StringTableSection<ELFT> *ShStrTab;
788-
static StringTableSection<ELFT> *StrTab;
786+
static StringTableSection *ShStrTab;
787+
static StringTableSection *StrTab;
789788
static SymbolTableSection<ELFT> *SymTab;
790789
static VersionDefinitionSection<ELFT> *VerDef;
791790
static VersionTableSection<ELFT> *VerSym;
@@ -798,7 +797,7 @@ template <class ELFT> BssSection *In<ELFT>::BssRelRo;
798797
template <class ELFT> BuildIdSection<ELFT> *In<ELFT>::BuildId;
799798
template <class ELFT> InputSection *In<ELFT>::Common;
800799
template <class ELFT> DynamicSection<ELFT> *In<ELFT>::Dynamic;
801-
template <class ELFT> StringTableSection<ELFT> *In<ELFT>::DynStrTab;
800+
template <class ELFT> StringTableSection *In<ELFT>::DynStrTab;
802801
template <class ELFT> SymbolTableSection<ELFT> *In<ELFT>::DynSymTab;
803802
template <class ELFT> EhFrameHeader<ELFT> *In<ELFT>::EhFrameHdr;
804803
template <class ELFT> GdbIndexSection<ELFT> *In<ELFT>::GdbIndex;
@@ -816,8 +815,8 @@ template <class ELFT> PltSection<ELFT> *In<ELFT>::Iplt;
816815
template <class ELFT> RelocationSection<ELFT> *In<ELFT>::RelaDyn;
817816
template <class ELFT> RelocationSection<ELFT> *In<ELFT>::RelaPlt;
818817
template <class ELFT> RelocationSection<ELFT> *In<ELFT>::RelaIplt;
819-
template <class ELFT> StringTableSection<ELFT> *In<ELFT>::ShStrTab;
820-
template <class ELFT> StringTableSection<ELFT> *In<ELFT>::StrTab;
818+
template <class ELFT> StringTableSection *In<ELFT>::ShStrTab;
819+
template <class ELFT> StringTableSection *In<ELFT>::StrTab;
821820
template <class ELFT> SymbolTableSection<ELFT> *In<ELFT>::SymTab;
822821
template <class ELFT> VersionDefinitionSection<ELFT> *In<ELFT>::VerDef;
823822
template <class ELFT> VersionTableSection<ELFT> *In<ELFT>::VerSym;

‎lld/ELF/Writer.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,11 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
330330

331331
auto Add = [](InputSectionBase *Sec) { InputSections.push_back(Sec); };
332332

333-
In<ELFT>::DynStrTab = make<StringTableSection<ELFT>>(".dynstr", true);
333+
In<ELFT>::DynStrTab = make<StringTableSection>(".dynstr", true);
334334
In<ELFT>::Dynamic = make<DynamicSection<ELFT>>();
335335
In<ELFT>::RelaDyn = make<RelocationSection<ELFT>>(
336336
Config->isRela() ? ".rela.dyn" : ".rel.dyn", Config->ZCombreloc);
337-
In<ELFT>::ShStrTab = make<StringTableSection<ELFT>>(".shstrtab", false);
337+
In<ELFT>::ShStrTab = make<StringTableSection>(".shstrtab", false);
338338

339339
Out::ElfHeader = make<OutputSection>("", 0, SHF_ALLOC);
340340
Out::ElfHeader->Size = sizeof(Elf_Ehdr);
@@ -352,7 +352,7 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
352352
Add(createCommentSection<ELFT>());
353353

354354
if (Config->Strip != StripPolicy::All) {
355-
In<ELFT>::StrTab = make<StringTableSection<ELFT>>(".strtab", false);
355+
In<ELFT>::StrTab = make<StringTableSection>(".strtab", false);
356356
In<ELFT>::SymTab = make<SymbolTableSection<ELFT>>(*In<ELFT>::StrTab);
357357
}
358358

0 commit comments

Comments
 (0)