[lld] r295993 - Make InputSection a class. NFC.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 23 08:49:08 PST 2017
Author: rafael
Date: Thu Feb 23 10:49:07 2017
New Revision: 295993
URL: http://llvm.org/viewvc/llvm-project?rev=295993&view=rev
Log:
Make InputSection a class. NFC.
With the current design an InputSection is basically anything that
goes directly in a OutputSection. That includes plain input section
but also synthetic sections, so this should probably not be a
template.
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/GdbIndex.cpp
lld/trunk/ELF/GdbIndex.h
lld/trunk/ELF/ICF.cpp
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/InputSection.h
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/LinkerScript.h
lld/trunk/ELF/MapFile.cpp
lld/trunk/ELF/MarkLive.cpp
lld/trunk/ELF/OutputSections.cpp
lld/trunk/ELF/OutputSections.h
lld/trunk/ELF/Relocations.cpp
lld/trunk/ELF/Relocations.h
lld/trunk/ELF/Symbols.cpp
lld/trunk/ELF/Symbols.h
lld/trunk/ELF/SyntheticSections.cpp
lld/trunk/ELF/SyntheticSections.h
lld/trunk/ELF/Target.cpp
lld/trunk/ELF/Thunks.cpp
lld/trunk/ELF/Thunks.h
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Thu Feb 23 10:49:07 2017
@@ -845,11 +845,11 @@ template <class ELFT> void LinkerDriver:
// Aggregate all input sections into one place.
for (elf::ObjectFile<ELFT> *F : Symtab.getObjectFiles())
for (InputSectionBase *S : F->getSections())
- if (S && S != &InputSection<ELFT>::Discarded)
+ if (S && S != &InputSection::Discarded)
Symtab.Sections.push_back(S);
for (BinaryFile *F : Symtab.getBinaryFiles())
for (InputSectionBase *S : F->getSections())
- Symtab.Sections.push_back(cast<InputSection<ELFT>>(S));
+ Symtab.Sections.push_back(cast<InputSection>(S));
// Do size optimizations: garbage collection and identical code folding.
if (Config->GcSections)
Modified: lld/trunk/ELF/GdbIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/GdbIndex.cpp?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/GdbIndex.cpp (original)
+++ lld/trunk/ELF/GdbIndex.cpp Thu Feb 23 10:49:07 2017
@@ -67,7 +67,7 @@ using namespace llvm::object;
using namespace lld::elf;
template <class ELFT>
-GdbIndexBuilder<ELFT>::GdbIndexBuilder(InputSection<ELFT> *DebugInfoSec)
+GdbIndexBuilder<ELFT>::GdbIndexBuilder(InputSection *DebugInfoSec)
: DebugInfoSec(DebugInfoSec) {
if (Expected<std::unique_ptr<object::ObjectFile>> Obj =
object::ObjectFile::createObjectFile(
@@ -155,7 +155,7 @@ template <class ELFT>
static InputSectionBase *findSection(ArrayRef<InputSectionBase *> Arr,
uint64_t Offset) {
for (InputSectionBase *S : Arr)
- if (S && S != &InputSection<ELFT>::Discarded)
+ if (S && S != &InputSection::Discarded)
if (Offset >= S->Offset && Offset < S->Offset + S->getSize<ELFT>())
return S;
return nullptr;
Modified: lld/trunk/ELF/GdbIndex.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/GdbIndex.h?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/GdbIndex.h (original)
+++ lld/trunk/ELF/GdbIndex.h Thu Feb 23 10:49:07 2017
@@ -17,7 +17,7 @@
namespace lld {
namespace elf {
-template <class ELFT> class InputSection;
+class InputSection;
// Struct represents single entry of address area of gdb index.
template <class ELFT> struct AddressEntry {
@@ -32,12 +32,12 @@ template <class ELFT> struct AddressEntr
template <class ELFT> class GdbIndexBuilder : public llvm::LoadedObjectInfo {
typedef typename ELFT::uint uintX_t;
- InputSection<ELFT> *DebugInfoSec;
+ InputSection *DebugInfoSec;
std::unique_ptr<llvm::DWARFContext> Dwarf;
public:
- GdbIndexBuilder(InputSection<ELFT> *DebugInfoSec);
+ GdbIndexBuilder(InputSection *DebugInfoSec);
// Extracts the compilation units. Each first element of pair is a offset of a
// CU in the .debug_info section and second is the length of that CU.
Modified: lld/trunk/ELF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ICF.cpp?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/ICF.cpp (original)
+++ lld/trunk/ELF/ICF.cpp Thu Feb 23 10:49:07 2017
@@ -102,11 +102,11 @@ private:
bool constantEq(ArrayRef<RelTy> RelsA, ArrayRef<RelTy> RelsB);
template <class RelTy>
- bool variableEq(const InputSection<ELFT> *A, ArrayRef<RelTy> RelsA,
- const InputSection<ELFT> *B, ArrayRef<RelTy> RelsB);
+ bool variableEq(const InputSection *A, ArrayRef<RelTy> RelsA,
+ const InputSection *B, ArrayRef<RelTy> RelsB);
- bool equalsConstant(const InputSection<ELFT> *A, const InputSection<ELFT> *B);
- bool equalsVariable(const InputSection<ELFT> *A, const InputSection<ELFT> *B);
+ bool equalsConstant(const InputSection *A, const InputSection *B);
+ bool equalsVariable(const InputSection *A, const InputSection *B);
size_t findBoundary(size_t Begin, size_t End);
@@ -115,7 +115,7 @@ private:
void forEachClass(std::function<void(size_t, size_t)> Fn);
- std::vector<InputSection<ELFT> *> Sections;
+ std::vector<InputSection *> Sections;
// We repeat the main loop while `Repeat` is true.
std::atomic<bool> Repeat;
@@ -154,12 +154,12 @@ private:
// Returns a hash value for S. Note that the information about
// relocation targets is not included in the hash value.
-template <class ELFT> static uint32_t getHash(InputSection<ELFT> *S) {
+template <class ELFT> static uint32_t getHash(InputSection *S) {
return hash_combine(S->Flags, S->template getSize<ELFT>(), S->NumRelocations);
}
// Returns true if section S is subject of ICF.
-template <class ELFT> static bool isEligible(InputSection<ELFT> *S) {
+template <class ELFT> static bool isEligible(InputSection *S) {
// .init and .fini contains instructions that must be executed to
// initialize and finalize the process. They cannot and should not
// be merged.
@@ -181,13 +181,13 @@ void ICF<ELFT>::segregate(size_t Begin,
while (Begin < End) {
// Divide [Begin, End) into two. Let Mid be the start index of the
// second group.
- auto Bound = std::stable_partition(
- Sections.begin() + Begin + 1, Sections.begin() + End,
- [&](InputSection<ELFT> *S) {
- if (Constant)
- return equalsConstant(Sections[Begin], S);
- return equalsVariable(Sections[Begin], S);
- });
+ auto Bound =
+ std::stable_partition(Sections.begin() + Begin + 1,
+ Sections.begin() + End, [&](InputSection *S) {
+ if (Constant)
+ return equalsConstant(Sections[Begin], S);
+ return equalsVariable(Sections[Begin], S);
+ });
size_t Mid = Bound - Sections.begin();
// Now we split [Begin, End) into [Begin, Mid) and [Mid, End) by
@@ -221,8 +221,7 @@ bool ICF<ELFT>::constantEq(ArrayRef<RelT
// Compare "non-moving" part of two InputSections, namely everything
// except relocation targets.
template <class ELFT>
-bool ICF<ELFT>::equalsConstant(const InputSection<ELFT> *A,
- const InputSection<ELFT> *B) {
+bool ICF<ELFT>::equalsConstant(const InputSection *A, const InputSection *B) {
if (A->NumRelocations != B->NumRelocations || A->Flags != B->Flags ||
A->template getSize<ELFT>() != B->template getSize<ELFT>() ||
A->Data != B->Data)
@@ -237,8 +236,8 @@ bool ICF<ELFT>::equalsConstant(const Inp
// relocations point to the same section in terms of ICF.
template <class ELFT>
template <class RelTy>
-bool ICF<ELFT>::variableEq(const InputSection<ELFT> *A, ArrayRef<RelTy> RelsA,
- const InputSection<ELFT> *B, ArrayRef<RelTy> RelsB) {
+bool ICF<ELFT>::variableEq(const InputSection *A, ArrayRef<RelTy> RelsA,
+ const InputSection *B, ArrayRef<RelTy> RelsB) {
auto Eq = [&](const RelTy &RA, const RelTy &RB) {
// The two sections must be identical.
SymbolBody &SA = A->template getFile<ELFT>()->getRelocTargetSym(RA);
@@ -258,8 +257,8 @@ bool ICF<ELFT>::variableEq(const InputSe
return !DA->Section && !DB->Section;
// Or the two sections must be in the same equivalence class.
- auto *X = dyn_cast<InputSection<ELFT>>(DA->Section);
- auto *Y = dyn_cast<InputSection<ELFT>>(DB->Section);
+ auto *X = dyn_cast<InputSection>(DA->Section);
+ auto *Y = dyn_cast<InputSection>(DB->Section);
if (!X || !Y)
return false;
@@ -276,8 +275,7 @@ bool ICF<ELFT>::variableEq(const InputSe
// Compare "moving" part of two InputSections, namely relocation targets.
template <class ELFT>
-bool ICF<ELFT>::equalsVariable(const InputSection<ELFT> *A,
- const InputSection<ELFT> *B) {
+bool ICF<ELFT>::equalsVariable(const InputSection *A, const InputSection *B) {
if (A->AreRelocsRela)
return variableEq(A, A->template relas<ELFT>(), B,
B->template relas<ELFT>());
@@ -339,19 +337,19 @@ void ICF<ELFT>::forEachClass(std::functi
template <class ELFT> void ICF<ELFT>::run() {
// Collect sections to merge.
for (InputSectionBase *Sec : Symtab<ELFT>::X->Sections)
- if (auto *S = dyn_cast<InputSection<ELFT>>(Sec))
- if (isEligible(S))
+ if (auto *S = dyn_cast<InputSection>(Sec))
+ if (isEligible<ELFT>(S))
Sections.push_back(S);
// Initially, we use hash values to partition sections.
- for (InputSection<ELFT> *S : Sections)
+ for (InputSection *S : Sections)
// Set MSB to 1 to avoid collisions with non-hash IDs.
- S->Class[0] = getHash(S) | (1 << 31);
+ S->Class[0] = getHash<ELFT>(S) | (1 << 31);
// From now on, sections in Sections vector are ordered so that sections
// in the same equivalence class are consecutive in the vector.
std::stable_sort(Sections.begin(), Sections.end(),
- [](InputSection<ELFT> *A, InputSection<ELFT> *B) {
+ [](InputSection *A, InputSection *B) {
return A->Class[0] < B->Class[0];
});
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Thu Feb 23 10:49:07 2017
@@ -277,20 +277,20 @@ void elf::ObjectFile<ELFT>::initializeSe
StringRef SectionStringTable = check(Obj.getSectionStringTable(ObjSections));
for (const Elf_Shdr &Sec : ObjSections) {
++I;
- if (Sections[I] == &InputSection<ELFT>::Discarded)
+ if (Sections[I] == &InputSection::Discarded)
continue;
// SHF_EXCLUDE'ed sections are discarded by the linker. However,
// if -r is given, we'll let the final link discard such sections.
// This is compatible with GNU.
if ((Sec.sh_flags & SHF_EXCLUDE) && !Config->Relocatable) {
- Sections[I] = &InputSection<ELFT>::Discarded;
+ Sections[I] = &InputSection::Discarded;
continue;
}
switch (Sec.sh_type) {
case SHT_GROUP:
- Sections[I] = &InputSection<ELFT>::Discarded;
+ Sections[I] = &InputSection::Discarded;
if (ComdatGroups.insert(CachedHashStringRef(
getShtGroupSignature(ObjSections, Sec)))
.second)
@@ -299,7 +299,7 @@ void elf::ObjectFile<ELFT>::initializeSe
if (SecIndex >= Size)
fatal(toString(this) + ": invalid section index in group: " +
Twine(SecIndex));
- Sections[SecIndex] = &InputSection<ELFT>::Discarded;
+ Sections[SecIndex] = &InputSection::Discarded;
}
break;
case SHT_SYMTAB:
@@ -336,7 +336,7 @@ InputSectionBase *elf::ObjectFile<ELFT>:
// Strictly speaking, a relocation section must be included in the
// group of the section it relocates. However, LLVM 3.3 and earlier
// would fail to do so, so we gracefully handle that case.
- if (Target == &InputSection<ELFT>::Discarded)
+ if (Target == &InputSection::Discarded)
return nullptr;
if (!Target)
@@ -358,10 +358,10 @@ elf::ObjectFile<ELFT>::createInputSectio
// 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<ELFT>>(this, &Sec, Name);
+ In<ELFT>::ARMAttributes = make<InputSection>(this, &Sec, Name);
return In<ELFT>::ARMAttributes;
}
- return &InputSection<ELFT>::Discarded;
+ return &InputSection::Discarded;
case SHT_RELA:
case SHT_REL: {
// Find the relocation target section and associate this
@@ -376,7 +376,7 @@ elf::ObjectFile<ELFT>::createInputSectio
// If -r is given, we do not interpret or apply relocation
// but just copy relocation sections to output.
if (Config->Relocatable)
- return make<InputSection<ELFT>>(this, &Sec, Name);
+ return make<InputSection>(this, &Sec, Name);
if (Target->FirstRelocation)
fatal(toString(this) +
@@ -405,7 +405,7 @@ elf::ObjectFile<ELFT>::createInputSectio
// However, if -emit-relocs is given, we need to leave them in the output.
// (Some post link analysis tools need this information.)
if (Config->EmitRelocs) {
- InputSection<ELFT> *RelocSec = make<InputSection<ELFT>>(this, &Sec, Name);
+ InputSection *RelocSec = make<InputSection>(this, &Sec, Name);
// We will not emit relocation section if target was discarded.
Target->DependentSections.push_back(RelocSec);
return RelocSec;
@@ -428,7 +428,7 @@ elf::ObjectFile<ELFT>::createInputSectio
// executable-ness is controlled solely by command line options,
// .note.GNU-stack sections are simply ignored.
if (Name == ".note.GNU-stack")
- return &InputSection<ELFT>::Discarded;
+ return &InputSection::Discarded;
// Split stacks is a feature to support a discontiguous stack. At least
// as of 2017, it seems that the feature is not being used widely.
@@ -437,11 +437,11 @@ elf::ObjectFile<ELFT>::createInputSectio
if (Name == ".note.GNU-split-stack") {
error(toString(this) +
": object file compiled with -fsplit-stack is not supported");
- return &InputSection<ELFT>::Discarded;
+ return &InputSection::Discarded;
}
if (Config->Strip != StripPolicy::None && Name.startswith(".debug"))
- return &InputSection<ELFT>::Discarded;
+ return &InputSection::Discarded;
// The linkonce feature is a sort of proto-comdat. Some glibc i386 object
// files contain definitions of symbol "__x86.get_pc_thunk.bx" in linkonce
@@ -449,7 +449,7 @@ elf::ObjectFile<ELFT>::createInputSectio
// FIXME: This is glibc PR20543, we should remove this hack once that has been
// fixed for a while.
if (Name.startswith(".gnu.linkonce."))
- return &InputSection<ELFT>::Discarded;
+ return &InputSection::Discarded;
// The linker merges EH (exception handling) frames and creates a
// .eh_frame_hdr section for runtime. So we handle them with a special
@@ -459,7 +459,7 @@ elf::ObjectFile<ELFT>::createInputSectio
if (shouldMerge(Sec))
return make<MergeInputSection<ELFT>>(this, &Sec, Name);
- return make<InputSection<ELFT>>(this, &Sec, Name);
+ return make<InputSection>(this, &Sec, Name);
}
template <class ELFT> void elf::ObjectFile<ELFT>::initializeSymbols() {
@@ -487,7 +487,7 @@ InputSectionBase *elf::ObjectFile<ELFT>:
fatal(toString(this) + ": invalid section index: " + Twine(Index));
}
- if (S == &InputSection<ELFT>::Discarded)
+ if (S == &InputSection::Discarded)
return S;
return S->Repl;
}
@@ -541,7 +541,7 @@ SymbolBody *elf::ObjectFile<ELFT>::creat
case STB_GLOBAL:
case STB_WEAK:
case STB_GNU_UNIQUE:
- if (Sec == &InputSection<ELFT>::Discarded)
+ if (Sec == &InputSection::Discarded)
return elf::Symtab<ELFT>::X
->addUndefined(Name, /*IsLocal=*/false, Binding, StOther, Type,
/*CanOmitFromDynSym=*/false, this)
@@ -881,8 +881,8 @@ template <class ELFT> void BinaryFile::p
StringRef EndName = Saver.save(Twine(Filename) + "_end");
StringRef SizeName = Saver.save(Twine(Filename) + "_size");
- auto *Section = make<InputSection<ELFT>>(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS,
- 8, Data, ".data");
+ auto *Section =
+ make<InputSection>(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS, 8, Data, ".data");
Sections.push_back(Section);
elf::Symtab<ELFT>::X->addRegular(StartName, STV_DEFAULT, STT_OBJECT, 0, 0,
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Thu Feb 23 10:49:07 2017
@@ -97,11 +97,11 @@ uint64_t InputSectionBase::getOffset(uin
typedef typename ELFT::uint uintX_t;
switch (kind()) {
case Regular:
- return cast<InputSection<ELFT>>(this)->OutSecOff + Offset;
+ return cast<InputSection>(this)->OutSecOff + Offset;
case Synthetic:
// For synthetic sections we treat offset -1 as the end of the section.
// The same approach is used for synthetic symbols (DefinedSynthetic).
- return cast<InputSection<ELFT>>(this)->OutSecOff +
+ return cast<InputSection>(this)->OutSecOff +
(Offset == uintX_t(-1) ? getSize<ELFT>() : Offset);
case EHFrame:
// The file crtbeginT.o has relocations pointing to the start of an empty
@@ -182,29 +182,27 @@ std::string InputSectionBase::getLocatio
return (SrcFile + ":(" + Name + "+0x" + utohexstr(Offset) + ")").str();
}
-template <class ELFT> InputSection<ELFT>::InputSection() : InputSectionBase() {}
+InputSection InputSection::Discarded;
-template <class ELFT>
-InputSection<ELFT>::InputSection(uintX_t Flags, uint32_t Type,
- uintX_t Addralign, ArrayRef<uint8_t> Data,
- StringRef Name, Kind K)
+InputSection::InputSection() : InputSectionBase() {}
+
+InputSection::InputSection(uint64_t Flags, uint32_t Type, uint64_t Addralign,
+ ArrayRef<uint8_t> Data, StringRef Name, Kind K)
: InputSectionBase(nullptr, Flags, Type,
/*Entsize*/ 0, /*Link*/ 0, /*Info*/ 0, Addralign, Data,
Name, K) {}
template <class ELFT>
-InputSection<ELFT>::InputSection(elf::ObjectFile<ELFT> *F,
- const Elf_Shdr *Header, StringRef Name)
+InputSection::InputSection(elf::ObjectFile<ELFT> *F,
+ const typename ELFT::Shdr *Header, StringRef Name)
: InputSectionBase(F, Header, Name, InputSectionBase::Regular) {}
-template <class ELFT>
-bool InputSection<ELFT>::classof(const InputSectionBase *S) {
+bool InputSection::classof(const InputSectionBase *S) {
return S->kind() == InputSectionBase::Regular ||
S->kind() == InputSectionBase::Synthetic;
}
-template <class ELFT>
-InputSectionBase *InputSection<ELFT>::getRelocatedSection() {
+template <class ELFT> InputSectionBase *InputSection::getRelocatedSection() {
assert(this->Type == SHT_RELA || this->Type == SHT_REL);
ArrayRef<InputSectionBase *> Sections = this->getFile<ELFT>()->getSections();
return Sections[this->Info];
@@ -213,10 +211,9 @@ InputSectionBase *InputSection<ELFT>::ge
// This is used for -r and --emit-relocs. We can't use memcpy to copy
// relocations because we need to update symbol table offset and section index
// for each relocation. So we copy relocations one by one.
-template <class ELFT>
-template <class RelTy>
-void InputSection<ELFT>::copyRelocations(uint8_t *Buf, ArrayRef<RelTy> Rels) {
- InputSectionBase *RelocatedSection = getRelocatedSection();
+template <class ELFT, class RelTy>
+void InputSection::copyRelocations(uint8_t *Buf, ArrayRef<RelTy> Rels) {
+ InputSectionBase *RelocatedSection = getRelocatedSection<ELFT>();
// Loop is slow and have complexity O(N*M), where N - amount of
// relocations and M - amount of symbols in symbol table.
@@ -226,7 +223,7 @@ void InputSection<ELFT>::copyRelocations
uint32_t Type = Rel.getType(Config->Mips64EL);
SymbolBody &Body = this->getFile<ELFT>()->getRelocTargetSym(Rel);
- Elf_Rela *P = reinterpret_cast<Elf_Rela *>(Buf);
+ auto *P = reinterpret_cast<typename ELFT::Rela *>(Buf);
Buf += sizeof(RelTy);
if (Config->Rela)
@@ -250,7 +247,7 @@ void InputSection<ELFT>::copyRelocations
// relocation in it pointing to discarded sections with R_*_NONE, which
// hopefully creates a frame that is ignored at runtime.
InputSectionBase *Section = cast<DefinedRegular<ELFT>>(Body).Section;
- if (Section == &InputSection<ELFT>::Discarded) {
+ if (Section == &InputSection::Discarded) {
P->setSymbolAndType(0, 0, false);
continue;
}
@@ -448,9 +445,9 @@ getRelocTargetVA(uint32_t Type, int64_t
// treatement such as GOT or PLT (because at runtime no one refers them).
// So, we handle relocations for non-alloc sections directly in this
// function as a performance optimization.
-template <class ELFT>
-template <class RelTy>
-void InputSection<ELFT>::relocateNonAlloc(uint8_t *Buf, ArrayRef<RelTy> Rels) {
+template <class ELFT, class RelTy>
+void InputSection::relocateNonAlloc(uint8_t *Buf, ArrayRef<RelTy> Rels) {
+ typedef typename ELFT::uint uintX_t;
for (const RelTy &Rel : Rels) {
uint32_t Type = Rel.getType(Config->Mips64EL);
uintX_t Offset = this->getOffset<ELFT>(Rel.r_offset);
@@ -486,12 +483,12 @@ void InputSectionBase::relocate(uint8_t
// scanReloc function in Writer.cpp constructs Relocations
// vector only for SHF_ALLOC'ed sections. For other sections,
// we handle relocations directly here.
- auto *IS = dyn_cast<InputSection<ELFT>>(this);
+ auto *IS = dyn_cast<InputSection>(this);
if (IS && !(IS->Flags & SHF_ALLOC)) {
if (IS->AreRelocsRela)
- IS->relocateNonAlloc(Buf, IS->template relas<ELFT>());
+ IS->relocateNonAlloc<ELFT>(Buf, IS->template relas<ELFT>());
else
- IS->relocateNonAlloc(Buf, IS->template rels<ELFT>());
+ IS->relocateNonAlloc<ELFT>(Buf, IS->template rels<ELFT>());
return;
}
@@ -540,7 +537,7 @@ void InputSectionBase::relocate(uint8_t
}
}
-template <class ELFT> void InputSection<ELFT>::writeTo(uint8_t *Buf) {
+template <class ELFT> void InputSection::writeTo(uint8_t *Buf) {
if (this->Type == SHT_NOBITS)
return;
@@ -552,11 +549,13 @@ template <class ELFT> void InputSection<
// If -r or --emit-relocs is given, then an InputSection
// may be a relocation section.
if (this->Type == SHT_RELA) {
- copyRelocations(Buf + OutSecOff, this->template getDataAs<Elf_Rela>());
+ copyRelocations<ELFT>(Buf + OutSecOff,
+ this->template getDataAs<typename ELFT::Rela>());
return;
}
if (this->Type == SHT_REL) {
- copyRelocations(Buf + OutSecOff, this->template getDataAs<Elf_Rel>());
+ copyRelocations<ELFT>(Buf + OutSecOff,
+ this->template getDataAs<typename ELFT::Rel>());
return;
}
@@ -569,8 +568,7 @@ template <class ELFT> void InputSection<
this->relocate<ELFT>(Buf, BufEnd);
}
-template <class ELFT>
-void InputSection<ELFT>::replace(InputSection<ELFT> *Other) {
+void InputSection::replace(InputSection *Other) {
this->Alignment = std::max(this->Alignment, Other->Alignment);
Other->Repl = this->Repl;
Other->Live = false;
@@ -784,10 +782,28 @@ typename ELFT::uint MergeInputSection<EL
return Piece.OutputOff + Addend;
}
-template class elf::InputSection<ELF32LE>;
-template class elf::InputSection<ELF32BE>;
-template class elf::InputSection<ELF64LE>;
-template class elf::InputSection<ELF64BE>;
+template InputSection::InputSection(elf::ObjectFile<ELF32LE> *F,
+ const ELF32LE::Shdr *Header,
+ StringRef Name);
+template InputSection::InputSection(elf::ObjectFile<ELF32BE> *F,
+ const ELF32BE::Shdr *Header,
+ StringRef Name);
+template InputSection::InputSection(elf::ObjectFile<ELF64LE> *F,
+ const ELF64LE::Shdr *Header,
+ StringRef Name);
+template InputSection::InputSection(elf::ObjectFile<ELF64BE> *F,
+ const ELF64BE::Shdr *Header,
+ StringRef Name);
+
+template std::string InputSectionBase::getLocation<ELF32LE>(uint64_t Offset);
+template std::string InputSectionBase::getLocation<ELF32BE>(uint64_t Offset);
+template std::string InputSectionBase::getLocation<ELF64LE>(uint64_t Offset);
+template std::string InputSectionBase::getLocation<ELF64BE>(uint64_t Offset);
+
+template void InputSection::writeTo<ELF32LE>(uint8_t *Buf);
+template void InputSection::writeTo<ELF32BE>(uint8_t *Buf);
+template void InputSection::writeTo<ELF64LE>(uint8_t *Buf);
+template void InputSection::writeTo<ELF64BE>(uint8_t *Buf);
template class elf::EhInputSection<ELF32LE>;
template class elf::EhInputSection<ELF32BE>;
@@ -814,6 +830,11 @@ template OutputSectionBase *InputSection
template OutputSectionBase *InputSectionBase::getOutputSection<ELF64LE>() const;
template OutputSectionBase *InputSectionBase::getOutputSection<ELF64BE>() const;
+template InputSectionBase *InputSection::getRelocatedSection<ELF32LE>();
+template InputSectionBase *InputSection::getRelocatedSection<ELF32BE>();
+template InputSectionBase *InputSection::getRelocatedSection<ELF64LE>();
+template InputSectionBase *InputSection::getRelocatedSection<ELF64BE>();
+
template uint64_t
InputSectionBase::getOffset(const DefinedRegular<ELF32LE> &Sym) const;
template uint64_t
Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Thu Feb 23 10:49:07 2017
@@ -247,24 +247,20 @@ public:
};
// This corresponds to a non SHF_MERGE section of an input file.
-template <class ELFT> class InputSection : public InputSectionBase {
- typedef typename ELFT::Shdr Elf_Shdr;
- typedef typename ELFT::Rela Elf_Rela;
- typedef typename ELFT::Rel Elf_Rel;
- typedef typename ELFT::Sym Elf_Sym;
- typedef typename ELFT::uint uintX_t;
-
+class InputSection : public InputSectionBase {
public:
InputSection();
- InputSection(uintX_t Flags, uint32_t Type, uintX_t Addralign,
+ InputSection(uint64_t Flags, uint32_t Type, uint64_t Addralign,
ArrayRef<uint8_t> Data, StringRef Name, Kind K = Regular);
- InputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Header, StringRef Name);
+ template <class ELFT>
+ InputSection(ObjectFile<ELFT> *F, const typename ELFT::Shdr *Header,
+ StringRef Name);
- static InputSection<ELFT> Discarded;
+ static InputSection Discarded;
// Write this section to a mmap'ed file, assuming Buf is pointing to
// beginning of the output section.
- void writeTo(uint8_t *Buf);
+ template <class ELFT> void writeTo(uint8_t *Buf);
// The offset from beginning of the output sections this section was assigned
// to. The writer sets a value.
@@ -272,23 +268,22 @@ public:
static bool classof(const InputSectionBase *S);
- InputSectionBase *getRelocatedSection();
+ template <class ELFT> InputSectionBase *getRelocatedSection();
- template <class RelTy>
+ template <class ELFT, class RelTy>
void relocateNonAlloc(uint8_t *Buf, llvm::ArrayRef<RelTy> Rels);
// Used by ICF.
uint32_t Class[2] = {0, 0};
// Called by ICF to merge two input sections.
- void replace(InputSection<ELFT> *Other);
+ void replace(InputSection *Other);
private:
- template <class RelTy>
+ template <class ELFT, class RelTy>
void copyRelocations(uint8_t *Buf, llvm::ArrayRef<RelTy> Rels);
};
-template <class ELFT> InputSection<ELFT> InputSection<ELFT>::Discarded;
} // namespace elf
std::string toString(const elf::InputSectionBase *);
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu Feb 23 10:49:07 2017
@@ -401,7 +401,7 @@ template <class ELFT> static bool isTbss
return (Sec->Flags & SHF_TLS) && Sec->Type == SHT_NOBITS;
}
-template <class ELFT> void LinkerScript<ELFT>::output(InputSection<ELFT> *S) {
+template <class ELFT> void LinkerScript<ELFT>::output(InputSection *S) {
if (!AlreadyOutputIS.insert(S).second)
return;
bool IsTbss = isTbss<ELFT>(CurOutSec);
@@ -439,7 +439,7 @@ template <class ELFT> void LinkerScript<
if (!CurOutSec || !AlreadyOutputOS.insert(CurOutSec).second)
return;
if (auto *OutSec = dyn_cast<OutputSection<ELFT>>(CurOutSec)) {
- for (InputSection<ELFT> *I : OutSec->Sections)
+ for (InputSection *I : OutSec->Sections)
output(I);
} else {
Dot += CurOutSec->Size;
@@ -504,7 +504,7 @@ template <class ELFT> void LinkerScript<
if (!IB->Live)
continue;
switchTo(IB->OutSec);
- if (auto *I = dyn_cast<InputSection<ELFT>>(IB))
+ if (auto *I = dyn_cast<InputSection>(IB))
output(I);
else
flush();
Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Thu Feb 23 10:49:07 2017
@@ -32,7 +32,7 @@ class DefinedCommon;
class ScriptParser;
class SymbolBody;
class InputSectionBase;
-template <class ELFT> class InputSection;
+class InputSection;
class OutputSectionBase;
template <class ELFT> class OutputSectionFactory;
class InputSectionBase;
@@ -304,7 +304,7 @@ private:
uintX_t ThreadBssOffset = 0;
void switchTo(OutputSectionBase *Sec);
void flush();
- void output(InputSection<ELFT> *Sec);
+ void output(InputSection *Sec);
void process(BaseCommand &Base);
llvm::DenseSet<OutputSectionBase *> AlreadyOutputOS;
llvm::DenseSet<InputSectionBase *> AlreadyOutputIS;
Modified: lld/trunk/ELF/MapFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MapFile.cpp?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/MapFile.cpp (original)
+++ lld/trunk/ELF/MapFile.cpp Thu Feb 23 10:49:07 2017
@@ -61,7 +61,7 @@ static void writeSymbolLine(raw_fd_ostre
}
template <class ELFT>
-static void writeInputSection(raw_fd_ostream &OS, const InputSection<ELFT> *IS,
+static void writeInputSection(raw_fd_ostream &OS, const InputSection *IS,
StringRef &PrevName) {
int Width = ELFT::Is64Bits ? 16 : 8;
StringRef Name = IS->Name;
@@ -108,8 +108,8 @@ static void writeMapFile2(raw_fd_ostream
StringRef PrevName = "";
Sec->forEachInputSection([&](InputSectionBase *S) {
- if (const auto *IS = dyn_cast<InputSection<ELFT>>(S))
- writeInputSection(OS, IS, PrevName);
+ if (const auto *IS = dyn_cast<InputSection>(S))
+ writeInputSection<ELFT>(OS, IS, PrevName);
});
}
}
Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Thu Feb 23 10:49:07 2017
@@ -77,7 +77,7 @@ static ResolvedReloc<ELFT> resolveReloc(
// Calls Fn for each section that Sec refers to via relocations.
template <class ELFT>
-static void forEachSuccessor(InputSection<ELFT> &Sec,
+static void forEachSuccessor(InputSection &Sec,
std::function<void(ResolvedReloc<ELFT>)> Fn) {
if (Sec.AreRelocsRela) {
for (const typename ELFT::Rela &Rel : Sec.template relas<ELFT>())
@@ -129,7 +129,7 @@ scanEhFrameSection(EhInputSection<ELFT>
if (Rel.r_offset >= PieceEnd)
break;
ResolvedReloc<ELFT> R = resolveReloc<ELFT>(EH, Rels[I2]);
- if (!R.Sec || R.Sec == &InputSection<ELFT>::Discarded)
+ if (!R.Sec || R.Sec == &InputSection::Discarded)
continue;
if (R.Sec->Flags & SHF_EXECINSTR)
continue;
@@ -188,14 +188,14 @@ template <class ELFT> static bool isRese
// Starting from GC-root sections, this function visits all reachable
// sections to set their "Live" bits.
template <class ELFT> void elf::markLive() {
- SmallVector<InputSection<ELFT> *, 256> Q;
+ SmallVector<InputSection *, 256> Q;
auto Enqueue = [&](ResolvedReloc<ELFT> R) {
// Skip over discarded sections. This in theory shouldn't happen, because
// the ELF spec doesn't allow a relocation to point to a deduplicated
// COMDAT section directly. Unfortunately this happens in practice (e.g.
// .eh_frame) so we need to add a check.
- if (!R.Sec || R.Sec == &InputSection<ELFT>::Discarded)
+ if (!R.Sec || R.Sec == &InputSection::Discarded)
return;
// We don't gc non alloc sections.
@@ -212,7 +212,7 @@ template <class ELFT> void elf::markLive
return;
R.Sec->Live = true;
// Add input section to the queue.
- if (InputSection<ELFT> *S = dyn_cast<InputSection<ELFT>>(R.Sec))
+ if (InputSection *S = dyn_cast<InputSection>(R.Sec))
Q.push_back(S);
};
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Thu Feb 23 10:49:07 2017
@@ -86,14 +86,13 @@ OutputSection<ELFT>::OutputSection(Strin
}
template <typename ELFT>
-static bool compareByFilePosition(InputSection<ELFT> *A,
- InputSection<ELFT> *B) {
+static bool compareByFilePosition(InputSection *A, InputSection *B) {
// Synthetic doesn't have link order dependecy, stable_sort will keep it last
if (A->kind() == InputSectionBase::Synthetic ||
B->kind() == InputSectionBase::Synthetic)
return false;
- auto *LA = cast<InputSection<ELFT>>(A->template getLinkOrderDep<ELFT>());
- auto *LB = cast<InputSection<ELFT>>(B->template getLinkOrderDep<ELFT>());
+ auto *LA = cast<InputSection>(A->template getLinkOrderDep<ELFT>());
+ auto *LB = cast<InputSection>(B->template getLinkOrderDep<ELFT>());
OutputSectionBase *AOut = LA->OutSec;
OutputSectionBase *BOut = LB->OutSec;
if (AOut != BOut)
@@ -119,21 +118,21 @@ template <class ELFT> void OutputSection
if (!Config->copyRelocs() || (Type != SHT_RELA && Type != SHT_REL))
return;
- InputSection<ELFT> *First = Sections[0];
+ InputSection *First = Sections[0];
if (isa<SyntheticSection<ELFT>>(First))
return;
this->Link = In<ELFT>::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();
+ InputSectionBase *S = First->getRelocatedSection<ELFT>();
this->Info = S->OutSec->SectionIndex;
}
template <class ELFT>
void OutputSection<ELFT>::addSection(InputSectionBase *C) {
assert(C->Live);
- auto *S = cast<InputSection<ELFT>>(C);
+ auto *S = cast<InputSection>(C);
Sections.push_back(S);
S->OutSec = this;
this->updateAlignment(S->Alignment);
@@ -146,7 +145,7 @@ void OutputSection<ELFT>::addSection(Inp
template <class ELFT>
void OutputSection<ELFT>::forEachInputSection(
std::function<void(InputSectionBase *)> F) {
- for (InputSection<ELFT> *S : Sections)
+ for (InputSection *S : Sections)
F(S);
}
@@ -154,7 +153,7 @@ void OutputSection<ELFT>::forEachInputSe
// and scan relocations to setup sections' offsets.
template <class ELFT> void OutputSection<ELFT>::assignOffsets() {
uintX_t Off = this->Size;
- for (InputSection<ELFT> *S : Sections) {
+ for (InputSection *S : Sections) {
Off = alignTo(Off, S->Alignment);
S->OutSecOff = Off;
Off += S->template getSize<ELFT>();
@@ -164,11 +163,11 @@ template <class ELFT> void OutputSection
template <class ELFT>
void OutputSection<ELFT>::sort(std::function<int(InputSectionBase *S)> Order) {
- typedef std::pair<unsigned, InputSection<ELFT> *> Pair;
+ typedef std::pair<unsigned, InputSection *> Pair;
auto Comp = [](const Pair &A, const Pair &B) { return A.first < B.first; };
std::vector<Pair> V;
- for (InputSection<ELFT> *S : Sections)
+ for (InputSection *S : Sections)
V.push_back({Order(S), S});
std::stable_sort(V.begin(), V.end(), Comp);
Sections.clear();
@@ -219,8 +218,7 @@ static bool isCrtend(StringRef S) { retu
// are too many real-world use cases of .ctors, so we had no choice to
// support that with this rather ad-hoc semantics.
template <class ELFT>
-static bool compCtors(const InputSection<ELFT> *A,
- const InputSection<ELFT> *B) {
+static bool compCtors(const InputSection *A, const InputSection *B) {
bool BeginA = isCrtbegin(A->template getFile<ELFT>()->getName());
bool BeginB = isCrtbegin(B->template getFile<ELFT>()->getName());
if (BeginA != BeginB)
@@ -263,7 +261,7 @@ template <class ELFT> void OutputSection
if (uint32_t Filler = Script<ELFT>::X->getFiller(this->Name))
fill(Buf, this->Size, Filler);
- auto Fn = [=](InputSection<ELFT> *IS) { IS->writeTo(Buf); };
+ auto Fn = [=](InputSection *IS) { IS->writeTo<ELFT>(Buf); };
forEach(Sections.begin(), Sections.end(), Fn);
// Linker scripts may have BYTE()-family commands with which you
Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Thu Feb 23 10:49:07 2017
@@ -24,7 +24,7 @@ struct PhdrEntry;
class SymbolBody;
struct EhSectionPiece;
template <class ELFT> class EhInputSection;
-template <class ELFT> class InputSection;
+class InputSection;
class InputSectionBase;
template <class ELFT> class MergeInputSection;
template <class ELFT> class OutputSection;
@@ -123,7 +123,7 @@ public:
static bool classof(const OutputSectionBase *B) {
return B->getKind() == Regular;
}
- std::vector<InputSection<ELFT> *> Sections;
+ std::vector<InputSection *> Sections;
// Location in the output buffer.
uint8_t *Loc = nullptr;
Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Thu Feb 23 10:49:07 2017
@@ -875,9 +875,9 @@ static void mergeThunks(OutputSection<EL
std::stable_sort(Thunks.begin(), Thunks.end(), ThunkCmp);
// Merge sorted vectors of Thunks and InputSections by OutSecOff
- std::vector<InputSection<ELFT> *> Tmp;
+ std::vector<InputSection *> Tmp;
Tmp.reserve(OS->Sections.size() + Thunks.size());
- auto MergeCmp = [](const InputSection<ELFT> *A, const InputSection<ELFT> *B) {
+ auto MergeCmp = [](const InputSection *A, const InputSection *B) {
// std::merge requires a strict weak ordering.
if (A->OutSecOff < B->OutSecOff)
return true;
@@ -911,7 +911,7 @@ void createThunks(ArrayRef<OutputSection
// Track Symbols that already have a Thunk
DenseMap<SymbolBody *, Thunk<ELFT> *> ThunkedSymbols;
// Track InputSections that have a ThunkSection placed in front
- DenseMap<InputSection<ELFT> *, ThunkSection<ELFT> *> ThunkedSections;
+ DenseMap<InputSection *, ThunkSection<ELFT> *> ThunkedSections;
// Track the ThunksSections that need to be inserted into an OutputSection
std::map<OutputSection<ELFT> *, std::vector<ThunkSection<ELFT> *>>
ThunkSections;
@@ -925,7 +925,7 @@ void createThunks(ArrayRef<OutputSection
};
// Find or create a ThunkSection to be placed immediately before IS
- auto GetISThunkSec = [&](InputSection<ELFT> *IS, OutputSection<ELFT> *OS) {
+ auto GetISThunkSec = [&](InputSection *IS, OutputSection<ELFT> *OS) {
ThunkSection<ELFT> *TS = ThunkedSections.lookup(IS);
if (TS)
return TS;
@@ -962,7 +962,7 @@ void createThunks(ArrayRef<OutputSection
continue;
ThunkSection<ELFT> *OSTS = nullptr;
- for (InputSection<ELFT> *IS : OS->Sections) {
+ for (InputSection *IS : OS->Sections) {
for (Relocation &Rel : IS->Relocations) {
SymbolBody &Body = *Rel.Sym;
if (Target->needsThunk(Rel.Expr, Rel.Type, IS->template getFile<ELFT>(),
Modified: lld/trunk/ELF/Relocations.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.h?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.h (original)
+++ lld/trunk/ELF/Relocations.h Thu Feb 23 10:49:07 2017
@@ -16,7 +16,7 @@ namespace lld {
namespace elf {
class SymbolBody;
class InputSectionData;
-template <class ELFT> class InputSection;
+class InputSection;
class InputSectionBase;
class OutputSectionBase;
Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Thu Feb 23 10:49:07 2017
@@ -50,7 +50,7 @@ static typename ELFT::uint getSymVA(cons
// the group are not allowed. Unfortunately .eh_frame breaks that rule
// and must be treated specially. For now we just replace the symbol with
// 0.
- if (IS == &InputSection<ELFT>::Discarded)
+ if (IS == &InputSection::Discarded)
return 0;
// This is an absolute symbol.
Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Thu Feb 23 10:49:07 2017
@@ -272,7 +272,7 @@ public:
const Elf_Verdef *Verdef;
// Section is significant only when NeedsCopy is true.
- InputSection<ELFT> *Section = nullptr;
+ InputSection *Section = nullptr;
};
// This class represents a symbol defined in an archive file. It is
Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Thu Feb 23 10:49:07 2017
@@ -54,9 +54,9 @@ template <class ELFT> static std::vector
}
// Find all common symbols and allocate space for them.
-template <class ELFT> InputSection<ELFT> *elf::createCommonSection() {
- auto *Ret = make<InputSection<ELFT>>(SHF_ALLOC | SHF_WRITE, SHT_NOBITS, 1,
- ArrayRef<uint8_t>(), "COMMON");
+template <class ELFT> InputSection *elf::createCommonSection() {
+ auto *Ret = make<InputSection>(SHF_ALLOC | SHF_WRITE, SHT_NOBITS, 1,
+ ArrayRef<uint8_t>(), "COMMON");
Ret->Live = true;
if (!Config->DefineCommon)
@@ -278,9 +278,9 @@ MipsReginfoSection<ELFT> *MipsReginfoSec
return nullptr;
}
-template <class ELFT> InputSection<ELFT> *elf::createInterpSection() {
- auto *Ret = make<InputSection<ELFT>>(SHF_ALLOC, SHT_PROGBITS, 1,
- ArrayRef<uint8_t>(), ".interp");
+template <class ELFT> InputSection *elf::createInterpSection() {
+ auto *Ret = make<InputSection>(SHF_ALLOC, SHT_PROGBITS, 1,
+ ArrayRef<uint8_t>(), ".interp");
Ret->Live = true;
// StringSaver guarantees that the returned string ends with '\0'.
@@ -1515,7 +1515,7 @@ GdbIndexSection<ELFT>::GdbIndexSection()
template <class ELFT> void GdbIndexSection<ELFT>::parseDebugSections() {
for (InputSectionBase *S : Symtab<ELFT>::X->Sections)
- if (InputSection<ELFT> *IS = dyn_cast<InputSection<ELFT>>(S))
+ if (InputSection *IS = dyn_cast<InputSection>(S))
if (IS->OutSec && IS->Name == ".debug_info")
readDwarf(IS);
}
@@ -1530,8 +1530,7 @@ static uint32_t hash(StringRef Str) {
return R;
}
-template <class ELFT>
-void GdbIndexSection<ELFT>::readDwarf(InputSection<ELFT> *I) {
+template <class ELFT> void GdbIndexSection<ELFT>::readDwarf(InputSection *I) {
GdbIndexBuilder<ELFT> Builder(I);
if (ErrorCount)
return;
@@ -1971,9 +1970,8 @@ template <class ELFT>
void ARMExidxSentinelSection<ELFT>::writeTo(uint8_t *Buf) {
// Get the InputSection before us, we are by definition last
auto RI = cast<OutputSection<ELFT>>(this->OutSec)->Sections.rbegin();
- InputSection<ELFT> *LE = *(++RI);
- InputSection<ELFT> *LC =
- cast<InputSection<ELFT>>(LE->template getLinkOrderDep<ELFT>());
+ InputSection *LE = *(++RI);
+ InputSection *LC = cast<InputSection>(LE->template getLinkOrderDep<ELFT>());
uint64_t S = LC->OutSec->Addr +
LC->template getOffset<ELFT>(LC->template getSize<ELFT>());
uint64_t P = this->getVA();
@@ -2003,20 +2001,20 @@ template <class ELFT> void ThunkSection<
}
template <class ELFT>
-InputSection<ELFT> *ThunkSection<ELFT>::getTargetInputSection() const {
+InputSection *ThunkSection<ELFT>::getTargetInputSection() const {
const Thunk<ELFT> *T = Thunks.front();
return T->getTargetInputSection();
}
-template InputSection<ELF32LE> *elf::createCommonSection();
-template InputSection<ELF32BE> *elf::createCommonSection();
-template InputSection<ELF64LE> *elf::createCommonSection();
-template InputSection<ELF64BE> *elf::createCommonSection();
-
-template InputSection<ELF32LE> *elf::createInterpSection();
-template InputSection<ELF32BE> *elf::createInterpSection();
-template InputSection<ELF64LE> *elf::createInterpSection();
-template InputSection<ELF64BE> *elf::createInterpSection();
+template InputSection *elf::createCommonSection<ELF32LE>();
+template InputSection *elf::createCommonSection<ELF32BE>();
+template InputSection *elf::createCommonSection<ELF64LE>();
+template InputSection *elf::createCommonSection<ELF64BE>();
+
+template InputSection *elf::createInterpSection<ELF32LE>();
+template InputSection *elf::createInterpSection<ELF32BE>();
+template InputSection *elf::createInterpSection<ELF64LE>();
+template InputSection *elf::createInterpSection<ELF64BE>();
template MergeInputSection<ELF32LE> *elf::createCommentSection();
template MergeInputSection<ELF32BE> *elf::createCommentSection();
Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Thu Feb 23 10:49:07 2017
@@ -33,14 +33,14 @@
namespace lld {
namespace elf {
-template <class ELFT> class SyntheticSection : public InputSection<ELFT> {
+template <class ELFT> class SyntheticSection : public InputSection {
typedef typename ELFT::uint uintX_t;
public:
SyntheticSection(uintX_t Flags, uint32_t Type, uintX_t Addralign,
StringRef Name)
- : InputSection<ELFT>(Flags, Type, Addralign, {}, Name,
- InputSectionBase::Synthetic) {
+ : InputSection(Flags, Type, Addralign, {}, Name,
+ InputSectionBase::Synthetic) {
this->Live = true;
}
@@ -315,14 +315,14 @@ class DynamicSection final : public Synt
int32_t Tag;
union {
OutputSectionBase *OutSec;
- InputSection<ELFT> *InSec;
+ InputSection *InSec;
uint64_t Val;
const SymbolBody *Sym;
};
enum KindT { SecAddr, SecSize, SymAddr, PlainInt, InSecAddr } Kind;
Entry(int32_t Tag, OutputSectionBase *OutSec, KindT Kind = SecAddr)
: Tag(Tag), OutSec(OutSec), Kind(Kind) {}
- Entry(int32_t Tag, InputSection<ELFT> *Sec)
+ Entry(int32_t Tag, InputSection *Sec)
: Tag(Tag), InSec(Sec), Kind(InSecAddr) {}
Entry(int32_t Tag, uint64_t Val) : Tag(Tag), Val(Val), Kind(PlainInt) {}
Entry(int32_t Tag, const SymbolBody *Sym)
@@ -514,7 +514,7 @@ public:
private:
void parseDebugSections();
- void readDwarf(InputSection<ELFT> *I);
+ void readDwarf(InputSection *I);
uint32_t CuTypesOffset;
uint32_t SymTabOffset;
@@ -736,15 +736,15 @@ public:
void addThunk(Thunk<ELFT> *T);
size_t getSize() const override { return Size; }
void writeTo(uint8_t *Buf) override;
- InputSection<ELFT> *getTargetInputSection() const;
+ InputSection *getTargetInputSection() const;
private:
std::vector<const Thunk<ELFT> *> Thunks;
size_t Size = 0;
};
-template <class ELFT> InputSection<ELFT> *createCommonSection();
-template <class ELFT> InputSection<ELFT> *createInterpSection();
+template <class ELFT> InputSection *createCommonSection();
+template <class ELFT> InputSection *createInterpSection();
template <class ELFT> MergeInputSection<ELFT> *createCommentSection();
template <class ELFT>
SymbolBody *addSyntheticLocal(StringRef Name, uint8_t Type, uint64_t Value,
@@ -752,9 +752,9 @@ SymbolBody *addSyntheticLocal(StringRef
// Linker generated sections which can be used as inputs.
template <class ELFT> struct In {
- static InputSection<ELFT> *ARMAttributes;
+ static InputSection *ARMAttributes;
static BuildIdSection<ELFT> *BuildId;
- static InputSection<ELFT> *Common;
+ static InputSection *Common;
static DynamicSection<ELFT> *Dynamic;
static StringTableSection<ELFT> *DynStrTab;
static SymbolTableSection<ELFT> *DynSymTab;
@@ -766,7 +766,7 @@ template <class ELFT> struct In {
static GotPltSection<ELFT> *GotPlt;
static IgotPltSection<ELFT> *IgotPlt;
static HashTableSection<ELFT> *HashTab;
- static InputSection<ELFT> *Interp;
+ static InputSection *Interp;
static MipsRldMapSection<ELFT> *MipsRldMap;
static PltSection<ELFT> *Plt;
static PltSection<ELFT> *Iplt;
@@ -781,9 +781,9 @@ template <class ELFT> struct In {
static VersionNeedSection<ELFT> *VerNeed;
};
-template <class ELFT> InputSection<ELFT> *In<ELFT>::ARMAttributes;
+template <class ELFT> InputSection *In<ELFT>::ARMAttributes;
template <class ELFT> BuildIdSection<ELFT> *In<ELFT>::BuildId;
-template <class ELFT> InputSection<ELFT> *In<ELFT>::Common;
+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> SymbolTableSection<ELFT> *In<ELFT>::DynSymTab;
@@ -795,7 +795,7 @@ template <class ELFT> MipsGotSection<ELF
template <class ELFT> GotPltSection<ELFT> *In<ELFT>::GotPlt;
template <class ELFT> IgotPltSection<ELFT> *In<ELFT>::IgotPlt;
template <class ELFT> HashTableSection<ELFT> *In<ELFT>::HashTab;
-template <class ELFT> InputSection<ELFT> *In<ELFT>::Interp;
+template <class ELFT> InputSection *In<ELFT>::Interp;
template <class ELFT> MipsRldMapSection<ELFT> *In<ELFT>::MipsRldMap;
template <class ELFT> PltSection<ELFT> *In<ELFT>::Plt;
template <class ELFT> PltSection<ELFT> *In<ELFT>::Iplt;
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Thu Feb 23 10:49:07 2017
@@ -61,7 +61,7 @@ static void or32be(uint8_t *P, int32_t V
template <class ELFT> static std::string getErrorLoc(uint8_t *Loc) {
for (InputSectionBase *D : Symtab<ELFT>::X->Sections) {
- auto *IS = dyn_cast_or_null<InputSection<ELFT>>(D);
+ auto *IS = dyn_cast_or_null<InputSection>(D);
if (!IS || !IS->OutSec)
continue;
@@ -1759,7 +1759,7 @@ void ARMTargetInfo::writePltHeader(uint8
}
void ARMTargetInfo::addPltHeaderSymbols(InputSectionBase *ISD) const {
- auto *IS = cast<InputSection<ELF32LE>>(ISD);
+ auto *IS = cast<InputSection>(ISD);
addSyntheticLocal<ELF32LE>("$a", STT_NOTYPE, 0, 0, IS);
addSyntheticLocal<ELF32LE>("$d", STT_NOTYPE, 16, 0, IS);
}
@@ -1782,7 +1782,7 @@ void ARMTargetInfo::writePlt(uint8_t *Bu
}
void ARMTargetInfo::addPltSymbols(InputSectionBase *ISD, uint64_t Off) const {
- auto *IS = cast<InputSection<ELF32LE>>(ISD);
+ auto *IS = cast<InputSection>(ISD);
addSyntheticLocal<ELF32LE>("$a", STT_NOTYPE, Off, 0, IS);
addSyntheticLocal<ELF32LE>("$d", STT_NOTYPE, Off + 12, 0, IS);
}
Modified: lld/trunk/ELF/Thunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Thunks.cpp?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/Thunks.cpp (original)
+++ lld/trunk/ELF/Thunks.cpp Thu Feb 23 10:49:07 2017
@@ -100,7 +100,7 @@ public:
uint32_t size() const override { return 16; }
void writeTo(uint8_t *Buf, ThunkSection<ELFT> &IS) const override;
void addSymbols(ThunkSection<ELFT> &IS) override;
- InputSection<ELFT> *getTargetInputSection() const override;
+ InputSection *getTargetInputSection() const override;
};
} // end anonymous namespace
@@ -224,9 +224,9 @@ template <class ELFT> void MipsThunk<ELF
}
template <class ELFT>
-InputSection<ELFT> *MipsThunk<ELFT>::getTargetInputSection() const {
+InputSection *MipsThunk<ELFT>::getTargetInputSection() const {
auto *DR = dyn_cast<DefinedRegular<ELFT>>(&this->Destination);
- return dyn_cast<InputSection<ELFT>>(DR->Section);
+ return dyn_cast<InputSection>(DR->Section);
}
template <class ELFT>
Modified: lld/trunk/ELF/Thunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Thunks.h?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/Thunks.h (original)
+++ lld/trunk/ELF/Thunks.h Thu Feb 23 10:49:07 2017
@@ -40,7 +40,7 @@ public:
// Some Thunks must be placed immediately before their Target as they elide
// a branch and fall through to the first Symbol in the Target.
- virtual InputSection<ELFT> *getTargetInputSection() const { return nullptr; }
+ virtual InputSection *getTargetInputSection() const { return nullptr; }
// The alignment requirement for this Thunk, defaults to the size of the
// typical code section alignment.
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=295993&r1=295992&r2=295993&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Feb 23 10:49:07 2017
@@ -348,7 +348,7 @@ template <class ELFT> void Writer<ELFT>:
Add(In<ELFT>::BuildId);
}
- InputSection<ELFT> *Common = createCommonSection<ELFT>();
+ InputSection *Common = createCommonSection<ELFT>();
if (!Common->Data.empty()) {
In<ELFT>::Common = Common;
Add(Common);
@@ -458,7 +458,7 @@ static bool shouldKeepInSymtab(InputSect
return false;
// If sym references a section in a discarded group, don't keep it.
- if (Sec == &InputSection<ELFT>::Discarded)
+ if (Sec == &InputSection::Discarded)
return false;
if (Config->Discard == DiscardPolicy::None)
@@ -531,7 +531,7 @@ template <class ELFT> void Writer<ELFT>:
if (!First)
First = D;
});
- auto *IS = dyn_cast_or_null<InputSection<ELFT>>(First);
+ auto *IS = dyn_cast_or_null<InputSection>(First);
if (!IS || isa<SyntheticSection<ELFT>>(IS) || IS->Type == SHT_REL ||
IS->Type == SHT_RELA)
continue;
@@ -914,7 +914,7 @@ void Writer<ELFT>::forEachRelSec(std::fu
// processed by InputSection::relocateNonAlloc.
if (!(IS->Flags & SHF_ALLOC))
continue;
- if (isa<InputSection<ELFT>>(IS) || isa<EhInputSection<ELFT>>(IS))
+ if (isa<InputSection>(IS) || isa<EhInputSection<ELFT>>(IS))
Fn(*IS);
}
}
More information about the llvm-commits
mailing list