[lld] r303153 - [ELF] - Detemplate access to SymTab, DynSymTab, GnuHashTab. NFC.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Tue May 16 03:04:42 PDT 2017
Author: grimar
Date: Tue May 16 05:04:42 2017
New Revision: 303153
URL: http://llvm.org/viewvc/llvm-project?rev=303153&view=rev
Log:
[ELF] - Detemplate access to SymTab, DynSymTab, GnuHashTab. NFC.
Follow up for r303150.
Modified:
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/OutputSections.cpp
lld/trunk/ELF/SyntheticSections.cpp
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=303153&r1=303152&r2=303153&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Tue May 16 05:04:42 2017
@@ -324,7 +324,7 @@ void InputSection::copyRelocations(uint8
// section, but for --emit-relocs it is an virtual address.
P->r_offset = RelocatedSection->OutSec->Addr +
RelocatedSection->getOffset(Rel.r_offset);
- P->setSymbolAndType(In<ELFT>::SymTab->getSymbolIndex(&Body), Type,
+ P->setSymbolAndType(InX::SymTab->getSymbolIndex(&Body), Type,
Config->IsMips64EL);
if (Body.Type == STT_SECTION) {
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=303153&r1=303152&r2=303153&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Tue May 16 05:04:42 2017
@@ -133,7 +133,7 @@ template <class ELFT> void OutputSection
if (isa<SyntheticSection>(First))
return;
- this->Link = In<ELFT>::SymTab->OutSec->SectionIndex;
+ this->Link = InX::SymTab->OutSec->SectionIndex;
// sh_info for SHT_REL[A] sections should contain the section header index of
// the section to which the relocation applies.
InputSectionBase *S = First->getRelocatedSection();
Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=303153&r1=303152&r2=303153&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Tue May 16 05:04:42 2017
@@ -298,8 +298,8 @@ SymbolBody *elf::addSyntheticLocal(Strin
uint64_t Size, InputSectionBase *Section) {
auto *S = make<DefinedRegular>(Name, /*IsLocal*/ true, STV_DEFAULT, Type,
Value, Size, Section, nullptr);
- if (In<ELFT>::SymTab)
- In<ELFT>::SymTab->addSymbol(S);
+ if (InX::SymTab)
+ InX::SymTab->addSymbol(S);
return S;
}
@@ -1092,14 +1092,14 @@ template <class ELFT> void DynamicSectio
add({DT_PLTREL, uint64_t(Config->IsRela ? DT_RELA : DT_REL)});
}
- add({DT_SYMTAB, In<ELFT>::DynSymTab});
+ add({DT_SYMTAB, InX::DynSymTab});
add({DT_SYMENT, sizeof(Elf_Sym)});
add({DT_STRTAB, InX::DynStrTab});
add({DT_STRSZ, InX::DynStrTab->getSize()});
if (!Config->ZText)
add({DT_TEXTREL, (uint64_t)0});
- if (In<ELFT>::GnuHashTab)
- add({DT_GNU_HASH, In<ELFT>::GnuHashTab});
+ if (InX::GnuHashTab)
+ add({DT_GNU_HASH, InX::GnuHashTab});
if (In<ELFT>::HashTab)
add({DT_HASH, In<ELFT>::HashTab});
@@ -1137,12 +1137,12 @@ template <class ELFT> void DynamicSectio
add({DT_MIPS_RLD_VERSION, 1});
add({DT_MIPS_FLAGS, RHF_NOTPOT});
add({DT_MIPS_BASE_ADDRESS, Config->ImageBase});
- add({DT_MIPS_SYMTABNO, In<ELFT>::DynSymTab->getNumSymbols()});
+ add({DT_MIPS_SYMTABNO, InX::DynSymTab->getNumSymbols()});
add({DT_MIPS_LOCAL_GOTNO, InX::MipsGot->getLocalEntriesNum()});
if (const SymbolBody *B = InX::MipsGot->getFirstGlobalEntry())
add({DT_MIPS_GOTSYM, B->DynsymIndex});
else
- add({DT_MIPS_GOTSYM, In<ELFT>::DynSymTab->getNumSymbols()});
+ add({DT_MIPS_GOTSYM, InX::DynSymTab->getNumSymbols()});
add({DT_PLTGOT, InX::MipsGot});
if (InX::MipsRldMap)
add({DT_MIPS_RLD_MAP, InX::MipsRldMap});
@@ -1254,8 +1254,8 @@ template <class ELFT> unsigned Relocatio
}
template <class ELFT> void RelocationSection<ELFT>::finalizeContents() {
- this->Link = In<ELFT>::DynSymTab ? In<ELFT>::DynSymTab->OutSec->SectionIndex
- : In<ELFT>::SymTab->OutSec->SectionIndex;
+ this->Link = InX::DynSymTab ? InX::DynSymTab->OutSec->SectionIndex
+ : InX::SymTab->OutSec->SectionIndex;
// Set required output section properties.
this->OutSec->Link = this->Link;
@@ -1586,15 +1586,15 @@ HashTableSection<ELFT>::HashTableSection
}
template <class ELFT> void HashTableSection<ELFT>::finalizeContents() {
- this->OutSec->Link = In<ELFT>::DynSymTab->OutSec->SectionIndex;
+ this->OutSec->Link = InX::DynSymTab->OutSec->SectionIndex;
unsigned NumEntries = 2; // nbucket and nchain.
- NumEntries += In<ELFT>::DynSymTab->getNumSymbols(); // The chain entries.
+ NumEntries += InX::DynSymTab->getNumSymbols(); // The chain entries.
// Create as many buckets as there are symbols.
// FIXME: This is simplistic. We can try to optimize it, but implementing
// support for SHT_GNU_HASH is probably even more profitable.
- NumEntries += In<ELFT>::DynSymTab->getNumSymbols();
+ NumEntries += InX::DynSymTab->getNumSymbols();
this->Size = NumEntries * 4;
}
@@ -1602,7 +1602,7 @@ template <class ELFT> void HashTableSect
// A 32-bit integer type in the target endianness.
typedef typename ELFT::Word Elf_Word;
- unsigned NumSymbols = In<ELFT>::DynSymTab->getNumSymbols();
+ unsigned NumSymbols = InX::DynSymTab->getNumSymbols();
auto *P = reinterpret_cast<Elf_Word *>(Buf);
*P++ = NumSymbols; // nbucket
@@ -1611,7 +1611,7 @@ template <class ELFT> void HashTableSect
Elf_Word *Buckets = P;
Elf_Word *Chains = P + NumSymbols;
- for (const SymbolTableEntry &S : In<ELFT>::DynSymTab->getSymbols()) {
+ for (const SymbolTableEntry &S : InX::DynSymTab->getSymbols()) {
SymbolBody *Body = S.Symbol;
StringRef Name = Body->getName();
unsigned I = Body->DynsymIndex;
@@ -2001,16 +2001,16 @@ VersionTableSection<ELFT>::VersionTableS
template <class ELFT> void VersionTableSection<ELFT>::finalizeContents() {
// At the moment of june 2016 GNU docs does not mention that sh_link field
// should be set, but Sun docs do. Also readelf relies on this field.
- this->OutSec->Link = In<ELFT>::DynSymTab->OutSec->SectionIndex;
+ this->OutSec->Link = InX::DynSymTab->OutSec->SectionIndex;
}
template <class ELFT> size_t VersionTableSection<ELFT>::getSize() const {
- return sizeof(Elf_Versym) * (In<ELFT>::DynSymTab->getSymbols().size() + 1);
+ return sizeof(Elf_Versym) * (InX::DynSymTab->getSymbols().size() + 1);
}
template <class ELFT> void VersionTableSection<ELFT>::writeTo(uint8_t *Buf) {
auto *OutVersym = reinterpret_cast<Elf_Versym *>(Buf) + 1;
- for (const SymbolTableEntry &S : In<ELFT>::DynSymTab->getSymbols()) {
+ for (const SymbolTableEntry &S : InX::DynSymTab->getSymbols()) {
OutVersym->vs_index = S.Symbol->symbol()->VersionId;
++OutVersym;
}
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=303153&r1=303152&r2=303153&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue May 16 05:04:42 2017
@@ -368,8 +368,8 @@ template <class ELFT> void Writer<ELFT>:
}
if (HasDynSymTab) {
- In<ELFT>::DynSymTab = make<SymbolTableSection<ELFT>>(*InX::DynStrTab);
- Add(In<ELFT>::DynSymTab);
+ InX::DynSymTab = make<SymbolTableSection<ELFT>>(*InX::DynStrTab);
+ Add(InX::DynSymTab);
In<ELFT>::VerSym = make<VersionTableSection<ELFT>>();
Add(In<ELFT>::VerSym);
@@ -383,8 +383,8 @@ template <class ELFT> void Writer<ELFT>:
Add(In<ELFT>::VerNeed);
if (Config->GnuHash) {
- In<ELFT>::GnuHashTab = make<GnuHashTableSection>();
- Add(In<ELFT>::GnuHashTab);
+ InX::GnuHashTab = make<GnuHashTableSection>();
+ Add(InX::GnuHashTab);
}
if (Config->SysvHash) {
@@ -444,8 +444,8 @@ template <class ELFT> void Writer<ELFT>:
Add(In<ELFT>::EhFrame);
}
- if (In<ELFT>::SymTab)
- Add(In<ELFT>::SymTab);
+ if (InX::SymTab)
+ Add(InX::SymTab);
Add(InX::ShStrTab);
if (InX::StrTab)
Add(InX::StrTab);
@@ -503,7 +503,7 @@ static bool includeInSymtab(const Symbol
// Local symbols are not in the linker's symbol table. This function scans
// each object file's symbol table to copy local symbols to the output.
template <class ELFT> void Writer<ELFT>::copyLocalSymbols() {
- if (!In<ELFT>::SymTab)
+ if (!InX::SymTab)
return;
for (elf::ObjectFile<ELFT> *F : Symtab<ELFT>::X->getObjectFiles()) {
for (SymbolBody *B : F->getLocalSymbols()) {
@@ -521,7 +521,7 @@ template <class ELFT> void Writer<ELFT>:
SectionBase *Sec = DR->Section;
if (!shouldKeepInSymtab(Sec, B->getName(), *B))
continue;
- In<ELFT>::SymTab->addSymbol(B);
+ InX::SymTab->addSymbol(B);
}
}
}
@@ -541,7 +541,7 @@ template <class ELFT> void Writer<ELFT>:
auto *Sym =
make<DefinedRegular>("", /*IsLocal=*/true, /*StOther=*/0, STT_SECTION,
/*Value=*/0, /*Size=*/0, IS, nullptr);
- In<ELFT>::SymTab->addSymbol(Sym);
+ InX::SymTab->addSymbol(Sym);
}
}
@@ -819,7 +819,7 @@ addOptionalRegular(StringRef Name, Secti
// need these symbols, since IRELATIVE relocs are resolved through GOT
// and PLT. For details, see http://www.airs.com/blog/archives/403.
template <class ELFT> void Writer<ELFT>::addRelIpltSymbols() {
- if (In<ELFT>::DynSymTab)
+ if (InX::DynSymTab)
return;
StringRef S = Config->IsRela ? "__rela_iplt_start" : "__rel_iplt_start";
addOptionalRegular<ELFT>(S, In<ELFT>::RelaIplt, 0, STV_HIDDEN, STB_WEAK);
@@ -872,7 +872,7 @@ template <class ELFT> void Writer<ELFT>:
// static linking the linker is required to optimize away any references to
// __tls_get_addr, so it's not defined anywhere. Create a hidden definition
// to avoid the undefined symbol error.
- if (!In<ELFT>::DynSymTab)
+ if (!InX::DynSymTab)
Symtab<ELFT>::X->addIgnored("__tls_get_addr");
// __ehdr_start is the location of ELF file headers. Note that we define
@@ -1131,7 +1131,7 @@ template <class ELFT> void Writer<ELFT>:
// It should be okay as no one seems to care about the type.
// Even the author of gold doesn't remember why gold behaves that way.
// https://sourceware.org/ml/binutils/2002-03/msg00360.html
- if (In<ELFT>::DynSymTab)
+ if (InX::DynSymTab)
addRegular<ELFT>("_DYNAMIC", InX::Dynamic, 0);
// Define __rel[a]_iplt_{start,end} symbols if needed.
@@ -1159,11 +1159,11 @@ template <class ELFT> void Writer<ELFT>:
if (!includeInSymtab(*Body))
continue;
- if (In<ELFT>::SymTab)
- In<ELFT>::SymTab->addSymbol(Body);
+ if (InX::SymTab)
+ InX::SymTab->addSymbol(Body);
- if (In<ELFT>::DynSymTab && S->includeInDynsym()) {
- In<ELFT>::DynSymTab->addSymbol(Body);
+ if (InX::DynSymTab && S->includeInDynsym()) {
+ InX::DynSymTab->addSymbol(Body);
if (auto *SS = dyn_cast<SharedSymbol>(Body))
if (cast<SharedFile<ELFT>>(SS->File)->isNeeded())
In<ELFT>::VerNeed->addSymbol(SS);
@@ -1203,30 +1203,14 @@ template <class ELFT> void Writer<ELFT>:
// 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,
- InX::Bss,
- InX::BssRelRo,
- In<ELFT>::GnuHashTab,
- In<ELFT>::HashTab,
- In<ELFT>::SymTab,
- InX::ShStrTab,
- InX::StrTab,
- In<ELFT>::VerDef,
- InX::DynStrTab,
- InX::GdbIndex,
- InX::Got,
- InX::MipsGot,
- InX::IgotPlt,
- InX::GotPlt,
- In<ELFT>::RelaDyn,
- In<ELFT>::RelaIplt,
- In<ELFT>::RelaPlt,
- InX::Plt,
- InX::Iplt,
- In<ELFT>::EhFrameHdr,
- In<ELFT>::VerSym,
- In<ELFT>::VerNeed,
- InX::Dynamic},
+ applySynthetic({InX::DynSymTab, InX::Bss, InX::BssRelRo,
+ InX::GnuHashTab, In<ELFT>::HashTab, InX::SymTab,
+ InX::ShStrTab, InX::StrTab, In<ELFT>::VerDef,
+ InX::DynStrTab, InX::GdbIndex, InX::Got,
+ InX::MipsGot, InX::IgotPlt, InX::GotPlt,
+ In<ELFT>::RelaDyn, In<ELFT>::RelaIplt, In<ELFT>::RelaPlt,
+ InX::Plt, InX::Iplt, In<ELFT>::EhFrameHdr,
+ In<ELFT>::VerSym, In<ELFT>::VerNeed, InX::Dynamic},
[](SyntheticSection *SS) { SS->finalizeContents(); });
// Some architectures use small displacements for jump instructions.
@@ -1257,7 +1241,7 @@ template <class ELFT> void Writer<ELFT>:
[](OutputSection *S) { S->maybeCompress<ELFT>(); });
// createThunks may have added local symbols to the static symbol table
- applySynthetic({In<ELFT>::SymTab, InX::ShStrTab, InX::StrTab},
+ applySynthetic({InX::SymTab, InX::ShStrTab, InX::StrTab},
[](SyntheticSection *SS) { SS->postThunkContents(); });
}
@@ -1392,7 +1376,7 @@ template <class ELFT> std::vector<PhdrEn
Ret.push_back(std::move(TlsHdr));
// Add an entry for .dynamic.
- if (In<ELFT>::DynSymTab)
+ if (InX::DynSymTab)
AddHdr(PT_DYNAMIC, InX::Dynamic->OutSec->getPhdrFlags())
->add(InX::Dynamic->OutSec);
More information about the llvm-commits
mailing list