[elf2] Add basic archive file support.

llvm-svn: 246886
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index 37e0033..b58d9e9 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -12,6 +12,9 @@
 #include "Error.h"
 #include "InputFiles.h"
 
+#include "llvm/ADT/STLExtras.h"
+
+using namespace llvm;
 using namespace llvm::object;
 using namespace llvm::ELF;
 
@@ -29,6 +32,7 @@
 // Returns 1, 0 or -1 if this symbol should take precedence
 // over the Other, tie or lose, respectively.
 template <class ELFT> int SymbolBody::compare(SymbolBody *Other) {
+  assert(!isLazy() && !Other->isLazy());
   std::pair<bool, bool> L(isDefined(), !isWeak());
   std::pair<bool, bool> R(Other->isDefined(), !Other->isWeak());
 
@@ -67,6 +71,17 @@
   return 1;
 }
 
+std::unique_ptr<InputFile> Lazy::getMember() {
+  MemoryBufferRef MBRef = File->getMember(&Sym);
+
+  // getMember returns an empty buffer if the member was already
+  // read from the library.
+  if (MBRef.getBuffer().empty())
+    return std::unique_ptr<InputFile>(nullptr);
+
+  return createELFFile<ObjectFile>(MBRef);
+}
+
 template int SymbolBody::compare<ELF32LE>(SymbolBody *Other);
 template int SymbolBody::compare<ELF32BE>(SymbolBody *Other);
 template int SymbolBody::compare<ELF64LE>(SymbolBody *Other);