[lld] r310049 - [ELF] - Move getSymbols() methods to InputFile.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 4 04:07:42 PDT 2017


Author: grimar
Date: Fri Aug  4 04:07:42 2017
New Revision: 310049

URL: http://llvm.org/viewvc/llvm-project?rev=310049&view=rev
Log:
[ELF] - Move getSymbols() methods to InputFile.

It can help to detemplate code.

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

Modified:
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/InputFiles.h
    lld/trunk/ELF/OutputSections.cpp

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=310049&r1=310048&r2=310049&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Fri Aug  4 04:07:42 2017
@@ -162,15 +162,9 @@ ObjFile<ELFT>::ObjFile(MemoryBufferRef M
 }
 
 template <class ELFT> ArrayRef<SymbolBody *> ObjFile<ELFT>::getLocalSymbols() {
-  if (this->SymbolBodies.empty())
-    return this->SymbolBodies;
-  return makeArrayRef(this->SymbolBodies).slice(1, this->FirstNonLocal - 1);
-}
-
-template <class ELFT> ArrayRef<SymbolBody *> ObjFile<ELFT>::getSymbols() {
-  if (this->SymbolBodies.empty())
-    return this->SymbolBodies;
-  return makeArrayRef(this->SymbolBodies).slice(1);
+  if (this->Symbols.empty())
+    return {};
+  return makeArrayRef(this->Symbols).slice(1, this->FirstNonLocal - 1);
 }
 
 template <class ELFT>
@@ -523,9 +517,9 @@ StringRef ObjFile<ELFT>::getSectionName(
 }
 
 template <class ELFT> void ObjFile<ELFT>::initializeSymbols() {
-  SymbolBodies.reserve(this->ELFSyms.size());
+  this->Symbols.reserve(this->ELFSyms.size());
   for (const Elf_Sym &Sym : this->ELFSyms)
-    SymbolBodies.push_back(createSymbolBody(&Sym));
+    this->Symbols.push_back(createSymbolBody(&Sym));
 }
 
 template <class ELFT>

Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=310049&r1=310048&r2=310049&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Fri Aug  4 04:07:42 2017
@@ -83,6 +83,14 @@ public:
     return Sections;
   }
 
+  // Returns object file symbols. It is a runtime error to call this
+  // function on files of other types.
+  ArrayRef<SymbolBody *> getSymbols() {
+    assert(FileKind == ObjectKind || FileKind == BitcodeKind ||
+           FileKind == ArchiveKind);
+    return Symbols;
+  }
+
   // 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.
@@ -100,6 +108,7 @@ public:
 protected:
   InputFile(Kind K, MemoryBufferRef M);
   std::vector<InputSectionBase *> Sections;
+  std::vector<SymbolBody *> Symbols;
 
 private:
   const Kind FileKind;
@@ -157,7 +166,6 @@ public:
 
   static std::vector<ObjFile<ELFT> *> Instances;
 
-  ArrayRef<SymbolBody *> getSymbols();
   ArrayRef<SymbolBody *> getLocalSymbols();
 
   ObjFile(MemoryBufferRef M, StringRef ArchiveName);
@@ -166,9 +174,9 @@ public:
   InputSectionBase *getSection(const Elf_Sym &Sym) const;
 
   SymbolBody &getSymbolBody(uint32_t SymbolIndex) const {
-    if (SymbolIndex >= SymbolBodies.size())
+    if (SymbolIndex >= this->Symbols.size())
       fatal(toString(this) + ": invalid symbol index");
-    return *SymbolBodies[SymbolIndex];
+    return *this->Symbols[SymbolIndex];
   }
 
   template <typename RelT>
@@ -204,9 +212,6 @@ private:
   bool shouldMerge(const Elf_Shdr &Sec);
   SymbolBody *createSymbolBody(const Elf_Sym *Sym);
 
-  // List of all symbols referenced or defined by this file.
-  std::vector<SymbolBody *> SymbolBodies;
-
   // .shstrtab contents.
   StringRef SectionStringTable;
 
@@ -258,7 +263,6 @@ public:
   explicit ArchiveFile(std::unique_ptr<Archive> &&File);
   static bool classof(const InputFile *F) { return F->kind() == ArchiveKind; }
   template <class ELFT> void parse();
-  ArrayRef<SymbolBody *> getSymbols() { return Symbols; }
 
   // Returns a memory buffer for a given symbol and the offset in the archive
   // for the member. An empty memory buffer and an offset of zero
@@ -269,7 +273,6 @@ public:
 private:
   std::unique_ptr<Archive> File;
   llvm::DenseSet<uint64_t> Seen;
-  std::vector<SymbolBody *> Symbols;
 };
 
 class BitcodeFile : public InputFile {
@@ -279,12 +282,8 @@ public:
   static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; }
   template <class ELFT>
   void parse(llvm::DenseSet<llvm::CachedHashStringRef> &ComdatGroups);
-  ArrayRef<SymbolBody *> getSymbols() { return Symbols; }
   std::unique_ptr<llvm::lto::InputFile> Obj;
   static std::vector<BitcodeFile *> Instances;
-
-private:
-  std::vector<SymbolBody *> Symbols;
 };
 
 // .so file.

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=310049&r1=310048&r2=310049&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Fri Aug  4 04:07:42 2017
@@ -435,7 +435,7 @@ static void finalizeShtGroup(OutputSecti
   // provides signature of the section group.
   ObjFile<ELFT> *Obj = Sections[0]->getFile<ELFT>();
   ArrayRef<SymbolBody *> Symbols = Obj->getSymbols();
-  OS->Info = InX::SymTab->getSymbolIndex(Symbols[Sections[0]->Info - 1]);
+  OS->Info = InX::SymTab->getSymbolIndex(Symbols[Sections[0]->Info]);
 }
 
 template <class ELFT> void OutputSection::finalize() {




More information about the llvm-commits mailing list