[lld] r298345 - [ELF] - Detemplate GdbIndexSection.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 21 01:19:35 PDT 2017


Author: grimar
Date: Tue Mar 21 03:19:34 2017
New Revision: 298345

URL: http://llvm.org/viewvc/llvm-project?rev=298345&view=rev
Log:
[ELF] - Detemplate GdbIndexSection.

Patch moves Sections array to
InputFile (root class for input files).

That allows to detemplate GdbIndexSection.

Differential revision: https://reviews.llvm.org/D30976

Modified:
    lld/trunk/ELF/InputFiles.h
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/ELF/SyntheticSections.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=298345&r1=298344&r2=298345&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Tue Mar 21 03:19:34 2017
@@ -74,6 +74,13 @@ public:
   StringRef getName() const { return MB.getBufferIdentifier(); }
   MemoryBufferRef MB;
 
+  // If it is a file that can have sections, like object file or binary file,
+  // then method returns them.
+  ArrayRef<InputSectionBase *> getSections() const {
+    assert(FileKind == ObjectKind || FileKind == BinaryKind);
+    return Sections;
+  }
+
   // Filename of .a which contained this file. If this file was
   // not in an archive file, it is the empty string. We use this
   // string for creating error messages.
@@ -88,6 +95,8 @@ public:
 protected:
   InputFile(Kind K, MemoryBufferRef M) : MB(M), FileKind(K) {}
 
+  std::vector<InputSectionBase *> Sections;
+
 private:
   const Kind FileKind;
 };
@@ -190,9 +199,6 @@ private:
   bool shouldMerge(const Elf_Shdr &Sec);
   SymbolBody *createSymbolBody(const Elf_Sym *Sym);
 
-  // List of all sections defined by this file.
-  std::vector<InputSectionBase *> Sections;
-
   // List of all symbols referenced or defined by this file.
   std::vector<SymbolBody *> SymbolBodies;
 
@@ -320,10 +326,6 @@ public:
   explicit BinaryFile(MemoryBufferRef M) : InputFile(BinaryKind, M) {}
   static bool classof(const InputFile *F) { return F->kind() == BinaryKind; }
   template <class ELFT> void parse();
-  ArrayRef<InputSectionBase *> getSections() const { return Sections; }
-
-private:
-  std::vector<InputSectionBase *> Sections;
 };
 
 InputFile *createObjectFile(MemoryBufferRef MB, StringRef ArchiveName = "",

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=298345&r1=298344&r2=298345&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Tue Mar 21 03:19:34 2017
@@ -1674,8 +1674,7 @@ unsigned PltSection::getPltRelocOff() co
   return (HeaderSize == 0) ? InX::Plt->getSize() : 0;
 }
 
-template <class ELFT>
-GdbIndexSection<ELFT>::GdbIndexSection()
+GdbIndexSection::GdbIndexSection()
     : SyntheticSection(0, SHT_PROGBITS, 1, ".gdb_index"),
       StringPool(llvm::StringTableBuilder::ELF) {}
 
@@ -1707,7 +1706,6 @@ static InputSectionBase *findSection(Arr
   return nullptr;
 }
 
