[lld] r255839 - ELF: Remove SymbolTable::addELFFile.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 16 14:59:14 PST 2015


Author: ruiu
Date: Wed Dec 16 16:59:13 2015
New Revision: 255839

URL: http://llvm.org/viewvc/llvm-project?rev=255839&view=rev
Log:
ELF: Remove SymbolTable::addELFFile.

addELFFile was called only from addFile, and what it did was actually
just adding a file to the symbol table. There seems to be no reason
to separate the two.

Modified:
    lld/trunk/ELF/SymbolTable.cpp
    lld/trunk/ELF/SymbolTable.h

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=255839&r1=255838&r2=255839&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Wed Dec 16 16:59:13 2015
@@ -36,24 +36,37 @@ template <class ELFT> bool SymbolTable<E
 template <class ELFT>
 void SymbolTable<ELFT>::addFile(std::unique_ptr<InputFile> File) {
   checkCompatibility(File);
+  InputFile *FileP = File.release();
 
-  if (auto *AF = dyn_cast<ArchiveFile>(File.get())) {
-    ArchiveFiles.emplace_back(std::move(File));
-    AF->parse();
-    for (Lazy &Sym : AF->getLazySymbols())
+  // .a file
+  if (auto *F = dyn_cast<ArchiveFile>(FileP)) {
+    ArchiveFiles.emplace_back(F);
+    F->parse();
+    for (Lazy &Sym : F->getLazySymbols())
       addLazy(&Sym);
     return;
   }
 
-  if (auto *S = dyn_cast<SharedFile<ELFT>>(File.get())) {
-    S->parseSoName();
-    if (!IncludedSoNames.insert(S->getSoName()).second)
+  // .so file
+  if (auto *F = dyn_cast<SharedFile<ELFT>>(FileP)) {
+    // DSOs are uniquified not by filename but by soname.
+    F->parseSoName();
+    if (!IncludedSoNames.insert(F->getSoName()).second)
       return;
-    S->parse();
-  } else {
-    cast<ObjectFile<ELFT>>(File.get())->parse(Comdats);
+
+    SharedFiles.emplace_back(F);
+    F->parse();
+    for (SharedSymbol<ELFT> &B : F->getSharedSymbols())
+      resolve(&B);
+    return;
   }
-  addELFFile(cast<ELFFileBase<ELFT>>(File.release()));
+
+  // .o file
+  auto *F = cast<ObjectFile<ELFT>>(FileP);
+  ObjectFiles.emplace_back(F);
+  F->parse(Comdats);
+  for (SymbolBody *B : F->getSymbols())
+    resolve(B);
 }
 
 template <class ELFT>
@@ -102,24 +115,6 @@ template <class ELFT> bool SymbolTable<E
   return false;
 }
 
-template <class ELFT>
-void SymbolTable<ELFT>::addELFFile(ELFFileBase<ELFT> *File) {
-  if (auto *O = dyn_cast<ObjectFile<ELFT>>(File))
-    ObjectFiles.emplace_back(O);
-  else if (auto *S = dyn_cast<SharedFile<ELFT>>(File))
-    SharedFiles.emplace_back(S);
-
-  if (auto *O = dyn_cast<ObjectFile<ELFT>>(File)) {
-    for (SymbolBody *Body : O->getSymbols())
-      resolve(Body);
-  }
-
-  if (auto *S = dyn_cast<SharedFile<ELFT>>(File)) {
-    for (SharedSymbol<ELFT> &Body : S->getSharedSymbols())
-      resolve(&Body);
-  }
-}
-
 // Returns a file from which symbol B was created.
 // If B does not belong to any file in ObjectFiles, returns a nullptr.
 template <class ELFT>

Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=255839&r1=255838&r2=255839&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Wed Dec 16 16:59:13 2015
@@ -61,7 +61,6 @@ public:
 
 private:
   Symbol *insert(SymbolBody *New);
-  void addELFFile(ELFFileBase<ELFT> *File);
   void addLazy(Lazy *New);
   void addMemberFile(Lazy *Body);
   void checkCompatibility(std::unique_ptr<InputFile> &File);




More information about the llvm-commits mailing list