[lld] r302241 - Use the archive offset with --whole-archive.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri May 5 08:08:07 PDT 2017


Author: rafael
Date: Fri May  5 10:08:06 2017
New Revision: 302241

URL: http://llvm.org/viewvc/llvm-project?rev=302241&view=rev
Log:
Use the archive offset with --whole-archive.

The test ELF/lto/thin-archivecollision.ll was not testing what it
wanted to test. It needs two archive members with the same name, but
different offsets.

Without this we could remove all references of OffsetInArchive and all
tests would still pass.

Fixing the test showed that the --whole-archive case was broken, which
this patch fixes.

Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/test/ELF/lto/thin-archivecollision.ll

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=302241&r1=302240&r2=302241&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Fri May  5 10:08:06 2017
@@ -123,13 +123,13 @@ static std::tuple<ELFKind, uint16_t, uin
 
 // Returns slices of MB by parsing MB as an archive file.
 // Each slice consists of a member file in the archive.
-std::vector<MemoryBufferRef>
-static getArchiveMembers(MemoryBufferRef MB) {
+std::vector<std::pair<MemoryBufferRef, uint64_t>> static getArchiveMembers(
+    MemoryBufferRef MB) {
   std::unique_ptr<Archive> File =
       check(Archive::create(MB),
             MB.getBufferIdentifier() + ": failed to parse archive");
 
-  std::vector<MemoryBufferRef> V;
+  std::vector<std::pair<MemoryBufferRef, uint64_t>> V;
   Error Err = Error::success();
   for (const ErrorOr<Archive::Child> &COrErr : File->children(Err)) {
     Archive::Child C =
@@ -139,7 +139,7 @@ static getArchiveMembers(MemoryBufferRef
         check(C.getMemoryBufferRef(),
               MB.getBufferIdentifier() +
                   ": could not get the buffer for a child of the archive");
-    V.push_back(MBRef);
+    V.push_back(std::make_pair(MBRef, C.getChildOffset()));
   }
   if (Err)
     fatal(MB.getBufferIdentifier() + ": Archive::children failed: " +
@@ -173,8 +173,8 @@ void LinkerDriver::addFile(StringRef Pat
   case file_magic::archive: {
     // Handle -whole-archive.
     if (InWholeArchive) {
-      for (MemoryBufferRef MB : getArchiveMembers(MBRef))
-        Files.push_back(createObjectFile(MB, Path));
+      for (const auto &P : getArchiveMembers(MBRef))
+        Files.push_back(createObjectFile(P.first, Path, P.second));
       return;
     }
 
@@ -186,8 +186,8 @@ void LinkerDriver::addFile(StringRef Pat
     // understand the LLVM bitcode file. It is a pretty common error, so
     // we'll handle it as if it had a symbol table.
     if (!File->hasSymbolTable()) {
-      for (MemoryBufferRef MB : getArchiveMembers(MBRef))
-        Files.push_back(make<LazyObjectFile>(MB, MBRef.getBufferIdentifier()));
+      for (const auto &P : getArchiveMembers(MBRef))
+        Files.push_back(make<LazyObjectFile>(P.first, Path));
       return;
     }
 

Modified: lld/trunk/test/ELF/lto/thin-archivecollision.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/thin-archivecollision.ll?rev=302241&r1=302240&r2=302241&view=diff
==============================================================================
--- lld/trunk/test/ELF/lto/thin-archivecollision.ll (original)
+++ lld/trunk/test/ELF/lto/thin-archivecollision.ll Fri May  5 10:08:06 2017
@@ -1,14 +1,15 @@
 ; RUN: opt -module-summary %s -o %t.o
-; RUN: opt -module-summary %p/Inputs/thin1.ll -o %t.coll.o
-; RUN: llvm-ar rcs %t1.a %t.coll.o
-; RUN: opt -module-summary %p/Inputs/thin2.ll -o %t.coll.o
-; RUN: llvm-ar rcsc %t2.a %t.coll.o
+; RUN: mkdir -p %t1 %t2
+; RUN: opt -module-summary %p/Inputs/thin1.ll -o %t1/t.coll.o
+; RUN: opt -module-summary %p/Inputs/thin2.ll -o %t2/t.coll.o
+; RUN: rm -f %t.a
+; RUN: llvm-ar rcs %t.a %t1/t.coll.o %t2/t.coll.o
 
-; RUN: ld.lld %t.o %t1.a %t2.a -o %t
+; RUN: ld.lld %t.o %t.a -o %t
 ; RUN: llvm-nm %t | FileCheck %s
 
 ; Check we handle this case correctly even in presence of --whole-archive.
-; RUN: ld.lld %t.o --whole-archive %t1.a %t2.a -o %t
+; RUN: ld.lld %t.o --whole-archive %t.a -o %t
 ; RUN: llvm-nm %t | FileCheck %s
 
 ; CHECK: T _start




More information about the llvm-commits mailing list