Simplify --whole-archive handling.

Previously, we handle archive files with --whole-archive this way:
create instances of ArchiveFile, call getMembers to obtain memory
buffers of archive members, and create ObjectFiles for the members.
We didn't call anything except getMembers if --whole-archive was
specified.

I noticed that we didn't actually have to create ArchiveFile instaces
at all for that case. All we need is to get a list of memory buffers
for members, which can be done by a non-member function.

This patch removes getMembers member function from ArchiveFile.
Also removed unnecessary code for memory management.

llvm-svn: 256893
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index cfc173c..2a3ecfa 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -57,6 +57,24 @@
   error("Unknown emulation: " + S);
 }
 
+// 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) {
+  ErrorOr<std::unique_ptr<Archive>> FileOrErr = Archive::create(MB);
+  error(FileOrErr, "Failed to parse archive");
+  std::unique_ptr<Archive> File = std::move(*FileOrErr);
+
+  std::vector<MemoryBufferRef> V;
+  for (const ErrorOr<Archive::Child> &C : File->children()) {
+    error(C, "Could not get the child of the archive " + File->getFileName());
+    ErrorOr<MemoryBufferRef> MbOrErr = C->getMemoryBufferRef();
+    error(MbOrErr, "Could not get the buffer for a child of the archive " +
+                       File->getFileName());
+    V.push_back(*MbOrErr);
+  }
+  return V;
+}
+
 // Opens and parses a file. Path has to be resolved already.
 // Newly created memory buffers are owned by this driver.
 void LinkerDriver::addFile(StringRef Path) {
@@ -75,10 +93,8 @@
     return;
   case file_magic::archive:
     if (WholeArchive) {
-      auto File = make_unique<ArchiveFile>(MBRef);
-      for (MemoryBufferRef &MB : File->getMembers())
+      for (MemoryBufferRef MB : getArchiveMembers(MBRef))
         Files.push_back(createObjectFile(MB));
-      OwningArchives.emplace_back(std::move(File));
       return;
     }
     Files.push_back(make_unique<ArchiveFile>(MBRef));