[lld] r265073 - ELF: Correctly handle --whole-archive for thin archives.

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


Author: pcc
Date: Thu Mar 31 18:12:18 2016
New Revision: 265073

URL: http://llvm.org/viewvc/llvm-project?rev=265073&view=rev
Log:
ELF: Correctly handle --whole-archive for thin archives.

Differential Revision: http://reviews.llvm.org/D18669

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

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=265073&r1=265072&r2=265073&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Thu Mar 31 18:12:18 2016
@@ -71,7 +71,8 @@ static std::pair<ELFKind, uint16_t> pars
 
 // 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 @@ static std::vector<MemoryBufferRef> getA
                   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;
 }
 

Modified: lld/trunk/ELF/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.h?rev=265073&r1=265072&r2=265073&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.h (original)
+++ lld/trunk/ELF/Driver.h Thu Mar 31 18:12:18 2016
@@ -28,6 +28,7 @@ public:
   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);

Modified: lld/trunk/test/ELF/archive.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/archive.s?rev=265073&r1=265072&r2=265073&view=diff
==============================================================================
--- lld/trunk/test/ELF/archive.s (original)
+++ lld/trunk/test/ELF/archive.s Thu Mar 31 18:12:18 2016
@@ -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.

Modified: lld/trunk/test/ELF/whole-archive.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/whole-archive.s?rev=265073&r1=265072&r2=265073&view=diff
==============================================================================
--- lld/trunk/test/ELF/whole-archive.s (original)
+++ lld/trunk/test/ELF/whole-archive.s Thu Mar 31 18:12:18 2016
@@ -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:




More information about the llvm-commits mailing list