Use IRMover directly.

This has a few advantages:
* If lld selected a non bitcode symbol, be the bitcode GV is not merged
* lib/Linker is not redoing symbol resolution.

llvm-svn: 262773
diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp
index 182be51..7f41724 100644
--- a/lld/ELF/SymbolTable.cpp
+++ b/lld/ELF/SymbolTable.cpp
@@ -20,7 +20,7 @@
 #include "Symbols.h"
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/IR/LegacyPassManager.h"
-#include "llvm/Linker/Linker.h"
+#include "llvm/Linker/IRMover.h"
 #include "llvm/Support/StringSaver.h"
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Target/TargetMachine.h"
@@ -126,21 +126,36 @@
   return createObjectFile(*LtoBuffer);
 }
 
+static void addBitcodeFile(IRMover &Mover, BitcodeFile &F,
+                           LLVMContext &Context) {
+  std::unique_ptr<MemoryBuffer> Buffer =
+      MemoryBuffer::getMemBuffer(F.MB, false);
+  std::unique_ptr<Module> M =
+      check(getLazyBitcodeModule(std::move(Buffer), Context,
+                                 /*ShouldLazyLoadMetadata*/ true));
+  std::vector<GlobalValue *> Keep;
+  for (SymbolBody *B : F.getSymbols()) {
+    if (B->repl() != B)
+      continue;
+    auto *DB = dyn_cast<DefinedBitcode>(B);
+    if (!DB)
+      continue;
+    GlobalValue *GV = M->getNamedValue(B->getName());
+    assert(GV);
+    Keep.push_back(GV);
+  }
+  Mover.move(std::move(M), Keep, [](GlobalValue &, IRMover::ValueAdder) {});
+}
+
 // Merge all the bitcode files we have seen, codegen the result and return
 // the resulting ObjectFile.
 template <class ELFT>
 ObjectFile<ELFT> *SymbolTable<ELFT>::createCombinedLtoObject() {
   LLVMContext Context;
   Module Combined("ld-temp.o", Context);
-  Linker L(Combined);
-  for (const std::unique_ptr<BitcodeFile> &F : BitcodeFiles) {
-    std::unique_ptr<MemoryBuffer> Buffer =
-        MemoryBuffer::getMemBuffer(F->MB, false);
-    std::unique_ptr<Module> M =
-        check(getLazyBitcodeModule(std::move(Buffer), Context,
-                                   /*ShouldLazyLoadMetadata*/ true));
-    L.linkInModule(std::move(M));
-  }
+  IRMover Mover(Combined);
+  for (const std::unique_ptr<BitcodeFile> &F : BitcodeFiles)
+    addBitcodeFile(Mover, *F, Context);
   std::unique_ptr<InputFile> F = codegen(Combined);
   ObjectFiles.emplace_back(cast<ObjectFile<ELFT>>(F.release()));
   return &*ObjectFiles.back();