-template <class ELFT>
 static std::vector<AddressEntry>
 readAddressArea(DWARFContext &Dwarf, InputSection *Sec, size_t CurrentCU) {
   std::vector<AddressEntry> Ret;
@@ -1716,9 +1714,7 @@ readAddressArea(DWARFContext &Dwarf, Inp
     DWARFAddressRangesVector Ranges;
     CU->collectAddressRanges(Ranges);
 
-    ArrayRef<InputSectionBase *> Sections =
-        Sec->template getFile<ELFT>()->getSections();
-
+    ArrayRef<InputSectionBase *> Sections = Sec->File->getSections();
     for (std::pair<uint64_t, uint64_t> &R : Ranges)
       if (InputSectionBase *S = findSection(Sections, R.first))
         Ret.push_back({S, R.first - S->getOffsetInFile(),
@@ -1754,7 +1750,7 @@ class ObjInfoTy : public llvm::LoadedObj
   std::unique_ptr<llvm::LoadedObjectInfo> clone() const override { return {}; }
 };
 
-template <class ELFT> void GdbIndexSection<ELFT>::readDwarf(InputSection *Sec) {
+void GdbIndexSection::readDwarf(InputSection *Sec) {
   Expected<std::unique_ptr<object::ObjectFile>> Obj =
       object::ObjectFile::createObjectFile(Sec->File->MB);
   if (!Obj) {
@@ -1769,11 +1765,11 @@ template <class ELFT> void GdbIndexSecti
   for (std::pair<uint64_t, uint64_t> &P : readCuList(Dwarf, Sec))
     CompilationUnits.push_back(P);
 
-  for (AddressEntry &Ent : readAddressArea<ELFT>(Dwarf, Sec, CuId))
+  for (AddressEntry &Ent : readAddressArea(Dwarf, Sec, CuId))
     AddressArea.push_back(Ent);
 
   std::vector<std::pair<StringRef, uint8_t>> NamesAndTypes =
-      readPubNamesAndTypes(Dwarf, ELFT::TargetEndianness == support::little);
+      readPubNamesAndTypes(Dwarf, Config->IsLE);
 
   for (std::pair<StringRef, uint8_t> &Pair : NamesAndTypes) {
     uint32_t Hash = hash(Pair.first);
@@ -1792,7 +1788,7 @@ template <class ELFT> void GdbIndexSecti
   }
 }
 
-template <class ELFT> void GdbIndexSection<ELFT>::finalizeContents() {
+void GdbIndexSection::finalizeContents() {
   if (Finalized)
     return;
   Finalized = true;
@@ -1821,12 +1817,12 @@ template <class ELFT> void GdbIndexSecti
   StringPool.finalizeInOrder();
 }
 
-template <class ELFT> size_t GdbIndexSection<ELFT>::getSize() const {
-  const_cast<GdbIndexSection<ELFT> *>(this)->finalizeContents();
+size_t GdbIndexSection::getSize() const {
+  const_cast<GdbIndexSection *>(this)->finalizeContents();
   return StringPoolOffset + StringPool.getSize();
 }
 
-template <class ELFT> void GdbIndexSection<ELFT>::writeTo(uint8_t *Buf) {
+void GdbIndexSection::writeTo(uint8_t *Buf) {
   write32le(Buf, 7);                       // Write version.
   write32le(Buf + 4, CuListOffset);        // CU list offset.
   write32le(Buf + 8, CuTypesOffset);       // Types CU list offset.
@@ -1880,7 +1876,7 @@ template <class ELFT> void GdbIndexSecti
   StringPool.write(Buf);
 }
 
-template <class ELFT> bool GdbIndexSection<ELFT>::empty() const {
+bool GdbIndexSection::empty() const {
   return !Out::DebugInfo;
 }
 
@@ -2239,6 +2235,7 @@ BuildIdSection *InX::BuildId;
 InputSection *InX::Common;
 StringTableSection *InX::DynStrTab;
 InputSection *InX::Interp;
+GdbIndexSection *InX::GdbIndex;
 GotPltSection *InX::GotPlt;
 IgotPltSection *InX::IgotPlt;
 MipsGotSection *InX::MipsGot;
@@ -2321,11 +2318,6 @@ template class elf::HashTableSection<ELF
 template class elf::HashTableSection<ELF64LE>;
 template class elf::HashTableSection<ELF64BE>;
 
-template class elf::GdbIndexSection<ELF32LE>;
-template class elf::GdbIndexSection<ELF32BE>;
-template class elf::GdbIndexSection<ELF64LE>;
-template class elf::GdbIndexSection<ELF64BE>;
-
 template class elf::EhFrameHeader<ELF32LE>;
 template class elf::EhFrameHeader<ELF32BE>;
 template class elf::EhFrameHeader<ELF64LE>;

Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=298345&r1=298344&r2=298345&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Tue Mar 21 03:19:34 2017
@@ -497,7 +497,7 @@ private:
   size_t HeaderSize;
 };
 
-template <class ELFT> class GdbIndexSection final : public SyntheticSection {
+class GdbIndexSection final : public SyntheticSection {
   const unsigned OffsetTypeSize = 4;
   const unsigned CuListOffset = 6 * OffsetTypeSize;
   const unsigned CompilationUnitSize = 16;
@@ -762,6 +762,7 @@ struct InX {
   static InputSection *Common;
   static StringTableSection *DynStrTab;
   static InputSection *Interp;
+  static GdbIndexSection *GdbIndex;
   static GotPltSection *GotPlt;
   static IgotPltSection *IgotPlt;
   static MipsGotSection *MipsGot;
@@ -777,7 +778,6 @@ template <class ELFT> struct In : public
   static SymbolTableSection<ELFT> *DynSymTab;
   static EhFrameHeader<ELFT> *EhFrameHdr;
   static GnuHashTableSection<ELFT> *GnuHashTab;
-  static GdbIndexSection<ELFT> *GdbIndex;
   static GotSection<ELFT> *Got;
   static EhFrameSection<ELFT> *EhFrame;
   static HashTableSection<ELFT> *HashTab;
@@ -793,7 +793,6 @@ template <class ELFT> struct In : public
 template <class ELFT> DynamicSection<ELFT> *In<ELFT>::Dynamic;
 template <class ELFT> SymbolTableSection<ELFT> *In<ELFT>::DynSymTab;
 template <class ELFT> EhFrameHeader<ELFT> *In<ELFT>::EhFrameHdr;
-template <class ELFT> GdbIndexSection<ELFT> *In<ELFT>::GdbIndex;
 template <class ELFT> GnuHashTableSection<ELFT> *In<ELFT>::GnuHashTab;
 template <class ELFT> GotSection<ELFT> *In<ELFT>::Got;
 template <class ELFT> EhFrameSection<ELFT> *In<ELFT>::EhFrame;

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=298345&r1=298344&r2=298345&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Mar 21 03:19:34 2017
@@ -428,7 +428,7 @@ template <class ELFT> void Writer<ELFT>:
   Add(In<ELFT>::IgotPlt);
 
   if (Config->GdbIndex) {
-    In<ELFT>::GdbIndex = make<GdbIndexSection<ELFT>>();
+    In<ELFT>::GdbIndex = make<GdbIndexSection>();
     Add(In<ELFT>::GdbIndex);
   }
 




More information about the llvm-commits mailing list