Reduce template usage. NFC.

llvm-svn: 302832
This commit is contained in:
Rafael Espindola 2017-05-11 22:02:41 +00:00
parent fd484c443f
commit 895aea6d15
5 changed files with 77 additions and 78 deletions

View File

@ -383,9 +383,9 @@ elf::ObjectFile<ELFT>::createInputSection(const Elf_Shdr &Sec,
// we see. The eglibc ARM dynamic loaders require the presence of an
// attribute section for dlopen to work.
// In a full implementation we would merge all attribute sections.
if (In<ELFT>::ARMAttributes == nullptr) {
In<ELFT>::ARMAttributes = make<InputSection>(this, &Sec, Name);
return In<ELFT>::ARMAttributes;
if (InX::ARMAttributes == nullptr) {
InX::ARMAttributes = make<InputSection>(this, &Sec, Name);
return InX::ARMAttributes;
}
return &InputSection::Discarded;
case SHT_RELA:

View File

@ -518,7 +518,7 @@ template <class ELFT> static void addCopyRelSymbol(SharedSymbol *SS) {
// See if this symbol is in a read-only segment. If so, preserve the symbol's
// memory protection by reserving space in the .bss.rel.ro section.
bool IsReadOnly = isReadOnly<ELFT>(SS);
BssSection *Sec = IsReadOnly ? In<ELFT>::BssRelRo : In<ELFT>::Bss;
BssSection *Sec = IsReadOnly ? InX::BssRelRo : InX::Bss;
uint64_t Off = Sec->reserveSpace(SymSize, SS->getAlignment<ELFT>());
// Look through the DSO's dynamic symbol table for aliases and create a
@ -874,7 +874,7 @@ static void scanRelocs(InputSectionBase &Sec, ArrayRef<RelTy> Rels) {
// If a relocation needs PLT, we create PLT and GOTPLT slots for the symbol.
if (needsPlt(Expr) && !Body.isInPlt()) {
if (Body.isGnuIFunc() && !Preemptible)
addPltEntry(InX::Iplt, In<ELFT>::IgotPlt, In<ELFT>::RelaIplt,
addPltEntry(InX::Iplt, InX::IgotPlt, In<ELFT>::RelaIplt,
Target->IRelativeRel, Body, true);
else
addPltEntry(InX::Plt, InX::GotPlt, In<ELFT>::RelaPlt, Target->PltRel,

View File

@ -1028,15 +1028,15 @@ template <class ELFT> void DynamicSection<ELFT>::addEntries() {
// Add strings to .dynstr early so that .dynstr's size will be
// fixed early.
for (StringRef S : Config->AuxiliaryList)
add({DT_AUXILIARY, In<ELFT>::DynStrTab->addString(S)});
add({DT_AUXILIARY, InX::DynStrTab->addString(S)});
if (!Config->Rpath.empty())
add({Config->EnableNewDtags ? DT_RUNPATH : DT_RPATH,
In<ELFT>::DynStrTab->addString(Config->Rpath)});
InX::DynStrTab->addString(Config->Rpath)});
for (SharedFile<ELFT> *F : Symtab<ELFT>::X->getSharedFiles())
if (F->isNeeded())
add({DT_NEEDED, In<ELFT>::DynStrTab->addString(F->SoName)});
add({DT_NEEDED, InX::DynStrTab->addString(F->SoName)});
if (!Config->SoName.empty())
add({DT_SONAME, In<ELFT>::DynStrTab->addString(Config->SoName)});
add({DT_SONAME, InX::DynStrTab->addString(Config->SoName)});
if (!Config->Shared && !Config->Relocatable)
add({DT_DEBUG, (uint64_t)0});
@ -1072,7 +1072,7 @@ template <class ELFT> void DynamicSection<ELFT>::finalizeContents() {
if (DtFlags1)
add({DT_FLAGS_1, DtFlags1});
this->Link = In<ELFT>::DynStrTab->OutSec->SectionIndex;
this->Link = InX::DynStrTab->OutSec->SectionIndex;
if (In<ELFT>::RelaDyn->OutSec->Size > 0) {
bool IsRela = Config->IsRela;
add({IsRela ? DT_RELA : DT_REL, In<ELFT>::RelaDyn});
@ -1099,8 +1099,8 @@ template <class ELFT> void DynamicSection<ELFT>::finalizeContents() {
add({DT_SYMTAB, In<ELFT>::DynSymTab});
add({DT_SYMENT, sizeof(Elf_Sym)});
add({DT_STRTAB, In<ELFT>::DynStrTab});
add({DT_STRSZ, In<ELFT>::DynStrTab->getSize()});
add({DT_STRTAB, InX::DynStrTab});
add({DT_STRSZ, InX::DynStrTab->getSize()});
if (!Config->ZText)
add({DT_TEXTREL, (uint64_t)0});
if (In<ELFT>::GnuHashTab)
@ -1149,8 +1149,8 @@ template <class ELFT> void DynamicSection<ELFT>::finalizeContents() {
else
add({DT_MIPS_GOTSYM, In<ELFT>::DynSymTab->getNumSymbols()});
add({DT_PLTGOT, InX::MipsGot});
if (In<ELFT>::MipsRldMap)
add({DT_MIPS_RLD_MAP, In<ELFT>::MipsRldMap});
if (InX::MipsRldMap)
add({DT_MIPS_RLD_MAP, InX::MipsRldMap});
}
this->OutSec->Link = this->Link;
@ -1951,11 +1951,11 @@ static StringRef getFileDefName() {
}
template <class ELFT> void VersionDefinitionSection<ELFT>::finalizeContents() {
FileDefNameOff = In<ELFT>::DynStrTab->addString(getFileDefName());
FileDefNameOff = InX::DynStrTab->addString(getFileDefName());
for (VersionDefinition &V : Config->VersionDefinitions)
V.NameOff = In<ELFT>::DynStrTab->addString(V.Name);
V.NameOff = InX::DynStrTab->addString(V.Name);
this->OutSec->Link = In<ELFT>::DynStrTab->OutSec->SectionIndex;
this->OutSec->Link = InX::DynStrTab->OutSec->SectionIndex;
// sh_info should be set to the number of definitions. This fact is missed in
// documentation, but confirmed by binutils community:
@ -2051,14 +2051,14 @@ void VersionNeedSection<ELFT>::addSymbol(SharedSymbol *SS) {
// to create one by adding it to our needed list and creating a dynstr entry
// for the soname.
if (File->VerdefMap.empty())
Needed.push_back({File, In<ELFT>::DynStrTab->addString(File->SoName)});
Needed.push_back({File, InX::DynStrTab->addString(File->SoName)});
typename SharedFile<ELFT>::NeededVer &NV = File->VerdefMap[Ver];
// If we don't already know that we need an Elf_Vernaux for this Elf_Verdef,
// prepare to create one by allocating a version identifier and creating a
// dynstr entry for the version name.
if (NV.Index == 0) {
NV.StrTab = In<ELFT>::DynStrTab->addString(File->getStringTable().data() +
Ver->getAux()->vda_name);
NV.StrTab = InX::DynStrTab->addString(File->getStringTable().data() +
Ver->getAux()->vda_name);
NV.Index = NextIndex++;
}
SS->symbol()->VersionId = NV.Index;
@ -2100,7 +2100,7 @@ template <class ELFT> void VersionNeedSection<ELFT>::writeTo(uint8_t *Buf) {
}
template <class ELFT> void VersionNeedSection<ELFT>::finalizeContents() {
this->OutSec->Link = In<ELFT>::DynStrTab->OutSec->SectionIndex;
this->OutSec->Link = InX::DynStrTab->OutSec->SectionIndex;
this->OutSec->Info = Needed.size();
}

View File

@ -461,7 +461,7 @@ void X86TargetInfo::writePltHeader(uint8_t *Buf) const {
memcpy(Buf, V, sizeof(V));
uint32_t Ebx = In<ELF32LE>::Got->getVA() + In<ELF32LE>::Got->getSize();
uint32_t GotPlt = In<ELF32LE>::GotPlt->getVA() - Ebx;
uint32_t GotPlt = InX::GotPlt->getVA() - Ebx;
write32le(Buf + 2, GotPlt + 4);
write32le(Buf + 8, GotPlt + 8);
return;
@ -473,7 +473,7 @@ void X86TargetInfo::writePltHeader(uint8_t *Buf) const {
0x90, 0x90, 0x90, 0x90 // nop
};
memcpy(Buf, PltData, sizeof(PltData));
uint32_t GotPlt = In<ELF32LE>::GotPlt->getVA();
uint32_t GotPlt = InX::GotPlt->getVA();
write32le(Buf + 2, GotPlt + 4);
write32le(Buf + 8, GotPlt + 8);
}
@ -737,7 +737,7 @@ void X86_64TargetInfo<ELFT>::writePltHeader(uint8_t *Buf) const {
};
memcpy(Buf, PltData, sizeof(PltData));
uint64_t GotPlt = InX::GotPlt->getVA();
uint64_t Plt = In<ELFT>::Plt->getVA();
uint64_t Plt = InX::Plt->getVA();
write32le(Buf + 2, GotPlt - Plt + 2); // GOTPLT+8
write32le(Buf + 8, GotPlt - Plt + 4); // GOTPLT+16
}
@ -1369,7 +1369,7 @@ bool AArch64TargetInfo::isPicRel(uint32_t Type) const {
}
void AArch64TargetInfo::writeGotPlt(uint8_t *Buf, const SymbolBody &) const {
write64le(Buf, In<ELF64LE>::Plt->getVA());
write64le(Buf, InX::Plt->getVA());
}
// Page(Expr) is the page address of the expression Expr, defined
@ -1392,8 +1392,8 @@ void AArch64TargetInfo::writePltHeader(uint8_t *Buf) const {
};
memcpy(Buf, PltData, sizeof(PltData));
uint64_t Got = In<ELF64LE>::GotPlt->getVA();
uint64_t Plt = In<ELF64LE>::Plt->getVA();
uint64_t Got = InX::GotPlt->getVA();
uint64_t Plt = InX::Plt->getVA();
relocateOne(Buf + 4, R_AARCH64_ADR_PREL_PG_HI21,
getAArch64Page(Got + 16) - getAArch64Page(Plt + 4));
relocateOne(Buf + 8, R_AARCH64_LDST64_ABS_LO12_NC, Got + 16);
@ -1746,7 +1746,7 @@ uint32_t ARMTargetInfo::getDynRel(uint32_t Type) const {
}
void ARMTargetInfo::writeGotPlt(uint8_t *Buf, const SymbolBody &) const {
write32le(Buf, In<ELF32LE>::Plt->getVA());
write32le(Buf, InX::Plt->getVA());
}
void ARMTargetInfo::writeIgotPlt(uint8_t *Buf, const SymbolBody &S) const {
@ -1763,8 +1763,8 @@ void ARMTargetInfo::writePltHeader(uint8_t *Buf) const {
0x00, 0x00, 0x00, 0x00, // L2: .word &(.got.plt) - L1 - 8
};
memcpy(Buf, PltData, sizeof(PltData));
uint64_t GotPlt = In<ELF32LE>::GotPlt->getVA();
uint64_t L1 = In<ELF32LE>::Plt->getVA() + 8;
uint64_t GotPlt = InX::GotPlt->getVA();
uint64_t L1 = InX::Plt->getVA() + 8;
write32le(Buf + 16, GotPlt - L1 - 8);
}
@ -2134,7 +2134,7 @@ uint32_t MipsTargetInfo<ELFT>::getDynRel(uint32_t Type) const {
template <class ELFT>
void MipsTargetInfo<ELFT>::writeGotPlt(uint8_t *Buf, const SymbolBody &) const {
write32<ELFT::TargetEndianness>(Buf, In<ELFT>::Plt->getVA());
write32<ELFT::TargetEndianness>(Buf, InX::Plt->getVA());
}
template <endianness E, uint8_t BSIZE, uint8_t SHIFT>

View File

@ -312,11 +312,11 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
auto Add = [](InputSectionBase *Sec) { InputSections.push_back(Sec); };
In<ELFT>::DynStrTab = make<StringTableSection>(".dynstr", true);
InX::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>(".shstrtab", false);
InX::ShStrTab = make<StringTableSection>(".shstrtab", false);
Out::ElfHeader = make<OutputSection>("", 0, SHF_ALLOC);
Out::ElfHeader->Size = sizeof(Elf_Ehdr);
@ -324,41 +324,41 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
Out::ProgramHeaders->updateAlignment(Config->Wordsize);
if (needsInterpSection<ELFT>()) {
In<ELFT>::Interp = createInterpSection();
Add(In<ELFT>::Interp);
InX::Interp = createInterpSection();
Add(InX::Interp);
} else {
In<ELFT>::Interp = nullptr;
InX::Interp = nullptr;
}
if (!Config->Relocatable)
Add(createCommentSection<ELFT>());
if (Config->Strip != StripPolicy::All) {
In<ELFT>::StrTab = make<StringTableSection>(".strtab", false);
In<ELFT>::SymTab = make<SymbolTableSection<ELFT>>(*In<ELFT>::StrTab);
InX::StrTab = make<StringTableSection>(".strtab", false);
In<ELFT>::SymTab = make<SymbolTableSection<ELFT>>(*InX::StrTab);
}
if (Config->BuildId != BuildIdKind::None) {
In<ELFT>::BuildId = make<BuildIdSection>();
Add(In<ELFT>::BuildId);
InX::BuildId = make<BuildIdSection>();
Add(InX::BuildId);
}
In<ELFT>::Common = createCommonSection<ELFT>();
if (In<ELFT>::Common)
InX::Common = createCommonSection<ELFT>();
if (InX::Common)
Add(InX::Common);
In<ELFT>::Bss = make<BssSection>(".bss");
Add(In<ELFT>::Bss);
In<ELFT>::BssRelRo = make<BssSection>(".bss.rel.ro");
Add(In<ELFT>::BssRelRo);
InX::Bss = make<BssSection>(".bss");
Add(InX::Bss);
InX::BssRelRo = make<BssSection>(".bss.rel.ro");
Add(InX::BssRelRo);
// Add MIPS-specific sections.
bool HasDynSymTab = !Symtab<ELFT>::X->getSharedFiles().empty() ||
Config->Pic || Config->ExportDynamic;
if (Config->EMachine == EM_MIPS) {
if (!Config->Shared && HasDynSymTab) {
In<ELFT>::MipsRldMap = make<MipsRldMapSection>();
Add(In<ELFT>::MipsRldMap);
InX::MipsRldMap = make<MipsRldMapSection>();
Add(InX::MipsRldMap);
}
if (auto *Sec = MipsAbiFlagsSection<ELFT>::create())
Add(Sec);
@ -369,7 +369,7 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
}
if (HasDynSymTab) {
In<ELFT>::DynSymTab = make<SymbolTableSection<ELFT>>(*In<ELFT>::DynStrTab);
In<ELFT>::DynSymTab = make<SymbolTableSection<ELFT>>(*InX::DynStrTab);
Add(In<ELFT>::DynSymTab);
In<ELFT>::VerSym = make<VersionTableSection<ELFT>>();
@ -394,7 +394,7 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
}
Add(In<ELFT>::Dynamic);
Add(In<ELFT>::DynStrTab);
Add(InX::DynStrTab);
Add(In<ELFT>::RelaDyn);
}
@ -410,12 +410,12 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
InX::GotPlt = make<GotPltSection>();
Add(InX::GotPlt);
In<ELFT>::IgotPlt = make<IgotPltSection>();
Add(In<ELFT>::IgotPlt);
InX::IgotPlt = make<IgotPltSection>();
Add(InX::IgotPlt);
if (Config->GdbIndex) {
In<ELFT>::GdbIndex = make<GdbIndexSection>();
Add(In<ELFT>::GdbIndex);
InX::GdbIndex = make<GdbIndexSection>();
Add(InX::GdbIndex);
}
// We always need to add rel[a].plt to output if it has entries.
@ -431,10 +431,10 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
false /*Sort*/);
Add(In<ELFT>::RelaIplt);
In<ELFT>::Plt = make<PltSection>(Target->PltHeaderSize);
Add(In<ELFT>::Plt);
In<ELFT>::Iplt = make<PltSection>(0);
Add(In<ELFT>::Iplt);
InX::Plt = make<PltSection>(Target->PltHeaderSize);
Add(InX::Plt);
InX::Iplt = make<PltSection>(0);
Add(InX::Iplt);
if (!Config->Relocatable) {
if (Config->EhFrameHdr) {
@ -447,9 +447,9 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
if (In<ELFT>::SymTab)
Add(In<ELFT>::SymTab);
Add(In<ELFT>::ShStrTab);
if (In<ELFT>::StrTab)
Add(In<ELFT>::StrTab);
Add(InX::ShStrTab);
if (InX::StrTab)
Add(InX::StrTab);
}
static bool shouldKeepInSymtab(SectionBase *Sec, StringRef SymName,
@ -633,7 +633,7 @@ template <class ELFT> bool elf::isRelroSection(const OutputSection *Sec) {
// Since the dynamic linker needs to process copy relocations, the
// section cannot be read-only, but once initialized, they shouldn't
// change.
if (Sec == In<ELFT>::BssRelRo->OutSec)
if (Sec == InX::BssRelRo->OutSec)
return true;
// Sections with some special names are put into RELRO. This is a
@ -1125,10 +1125,10 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
// we can correctly decide if a dynamic relocation is needed.
forEachRelSec(scanRelocations<ELFT>);
if (In<ELFT>::Plt && !In<ELFT>::Plt->empty())
In<ELFT>::Plt->addSymbols();
if (In<ELFT>::Iplt && !In<ELFT>::Iplt->empty())
In<ELFT>::Iplt->addSymbols();
if (InX::Plt && !InX::Plt->empty())
InX::Plt->addSymbols();
if (InX::Iplt && !InX::Iplt->empty())
InX::Iplt->addSymbols();
// Now that we have defined all possible global symbols including linker-
// synthesized ones. Visit all symbols to give the finishing touches.
@ -1167,7 +1167,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
unsigned I = 1;
for (OutputSection *Sec : OutputSections) {
Sec->SectionIndex = I++;
Sec->ShName = In<ELFT>::ShStrTab->addString(Sec->Name);
Sec->ShName = InX::ShStrTab->addString(Sec->Name);
}
// Binary and relocatable output does not have PHDRS.
@ -1181,15 +1181,14 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
// Dynamic section must be the last one in this list and dynamic
// symbol table section (DynSymTab) must be the first one.
applySynthetic({In<ELFT>::DynSymTab, In<ELFT>::Bss, In<ELFT>::BssRelRo,
applySynthetic({In<ELFT>::DynSymTab, InX::Bss, InX::BssRelRo,
In<ELFT>::GnuHashTab, In<ELFT>::HashTab, In<ELFT>::SymTab,
In<ELFT>::ShStrTab, In<ELFT>::StrTab, In<ELFT>::VerDef,
In<ELFT>::DynStrTab, In<ELFT>::GdbIndex, In<ELFT>::Got,
InX::MipsGot, In<ELFT>::IgotPlt, InX::GotPlt,
InX::ShStrTab, InX::StrTab, In<ELFT>::VerDef,
InX::DynStrTab, InX::GdbIndex, In<ELFT>::Got,
InX::MipsGot, InX::IgotPlt, InX::GotPlt,
In<ELFT>::RelaDyn, In<ELFT>::RelaIplt, In<ELFT>::RelaPlt,
In<ELFT>::Plt, In<ELFT>::Iplt, In<ELFT>::Plt,
In<ELFT>::EhFrameHdr, In<ELFT>::VerSym, In<ELFT>::VerNeed,
In<ELFT>::Dynamic},
InX::Plt, InX::Iplt, In<ELFT>::EhFrameHdr,
In<ELFT>::VerSym, In<ELFT>::VerNeed, In<ELFT>::Dynamic},
[](SyntheticSection *SS) { SS->finalizeContents(); });
// Some architectures use small displacements for jump instructions.
@ -1220,7 +1219,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
[](OutputSection *S) { S->maybeCompress<ELFT>(); });
// createThunks may have added local symbols to the static symbol table
applySynthetic({In<ELFT>::SymTab, In<ELFT>::ShStrTab, In<ELFT>::StrTab},
applySynthetic({In<ELFT>::SymTab, InX::ShStrTab, InX::StrTab},
[](SyntheticSection *SS) { SS->postThunkContents(); });
}
@ -1655,7 +1654,7 @@ template <class ELFT> void Writer<ELFT>::writeHeader() {
EHdr->e_phnum = Phdrs.size();
EHdr->e_shentsize = sizeof(Elf_Shdr);
EHdr->e_shnum = OutputSections.size() + 1;
EHdr->e_shstrndx = In<ELFT>::ShStrTab->OutSec->SectionIndex;
EHdr->e_shstrndx = InX::ShStrTab->OutSec->SectionIndex;
if (Config->EMachine == EM_ARM)
// We don't currently use any features incompatible with EF_ARM_EABI_VER5,
@ -1749,13 +1748,13 @@ template <class ELFT> void Writer<ELFT>::writeSections() {
}
template <class ELFT> void Writer<ELFT>::writeBuildId() {
if (!In<ELFT>::BuildId || !In<ELFT>::BuildId->OutSec)
if (!InX::BuildId || !InX::BuildId->OutSec)
return;
// Compute a hash of all sections of the output file.
uint8_t *Start = Buffer->getBufferStart();
uint8_t *End = Start + FileSize;
In<ELFT>::BuildId->writeBuildId({Start, End});
InX::BuildId->writeBuildId({Start, End});
}
template void elf::writeResult<ELF32LE>();