[PATCH] D50174: [LLD][ELF] - Remove dead code from ArchiveFile.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 2 03:14:16 PDT 2018


grimar created this revision.
grimar added a reviewer: ruiu.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: espindola.

I believe this is NFC change, but posting on review just in case I am missing something.

Currently, the code uses `Seen` set to prevent fetching the archive files twice,
but I think it is impossible to face this situation. Because if we have lazy symbols
`A1..An` from object in archive `AR`, then after facing undefined symbol A1 in some regular object,
we will fetch() and resolve all symbols and will never call fetch() for symbols from archive `AR` again.


https://reviews.llvm.org/D50174

Files:
  ELF/InputFiles.cpp
  ELF/InputFiles.h
  ELF/SymbolTable.cpp
  test/ELF/archive-fetch.s


Index: test/ELF/archive-fetch.s
===================================================================
--- test/ELF/archive-fetch.s
+++ test/ELF/archive-fetch.s
@@ -0,0 +1,17 @@
+# REQUIRES: x86
+
+# RUN: echo '.quad foo' | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %tfoo.o
+# RUN: echo '.quad bar' | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %tbar.o
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: rm -f %t.a
+# RUN: llvm-ar rcs %t.a %t.o
+
+# Test we can link it.
+# RUN: ld.lld %t.a %tfoo.o %tbar.o -o /dev/null
+
+.global foo
+foo:
+
+.global bar
+bar:
Index: ELF/SymbolTable.cpp
===================================================================
--- ELF/SymbolTable.cpp
+++ ELF/SymbolTable.cpp
@@ -646,8 +646,7 @@
 
 template <class ELFT> void SymbolTable::fetchLazy(Symbol *Sym) {
   if (auto *S = dyn_cast<LazyArchive>(Sym)) {
-    if (InputFile *File = S->fetch())
-      addFile<ELFT>(File);
+    addFile<ELFT>(S->fetch());
     return;
   }
 
Index: ELF/InputFiles.h
===================================================================
--- ELF/InputFiles.h
+++ ELF/InputFiles.h
@@ -284,15 +284,11 @@
   static bool classof(const InputFile *F) { return F->kind() == ArchiveKind; }
   template <class ELFT> void parse();
 
-  // Pulls out an object file that contains a definition for Sym and
-  // returns it. If the same file was instantiated before, this
-  // function returns a nullptr (so we don't instantiate the same file
-  // more than once.)
+  // Pulls out an object file that contains a definition for Sym.
   InputFile *fetch(const Archive::Symbol &Sym);
 
 private:
   std::unique_ptr<Archive> File;
-  llvm::DenseSet<uint64_t> Seen;
 };
 
 class BitcodeFile : public InputFile {
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -827,9 +827,6 @@
                                  ": could not get the member for symbol " +
                                  Sym.getName());
 
-  if (!Seen.insert(C.getChildOffset()).second)
-    return nullptr;
-
   MemoryBufferRef MB =
       CHECK(C.getMemoryBufferRef(),
             toString(this) +


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50174.158714.patch
Type: text/x-patch
Size: 2206 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180802/cb733956/attachment.bin>


More information about the llvm-commits mailing list