[PATCH] D18669: ELF: Correctly handle --whole-archive for thin archives.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 31 16:17:45 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL265073: ELF: Correctly handle --whole-archive for thin archives. (authored by pcc).

Changed prior to commit:
  http://reviews.llvm.org/D18669?vs=52288&id=52308#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D18669

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

Index: lld/trunk/ELF/Driver.cpp
===================================================================
--- lld/trunk/ELF/Driver.cpp
+++ lld/trunk/ELF/Driver.cpp
@@ -71,7 +71,8 @@
 
 // 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) {
+std::vector<MemoryBufferRef>
+LinkerDriver::getArchiveMembers(MemoryBufferRef MB) {
   std::unique_ptr<Archive> File =
       check(Archive::create(MB), "failed to parse archive");
 
@@ -85,6 +86,11 @@
                   File->getFileName());
     V.push_back(Mb);
   }
+
+  // Take ownership of memory buffers created for members of thin archives.
+  for (std::unique_ptr<MemoryBuffer> &MB : File->takeThinBuffers())
+    OwningMBs.push_back(std::move(MB));
+
   return V;
 }
 
Index: lld/trunk/ELF/Driver.h
===================================================================
--- lld/trunk/ELF/Driver.h
+++ lld/trunk/ELF/Driver.h
@@ -28,6 +28,7 @@
   void addLibrary(StringRef Name);
 
 private:
+  std::vector<MemoryBufferRef> getArchiveMembers(MemoryBufferRef MB);
   void readConfigs(llvm::opt::InputArgList &Args);
   void createFiles(llvm::opt::InputArgList &Args);
   template <class ELFT> void link(llvm::opt::InputArgList &Args);
Index: lld/trunk/test/ELF/archive.s
===================================================================
--- lld/trunk/test/ELF/archive.s
+++ lld/trunk/test/ELF/archive.s
@@ -6,6 +6,10 @@
 # RUN: llvm-ar rcs %tar %t2 %t3 %t4
 # RUN: ld.lld %t %tar %t5 -o %tout
 # RUN: llvm-nm %tout | FileCheck %s
+# RUN: rm -f %tarthin
+# RUN: llvm-ar --format=gnu 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: lld/trunk/test/ELF/whole-archive.s
===================================================================
--- lld/trunk/test/ELF/whole-archive.s
+++ lld/trunk/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 --format=gnu rcsT %tthin.a %ta.o
+// RUN: ld.lld -o %t3 %t.o --whole-archive %tthin.a
+// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=ADDED %s
+
 .globl _start;
 _start:


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


More information about the llvm-commits mailing list