From 5c02b741eb56108b4fc93a8abbfd71f211f7b18f Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 6 Mar 2017 21:17:18 +0000 Subject: [PATCH] Detemplate EhInputSection. NFC. llvm-svn: 297077 --- lld/ELF/InputFiles.cpp | 2 +- lld/ELF/InputSection.cpp | 46 ++++++++++++++++++++++------------- lld/ELF/InputSection.h | 15 ++++++------ lld/ELF/MarkLive.cpp | 12 ++++----- lld/ELF/OutputSections.h | 2 +- lld/ELF/Relocations.cpp | 2 +- lld/ELF/SyntheticSections.cpp | 12 ++++----- lld/ELF/SyntheticSections.h | 4 +-- lld/ELF/Writer.cpp | 2 +- 9 files changed, 55 insertions(+), 42 deletions(-) diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index c6687bc463cb..30ebe925dbe0 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -455,7 +455,7 @@ elf::ObjectFile::createInputSection(const Elf_Shdr &Sec, // .eh_frame_hdr section for runtime. So we handle them with a special // class. For relocatable outputs, they are just passed through. if (Name == ".eh_frame" && !Config->Relocatable) - return make>(this, &Sec, Name); + return make(this, &Sec, Name); if (shouldMerge(Sec)) return make(this, &Sec, Name); diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index c9e005952be2..b21af523096b 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -123,7 +123,7 @@ template OutputSection *InputSectionBase::getOutputSection() const { if (auto *MS = dyn_cast(this)) return MS->MergeSec ? MS->MergeSec->OutSec : nullptr; - if (auto *EH = dyn_cast>(this)) + if (auto *EH = dyn_cast(this)) return EH->EHSec->OutSec; return OutSec; } @@ -579,8 +579,9 @@ void InputSection::replace(InputSection *Other) { } template -EhInputSection::EhInputSection(elf::ObjectFile *F, - const Elf_Shdr *Header, StringRef Name) +EhInputSection::EhInputSection(elf::ObjectFile *F, + const typename ELFT::Shdr *Header, + StringRef Name) : InputSectionBase(F, Header, Name, InputSectionBase::EHFrame) { // Mark .eh_frame sections as live by default because there are // usually no relocations that point to .eh_frames. Otherwise, @@ -588,8 +589,7 @@ EhInputSection::EhInputSection(elf::ObjectFile *F, this->Live = true; } -template -bool EhInputSection::classof(const InputSectionBase *S) { +bool EhInputSection::classof(const InputSectionBase *S) { return S->kind() == InputSectionBase::EHFrame; } @@ -614,24 +614,23 @@ static unsigned getReloc(IntTy Begin, IntTy Size, const ArrayRef &Rels, // .eh_frame is a sequence of CIE or FDE records. // This function splits an input section into records and returns them. -template void EhInputSection::split() { +template void EhInputSection::split() { // Early exit if already split. if (!this->Pieces.empty()) return; if (this->NumRelocations) { if (this->AreRelocsRela) - split(this->relas()); + split(this->relas()); else - split(this->rels()); + split(this->rels()); return; } - split(makeArrayRef(nullptr, nullptr)); + split(makeArrayRef(nullptr, nullptr)); } -template -template -void EhInputSection::split(ArrayRef Rels) { +template +void EhInputSection::split(ArrayRef Rels) { ArrayRef Data = this->Data; unsigned RelI = 0; for (size_t Off = 0, End = Data.size(); Off != End;) { @@ -801,11 +800,6 @@ template void InputSection::writeTo(uint8_t *Buf); template void InputSection::writeTo(uint8_t *Buf); template void InputSection::writeTo(uint8_t *Buf); -template class elf::EhInputSection; -template class elf::EhInputSection; -template class elf::EhInputSection; -template class elf::EhInputSection; - template void InputSectionBase::uncompress(); template void InputSectionBase::uncompress(); template void InputSectionBase::uncompress(); @@ -862,3 +856,21 @@ template MergeInputSection::MergeInputSection(elf::ObjectFile *F, template MergeInputSection::MergeInputSection(elf::ObjectFile *F, const ELF64BE::Shdr *Header, StringRef Name); + +template EhInputSection::EhInputSection(elf::ObjectFile *F, + const ELF32LE::Shdr *Header, + StringRef Name); +template EhInputSection::EhInputSection(elf::ObjectFile *F, + const ELF32BE::Shdr *Header, + StringRef Name); +template EhInputSection::EhInputSection(elf::ObjectFile *F, + const ELF64LE::Shdr *Header, + StringRef Name); +template EhInputSection::EhInputSection(elf::ObjectFile *F, + const ELF64BE::Shdr *Header, + StringRef Name); + +template void EhInputSection::split(); +template void EhInputSection::split(); +template void EhInputSection::split(); +template void EhInputSection::split(); diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index 85df159af443..4f6a908c9f3b 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -28,6 +28,7 @@ class SymbolBody; struct SectionPiece; class DefinedRegular; +class SyntheticSection; template class EhFrameSection; class MergeSyntheticSection; template class ObjectFile; @@ -228,19 +229,19 @@ struct EhSectionPiece : public SectionPiece { }; // This corresponds to a .eh_frame section of an input file. -template class EhInputSection : public InputSectionBase { +class EhInputSection : public InputSectionBase { public: - typedef typename ELFT::Shdr Elf_Shdr; - typedef typename ELFT::uint uintX_t; - EhInputSection(ObjectFile *F, const Elf_Shdr *Header, StringRef Name); + template + EhInputSection(ObjectFile *F, const typename ELFT::Shdr *Header, + StringRef Name); static bool classof(const InputSectionBase *S); - void split(); - template void split(ArrayRef Rels); + template void split(); + template void split(ArrayRef Rels); // Splittable sections are handled as a sequence of data // rather than a single large blob of data. std::vector Pieces; - EhFrameSection *EHSec = nullptr; + SyntheticSection *EHSec = nullptr; }; // This is a section that is added directly to an output section diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index 0b05f5910760..f2d5f24ccb7d 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -115,7 +115,7 @@ static void forEachSuccessor(InputSection &Sec, // the gc pass. With that we would be able to also gc some sections holding // LSDAs and personality functions if we found that they were unused. template -static void scanEhFrameSection(EhInputSection &EH, ArrayRef Rels, +static void scanEhFrameSection(EhInputSection &EH, ArrayRef Rels, std::function Enqueue) { const endianness E = ELFT::TargetEndianness; for (unsigned I = 0, N = EH.Pieces.size(); I < N; ++I) { @@ -149,19 +149,19 @@ static void scanEhFrameSection(EhInputSection &EH, ArrayRef Rels, } template -static void scanEhFrameSection(EhInputSection &EH, +static void scanEhFrameSection(EhInputSection &EH, std::function Enqueue) { if (!EH.NumRelocations) return; // Unfortunately we need to split .eh_frame early since some relocations in // .eh_frame keep other section alive and some don't. - EH.split(); + EH.split(); if (EH.AreRelocsRela) - scanEhFrameSection(EH, EH.template relas(), Enqueue); + scanEhFrameSection(EH, EH.template relas(), Enqueue); else - scanEhFrameSection(EH, EH.template rels(), Enqueue); + scanEhFrameSection(EH, EH.template rels(), Enqueue); } // We do not garbage-collect two types of sections: @@ -245,7 +245,7 @@ template void elf::markLive() { // .eh_frame is always marked as live now, but also it can reference to // sections that contain personality. We preserve all non-text sections // referred by .eh_frame here. - if (auto *EH = dyn_cast_or_null>(Sec)) + if (auto *EH = dyn_cast_or_null(Sec)) scanEhFrameSection(*EH, Enqueue); if (isReserved(Sec) || Script::X->shouldKeep(Sec)) Enqueue({Sec, 0}); diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h index d831741d7e26..b35476cc6dbb 100644 --- a/lld/ELF/OutputSections.h +++ b/lld/ELF/OutputSections.h @@ -23,7 +23,7 @@ namespace elf { struct PhdrEntry; class SymbolBody; struct EhSectionPiece; -template class EhInputSection; +class EhInputSection; class InputSection; class InputSectionBase; class MergeInputSection; diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index ec0f81525f2d..a30b24a530ae 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -659,7 +659,7 @@ static void scanRelocs(InputSectionBase &C, ArrayRef Rels) { const uint8_t *Buf = SectionData.begin(); ArrayRef Pieces; - if (auto *Eh = dyn_cast>(&C)) + if (auto *Eh = dyn_cast(&C)) Pieces = Eh->Pieces; ArrayRef::iterator PieceI = Pieces.begin(); diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 5229a6eb28f8..35b809d23ffd 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -430,7 +430,7 @@ template template CieRecord *EhFrameSection::addCie(EhSectionPiece &Piece, ArrayRef Rels) { - auto *Sec = cast>(Piece.ID); + auto *Sec = cast(Piece.ID); const endianness E = ELFT::TargetEndianness; if (read32(Piece.data().data() + 4) != 0) fatal(toString(Sec) + ": CIE expected at beginning of .eh_frame"); @@ -458,7 +458,7 @@ template template bool EhFrameSection::isFdeLive(EhSectionPiece &Piece, ArrayRef Rels) { - auto *Sec = cast>(Piece.ID); + auto *Sec = cast(Piece.ID); unsigned FirstRelI = Piece.FirstRelocation; if (FirstRelI == (unsigned)-1) return false; @@ -477,7 +477,7 @@ bool EhFrameSection::isFdeLive(EhSectionPiece &Piece, // one and associates FDEs to the CIE. template template -void EhFrameSection::addSectionAux(EhInputSection *Sec, +void EhFrameSection::addSectionAux(EhInputSection *Sec, ArrayRef Rels) { const endianness E = ELFT::TargetEndianness; @@ -508,7 +508,7 @@ void EhFrameSection::addSectionAux(EhInputSection *Sec, template void EhFrameSection::addSection(InputSectionBase *C) { - auto *Sec = cast>(C); + auto *Sec = cast(C); Sec->EHSec = this; updateAlignment(Sec->Alignment); Sections.push_back(Sec); @@ -516,7 +516,7 @@ void EhFrameSection::addSection(InputSectionBase *C) { // .eh_frame is a sequence of CIE or FDE records. This function // splits it into pieces so that we can call // SplitInputSection::getSectionPiece on the section. - Sec->split(); + Sec->split(); if (Sec->Pieces.empty()) return; @@ -605,7 +605,7 @@ template void EhFrameSection::writeTo(uint8_t *Buf) { } } - for (EhInputSection *S : Sections) + for (EhInputSection *S : Sections) S->template relocate(Buf, nullptr); // Construct .eh_frame_hdr. .eh_frame_hdr is a binary search table diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index d85a39559099..f5d6078f4487 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -82,7 +82,7 @@ public: private: uint64_t Size = 0; template - void addSectionAux(EhInputSection *S, llvm::ArrayRef Rels); + void addSectionAux(EhInputSection *S, llvm::ArrayRef Rels); template CieRecord *addCie(EhSectionPiece &Piece, ArrayRef Rels); @@ -92,7 +92,7 @@ private: uintX_t getFdePc(uint8_t *Buf, size_t Off, uint8_t Enc); - std::vector *> Sections; + std::vector Sections; std::vector Cies; // CIE records are uniquified by their contents and personality functions. diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 4ef5a122751a..b210083d3c9b 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -910,7 +910,7 @@ void Writer::forEachRelSec(std::function Fn) { // processed by InputSection::relocateNonAlloc. if (!(IS->Flags & SHF_ALLOC)) continue; - if (isa(IS) || isa>(IS)) + if (isa(IS) || isa(IS)) Fn(*IS); } }