[lld] r297077 - Detemplate EhInputSection. NFC.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 6 13:17:18 PST 2017


Author: rafael
Date: Mon Mar  6 15:17:18 2017
New Revision: 297077

URL: http://llvm.org/viewvc/llvm-project?rev=297077&view=rev
Log:
Detemplate EhInputSection. NFC.

Modified:
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/InputSection.h
    lld/trunk/ELF/MarkLive.cpp
    lld/trunk/ELF/OutputSections.h
    lld/trunk/ELF/Relocations.cpp
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/ELF/SyntheticSections.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=297077&r1=297076&r2=297077&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Mon Mar  6 15:17:18 2017
@@ -455,7 +455,7 @@ elf::ObjectFile<ELFT>::createInputSectio
   // .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<EhInputSection<ELFT>>(this, &Sec, Name);
+    return make<EhInputSection>(this, &Sec, Name);
 
   if (shouldMerge(Sec))
     return make<MergeInputSection>(this, &Sec, Name);

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=297077&r1=297076&r2=297077&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Mon Mar  6 15:17:18 2017
@@ -123,7 +123,7 @@ template <class ELFT>
 OutputSection *InputSectionBase::getOutputSection() const {
   if (auto *MS = dyn_cast<MergeInputSection>(this))
     return MS->MergeSec ? MS->MergeSec->OutSec : nullptr;
-  if (auto *EH = dyn_cast<EhInputSection<ELFT>>(this))
+  if (auto *EH = dyn_cast<EhInputSection>(this))
     return EH->EHSec->OutSec;
   return OutSec;
 }
@@ -579,8 +579,9 @@ void InputSection::replace(InputSection
 }
 
 template <class ELFT>
