[PATCH] D18669: ELF: Correctly handle --whole-archive for thin archives.Depends on D18664Depends on D18666

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 31 12:51:51 PDT 2016


pcc created this revision.
pcc added reviewers: rafael, ruiu.
pcc added a subscriber: llvm-commits.

http://reviews.llvm.org/D18669

Files:
  ELF/Driver.cpp
  test/ELF/archive.s
  test/ELF/whole-archive.s

Index: test/ELF/whole-archive.s
===================================================================
--- test/ELF/whole-archive.s
+++ test/ELF/whole-archive.s
@@ -30,5 +30,11 @@
 // RUN: ld.lld -o %t3 %t.o --whole-archive %t.a --no-whole-archive
 // RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=ADDED %s
 
+// --whole-archive should also work with thin archives
+// RUN: rm -f %tthin.a
+// RUN: llvm-ar rcsT %tthin.a %ta.o
+// RUN: ld.lld -o %t3 %t.o --whole-archive %tthin.a --no-whole-archive
+// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=ADDED %s
+
 .globl _start;
 _start:
Index: test/ELF/archive.s
===================================================================
--- test/ELF/archive.s
+++ test/ELF/archive.s
@@ -6,6 +6,9 @@
 # RUN: llvm-ar rcs %tar %t2 %t3 %t4
 # RUN: ld.lld %t %tar %t5 -o %tout
 # RUN: llvm-nm %tout | FileCheck %s
+# RUN: llvm-ar rcsT %tarthin %t2 %t3 %t4
+# RUN: ld.lld %t %tarthin %t5 -o %tout
+# RUN: llvm-nm %tout | FileCheck %s
 # REQUIRES: x86
 
 # Nothing here. Just needed for the linker to create a undefined _start symbol.
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -69,7 +69,9 @@
 
 // Returns slices of MB by parsing MB as an archive file.
 // Each slice consists of a member file in the archive.
-static std::vector<MemoryBufferRef> getArchiveMembers(MemoryBufferRef MB) {
+static std::vector<MemoryBufferRef>
+getArchiveMembers(MemoryBufferRef MB,
+                  std::vector<std::unique_ptr<MemoryBuffer>> &OwningMBs) {
   std::unique_ptr<Archive> File =
       check(Archive::create(MB), "failed to parse archive");
 
@@ -83,6 +85,10 @@
                   File->getFileName());
     V.push_back(Mb);
   }
+
+  for (std::unique_ptr<MemoryBuffer> &MB : File->takeThinBuffers())
+    OwningMBs.push_back(std::move(MB));
+
   return V;
 }
 
@@ -107,7 +113,7 @@
     return;
   case file_magic::archive:
     if (WholeArchive) {
-      for (MemoryBufferRef MB : getArchiveMembers(MBRef))
+      for (MemoryBufferRef MB : getArchiveMembers(MBRef, OwningMBs))
         Files.push_back(createObjectFile(MB, Path));
       return;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18669.52266.patch
Type: text/x-patch
Size: 2195 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160331/cc9be15f/attachment.bin>


More information about the llvm-commits mailing list