diff options
Diffstat (limited to 'lld')
| -rw-r--r-- | lld/ELF/Driver.cpp | 4 | ||||
| -rw-r--r-- | lld/ELF/GdbIndex.cpp | 4 | ||||
| -rw-r--r-- | lld/ELF/GdbIndex.h | 6 | ||||
| -rw-r--r-- | lld/ELF/ICF.cpp | 52 | ||||
| -rw-r--r-- | lld/ELF/InputFiles.cpp | 36 | ||||
| -rw-r--r-- | lld/ELF/InputSection.cpp | 89 | ||||
| -rw-r--r-- | lld/ELF/InputSection.h | 27 | ||||
| -rw-r--r-- | lld/ELF/LinkerScript.cpp | 6 | ||||
| -rw-r--r-- | lld/ELF/LinkerScript.h | 4 | ||||
| -rw-r--r-- | lld/ELF/MapFile.cpp | 6 | ||||
| -rw-r--r-- | lld/ELF/MarkLive.cpp | 10 | ||||
| -rw-r--r-- | lld/ELF/OutputSections.cpp | 26 | ||||
| -rw-r--r-- | lld/ELF/OutputSections.h | 4 | ||||
| -rw-r--r-- | lld/ELF/Relocations.cpp | 10 | ||||
| -rw-r--r-- | lld/ELF/Relocations.h | 2 | ||||
| -rw-r--r-- | lld/ELF/Symbols.cpp | 2 | ||||
| -rw-r--r-- | lld/ELF/Symbols.h | 2 | ||||
| -rw-r--r-- | lld/ELF/SyntheticSections.cpp | 40 | ||||
| -rw-r--r-- | lld/ELF/SyntheticSections.h | 30 | ||||
| -rw-r--r-- | lld/ELF/Target.cpp | 6 | ||||
| -rw-r--r-- | lld/ELF/Thunks.cpp | 6 | ||||
| -rw-r--r-- | lld/ELF/Thunks.h | 2 | ||||
| -rw-r--r-- | lld/ELF/Writer.cpp | 8 |
23 files changed, 196 insertions, 186 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index e788f215229..fcde0eb32df 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -845,11 +845,11 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) { // 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) diff --git a/lld/ELF/GdbIndex.cpp b/lld/ELF/GdbIndex.cpp index df56b0951e2..4a79aee8981 100644 --- a/lld/ELF/GdbIndex.cpp +++ b/lld/ELF/GdbIndex.cpp @@ -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; diff --git a/lld/ELF/GdbIndex.h b/lld/ELF/GdbIndex.h index 0cdf986723c..e0b3fd167dc 100644 --- a/lld/ELF/GdbIndex.h +++ b/lld/ELF/GdbIndex.h @@ -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 AddressEntry { 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. diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp index 8dace92fe97..db802fd5868 100644 --- a/lld/ELF/ICF.cpp +++ b/lld/ELF/ICF.cpp @@ -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, size_t End, bool Constant) { 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<RelTy> RelsA, ArrayRef<RelTy> RelsB) { // 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 InputSection<ELFT> *A, // 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 InputSection<ELFT> *A, ArrayRef<RelTy> RelsA, 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 InputSection<ELFT> *A, ArrayRef<RelTy> RelsA, // 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::function<void(size_t, size_t)> Fn) { 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]; }); diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 8a1afbf5495..418ac061ce2 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -277,20 +277,20 @@ void elf::ObjectFile<ELFT>::initializeSections( 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>::initializeSections( 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>::getRelocTarget(const Elf_Shdr &Sec) { // 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>::createInputSection(const Elf_Shdr &Sec, // 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>::createInputSection(const Elf_Shdr &Sec, // 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>::createInputSection(const Elf_Shdr &Sec, // 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>::createInputSection(const Elf_Shdr &Sec, // 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>::createInputSection(const Elf_Shdr &Sec, 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>::createInputSection(const Elf_Shdr &Sec, // 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>::createInputSection(const Elf_Shdr &Sec, 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>::getSection(const Elf_Sym &Sym) const { 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>::createSymbolBody(const Elf_Sym *Sym) { 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::parse() { 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, diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 4fae7dd0d3b..0d40c198676 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -97,11 +97,11 @@ uint64_t InputSectionBase::getOffset(uint64_t Offset) const { 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::getLocation(uint64_t Offset) { 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>::getRelocatedSection() { // 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(uint8_t *Buf, ArrayRef<RelTy> Rels) { 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(uint8_t *Buf, ArrayRef<RelTy> Rels) { // 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 A, typename ELFT::uint P, // 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 *Buf, uint8_t *BufEnd) { // 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 *Buf, uint8_t *BufEnd) { } } -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<ELFT>::writeTo(uint8_t *Buf) { // 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<ELFT>::writeTo(uint8_t *Buf) { 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<ELFT>::getOffset(uintX_t Offset) const { 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 *InputSectionBase::getOutputSection<ELF32BE>() const; 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 diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index 9e5b09070cf..49733fc5fa2 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -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 *); diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index eccbb76d4ba..5f9b71e22da 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -401,7 +401,7 @@ template <class ELFT> static bool isTbss(OutputSectionBase *Sec) { 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<ELFT>::flush() { 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<ELFT>::process(BaseCommand &Base) { 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(); diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h index 66bf1d6b3e3..c8b967b2e37 100644 --- a/lld/ELF/LinkerScript.h +++ b/lld/ELF/LinkerScript.h @@ -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; diff --git a/lld/ELF/MapFile.cpp b/lld/ELF/MapFile.cpp index 9f128f66f24..4e28fabfa04 100644 --- a/lld/ELF/MapFile.cpp +++ b/lld/ELF/MapFile.cpp @@ -61,7 +61,7 @@ static void writeSymbolLine(raw_fd_ostream &OS, int Width, uint64_t Address, } 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 &OS, 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); }); } } diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index 2593bfe57b6..e2a62603d6c 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -77,7 +77,7 @@ static ResolvedReloc<ELFT> resolveReloc(InputSectionBase &Sec, RelT &Rel) { // 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> &EH, ArrayRef<RelTy> Rels, 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 isReserved(InputSectionBase *Sec) { // 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); }; diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index c563e935896..10aeca5a5bb 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -86,14 +86,13 @@ OutputSection<ELFT>::OutputSection(StringRef Name, uint32_t Type, uintX_t Flags) } 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<ELFT>::finalize() { 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(InputSectionBase *C) { 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>::forEachInputSection( // 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<ELFT>::assignOffsets() { 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) { return isCrtBeginEnd(S, "crtend"); } // 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<ELFT>::writeTo(uint8_t *Buf) { 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 diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h index a3064418ecb..f1f45dda58e 100644 --- a/lld/ELF/OutputSections.h +++ b/lld/ELF/OutputSections.h @@ -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; diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 871b1b0d37f..74d6d96dcf8 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -875,9 +875,9 @@ static void mergeThunks(OutputSection<ELFT> *OS, 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<OutputSectionBase *> OutputSections) { // 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<OutputSectionBase *> OutputSections) { }; // 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<OutputSectionBase *> OutputSections) { 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>(), diff --git a/lld/ELF/Relocations.h b/lld/ELF/Relocations.h index f531b99f1b9..f07f74efb05 100644 --- a/lld/ELF/Relocations.h +++ b/lld/ELF/Relocations.h @@ -16,7 +16,7 @@ namespace lld { namespace elf { class SymbolBody; class InputSectionData; -template <class ELFT> class InputSection; +class InputSection; class InputSectionBase; class OutputSectionBase; diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp index 4285211f92e..bbfcb2ec69c 100644 --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -50,7 +50,7 @@ static typename ELFT::uint getSymVA(const SymbolBody &Body, int64_t &Addend) { // 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. diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h index 0342f90b75b..ab19aa43d17 100644 --- a/lld/ELF/Symbols.h +++ b/lld/ELF/Symbols.h @@ -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 diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index e5a2df0ddd1..0398249016e 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -54,9 +54,9 @@ template <class ELFT> static std::vector<DefinedCommon *> getCommonSymbols() { } // 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> *MipsReginfoSection<ELFT>::create() { 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<ELFT>::writeTo(uint8_t *Buf) { } 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 *elf::createCommonSection<ELF32LE>(); +template InputSection *elf::createCommonSection<ELF32BE>(); +template InputSection *elf::createCommonSection<ELF64LE>(); +template InputSection *elf::createCommonSection<ELF64BE>(); -template InputSection<ELF32LE> *elf::createInterpSection(); -template InputSection<ELF32BE> *elf::createInterpSection(); -template InputSection<ELF64LE> *elf::createInterpSection(); -template InputSection<ELF64BE> *elf::createInterpSection(); +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(); diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index 3812636ac04..43f3ee96dbb 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -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 SyntheticSection<ELFT> { 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 Name, uint8_t Type, uint64_t Value, // 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<ELFT> *In<ELFT>::MipsGot; 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; diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index a05ff79a6d9..3cace69e7fb 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -61,7 +61,7 @@ static void or32be(uint8_t *P, int32_t V) { write32be(P, read32be(P) | 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_t *Buf) const { } 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 *Buf, uint64_t GotEntryAddr, } 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); } diff --git a/lld/ELF/Thunks.cpp b/lld/ELF/Thunks.cpp index 651e11b4172..099ac2c1fc3 100644 --- a/lld/ELF/Thunks.cpp +++ b/lld/ELF/Thunks.cpp @@ -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<ELFT>::addSymbols(ThunkSection<ELFT> &IS) { } 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> diff --git a/lld/ELF/Thunks.h b/lld/ELF/Thunks.h index b49f5ae393a..78b4bba8638 100644 --- a/lld/ELF/Thunks.h +++ b/lld/ELF/Thunks.h @@ -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. diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index d7278cd6110..35d9759565a 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -348,7 +348,7 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() { 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(InputSectionBase *Sec, StringRef SymName, 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>::addSectionSymbols() { 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::function<void(InputSectionBase &)> Fn) { // 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); } } |