-EhInputSection<ELFT>::EhInputSection(elf::ObjectFile<ELFT> *F,
-                                     const Elf_Shdr *Header, StringRef Name)
+EhInputSection::EhInputSection(elf::ObjectFile<ELFT> *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<ELFT>::EhInputSection(elf
   this->Live = true;
 }
 
-template <class ELFT>
-bool EhInputSection<ELFT>::classof(const InputSectionBase *S) {
+bool EhInputSection::classof(const InputSectionBase *S) {
   return S->kind() == InputSectionBase::EHFrame;
 }
 
@@ -614,24 +614,23 @@ static unsigned getReloc(IntTy Begin, In
 
 // .eh_frame is a sequence of CIE or FDE records.
 // This function splits an input section into records and returns them.
-template <class ELFT> void EhInputSection<ELFT>::split() {
+template <class ELFT> void EhInputSection::split() {
   // Early exit if already split.
   if (!this->Pieces.empty())
     return;
 
   if (this->NumRelocations) {
     if (this->AreRelocsRela)
-      split(this->relas<ELFT>());
+      split<ELFT>(this->relas<ELFT>());
     else
-      split(this->rels<ELFT>());
+      split<ELFT>(this->rels<ELFT>());
     return;
   }
-  split(makeArrayRef<typename ELFT::Rela>(nullptr, nullptr));
+  split<ELFT>(makeArrayRef<typename ELFT::Rela>(nullptr, nullptr));
 }
 
-template <class ELFT>
-template <class RelTy>
-void EhInputSection<ELFT>::split(ArrayRef<RelTy> Rels) {
+template <class ELFT, class RelTy>
+void EhInputSection::split(ArrayRef<RelTy> Rels) {
   ArrayRef<uint8_t> Data = this->Data;
   unsigned RelI = 0;
   for (size_t Off = 0, End = Data.size(); Off != End;) {
@@ -801,11 +800,6 @@ template void InputSection::writeTo<ELF3
 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>;
-template class elf::EhInputSection<ELF64LE>;
-template class elf::EhInputSection<ELF64BE>;
-
 template void InputSectionBase::uncompress<ELF32LE>();
 template void InputSectionBase::uncompress<ELF32BE>();
 template void InputSectionBase::uncompress<ELF64LE>();
@@ -862,3 +856,21 @@ template MergeInputSection::MergeInputSe
 template MergeInputSection::MergeInputSection(elf::ObjectFile<ELF64BE> *F,
                                               const ELF64BE::Shdr *Header,
                                               StringRef Name);
+
+template EhInputSection::EhInputSection(elf::ObjectFile<ELF32LE> *F,
+                                        const ELF32LE::Shdr *Header,
+                                        StringRef Name);
+template EhInputSection::EhInputSection(elf::ObjectFile<ELF32BE> *F,
+                                        const ELF32BE::Shdr *Header,
+                                        StringRef Name);
+template EhInputSection::EhInputSection(elf::ObjectFile<ELF64LE> *F,
+                                        const ELF64LE::Shdr *Header,
+                                        StringRef Name);
+template EhInputSection::EhInputSection(elf::ObjectFile<ELF64BE> *F,
+                                        const ELF64BE::Shdr *Header,
+                                        StringRef Name);
+
+template void EhInputSection::split<ELF32LE>();
+template void EhInputSection::split<ELF32BE>();
+template void EhInputSection::split<ELF64LE>();
+template void EhInputSection::split<ELF64BE>();

Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=297077&r1=297076&r2=297077&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Mon Mar  6 15:17:18 2017
@@ -28,6 +28,7 @@ class SymbolBody;
 struct SectionPiece;
 
 class DefinedRegular;
+class SyntheticSection;
 template <class ELFT> class EhFrameSection;
 class MergeSyntheticSection;
 template <class ELFT> class ObjectFile;
@@ -228,19 +229,19 @@ struct EhSectionPiece : public SectionPi
 };
 
 // This corresponds to a .eh_frame section of an input file.
-template <class ELFT> class EhInputSection : public InputSectionBase {
+class EhInputSection : public InputSectionBase {
 public:
-  typedef typename ELFT::Shdr Elf_Shdr;
-  typedef typename ELFT::uint uintX_t;
-  EhInputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Header, StringRef Name);
+  template <class ELFT>
+  EhInputSection(ObjectFile<ELFT> *F, const typename ELFT::Shdr *Header,
+                 StringRef Name);
   static bool classof(const InputSectionBase *S);
-  void split();
-  template <class RelTy> void split(ArrayRef<RelTy> Rels);
+  template <class ELFT> void split();
+  template <class ELFT, class RelTy> void split(ArrayRef<RelTy> Rels);
 
   // Splittable sections are handled as a sequence of data
   // rather than a single large blob of data.
   std::vector<EhSectionPiece> Pieces;
-  EhFrameSection<ELFT> *EHSec = nullptr;
+  SyntheticSection *EHSec = nullptr;
 };
 
 // This is a section that is added directly to an output section

Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=297077&r1=297076&r2=297077&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Mon Mar  6 15:17:18 2017
@@ -115,7 +115,7 @@ static void forEachSuccessor(InputSectio
 // 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 <class ELFT, class RelTy>
-static void scanEhFrameSection(EhInputSection<ELFT> &EH, ArrayRef<RelTy> Rels,
+static void scanEhFrameSection(EhInputSection &EH, ArrayRef<RelTy> Rels,
                                std::function<void(ResolvedReloc)> Enqueue) {
   const endianness E = ELFT::TargetEndianness;
   for (unsigned I = 0, N = EH.Pieces.size(); I < N; ++I) {
@@ -149,19 +149,19 @@ static void scanEhFrameSection(EhInputSe
 }
 
 template <class ELFT>
-static void scanEhFrameSection(EhInputSection<ELFT> &EH,
+static void scanEhFrameSection(EhInputSection &EH,
                                std::function<void(ResolvedReloc)> 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<ELFT>();
 
   if (EH.AreRelocsRela)
-    scanEhFrameSection(EH, EH.template relas<ELFT>(), Enqueue);
+    scanEhFrameSection<ELFT>(EH, EH.template relas<ELFT>(), Enqueue);
   else
-    scanEhFrameSection(EH, EH.template rels<ELFT>(), Enqueue);
+    scanEhFrameSection<ELFT>(EH, EH.template rels<ELFT>(), Enqueue);
 }
 
 // We do not garbage-collect two types of sections:
@@ -245,7 +245,7 @@ template <class ELFT> 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<EhInputSection<ELFT>>(Sec))
+    if (auto *EH = dyn_cast_or_null<EhInputSection>(Sec))
       scanEhFrameSection<ELFT>(*EH, Enqueue);
     if (isReserved<ELFT>(Sec) || Script<ELFT>::X->shouldKeep(Sec))
       Enqueue({Sec, 0});

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=297077&r1=297076&r2=297077&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Mon Mar  6 15:17:18 2017
@@ -23,7 +23,7 @@ namespace elf {
 struct PhdrEntry;
 class SymbolBody;
 struct EhSectionPiece;
-template <class ELFT> class EhInputSection;
+class EhInputSection;
 class InputSection;
 class InputSectionBase;
 class MergeInputSection;

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=297077&r1=297076&r2=297077&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Mon Mar  6 15:17:18 2017
@@ -659,7 +659,7 @@ static void scanRelocs(InputSectionBase
   const uint8_t *Buf = SectionData.begin();
 
   ArrayRef<EhSectionPiece> Pieces;
-  if (auto *Eh = dyn_cast<EhInputSection<ELFT>>(&C))
+  if (auto *Eh = dyn_cast<EhInputSection>(&C))
     Pieces = Eh->Pieces;
 
   ArrayRef<EhSectionPiece>::iterator PieceI = Pieces.begin();

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=297077&r1=297076&r2=297077&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Mon Mar  6 15:17:18 2017
@@ -430,7 +430,7 @@ template <class ELFT>
 template <class RelTy>
 CieRecord *EhFrameSection<ELFT>::addCie(EhSectionPiece &Piece,
                                         ArrayRef<RelTy> Rels) {
-  auto *Sec = cast<EhInputSection<ELFT>>(Piece.ID);
+  auto *Sec = cast<EhInputSection>(Piece.ID);
   const endianness E = ELFT::TargetEndianness;
   if (read32<E>(Piece.data().data() + 4) != 0)
     fatal(toString(Sec) + ": CIE expected at beginning of .eh_frame");
@@ -458,7 +458,7 @@ template <class ELFT>
 template <class RelTy>
 bool EhFrameSection<ELFT>::isFdeLive(EhSectionPiece &Piece,
                                      ArrayRef<RelTy> Rels) {
-  auto *Sec = cast<EhInputSection<ELFT>>(Piece.ID);
+  auto *Sec = cast<EhInputSection>(Piece.ID);
   unsigned FirstRelI = Piece.FirstRelocation;
   if (FirstRelI == (unsigned)-1)
     return false;
@@ -477,7 +477,7 @@ bool EhFrameSection<ELFT>::isFdeLive(EhS
 // one and associates FDEs to the CIE.
 template <class ELFT>
 template <class RelTy>
-void EhFrameSection<ELFT>::addSectionAux(EhInputSection<ELFT> *Sec,
+void EhFrameSection<ELFT>::addSectionAux(EhInputSection *Sec,
                                          ArrayRef<RelTy> Rels) {
   const endianness E = ELFT::TargetEndianness;
 
@@ -508,7 +508,7 @@ void EhFrameSection<ELFT>::addSectionAux
 
 template <class ELFT>
 void EhFrameSection<ELFT>::addSection(InputSectionBase *C) {
-  auto *Sec = cast<EhInputSection<ELFT>>(C);
+  auto *Sec = cast<EhInputSection>(C);
   Sec->EHSec = this;
   updateAlignment(Sec->Alignment);
   Sections.push_back(Sec);
@@ -516,7 +516,7 @@ void EhFrameSection<ELFT>::addSection(In
   // .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<ELFT>();
   if (Sec->Pieces.empty())
     return;
 
@@ -605,7 +605,7 @@ template <class ELFT> void EhFrameSectio
     }
   }
 
-  for (EhInputSection<ELFT> *S : Sections)
+  for (EhInputSection *S : Sections)
     S->template relocate<ELFT>(Buf, nullptr);
 
   // Construct .eh_frame_hdr. .eh_frame_hdr is a binary search table

Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=297077&r1=297076&r2=297077&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Mon Mar  6 15:17:18 2017
@@ -82,7 +82,7 @@ public:
 private:
   uint64_t Size = 0;
   template <class RelTy>
-  void addSectionAux(EhInputSection<ELFT> *S, llvm::ArrayRef<RelTy> Rels);
+  void addSectionAux(EhInputSection *S, llvm::ArrayRef<RelTy> Rels);
 
   template <class RelTy>
   CieRecord *addCie(EhSectionPiece &Piece, ArrayRef<RelTy> Rels);
@@ -92,7 +92,7 @@ private:
 
   uintX_t getFdePc(uint8_t *Buf, size_t Off, uint8_t Enc);
 
-  std::vector<EhInputSection<ELFT> *> Sections;
+  std::vector<EhInputSection *> Sections;
   std::vector<CieRecord *> Cies;
 
   // CIE records are uniquified by their contents and personality functions.

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=297077&r1=297076&r2=297077&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Mar  6 15:17:18 2017
@@ -910,7 +910,7 @@ void Writer<ELFT>::forEachRelSec(std::fu
     // processed by InputSection::relocateNonAlloc.
     if (!(IS->Flags & SHF_ALLOC))
       continue;
-    if (isa<InputSection>(IS) || isa<EhInputSection<ELFT>>(IS))
+    if (isa<InputSection>(IS) || isa<EhInputSection>(IS))
       Fn(*IS);
   }
 }




More information about the llvm-commits mailing list