From c0cb3ec7472d4667226d0183382e165a7a6d2c30 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Wed, 4 Oct 2017 12:55:38 -0700
Subject: [PATCH 3/6] [C API] Add LLVMLinkModules2Needed().

---
 include/llvm-c/Linker.h    | 1 +
 lib/Linker/LinkModules.cpp | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/include/llvm-c/Linker.h b/include/llvm-c/Linker.h
index d02c37f94c8..06af8193e57 100644
--- a/include/llvm-c/Linker.h
+++ b/include/llvm-c/Linker.h
@@ -33,6 +33,7 @@ typedef enum {
  * Use the diagnostic handler to get any diagnostic message.
 */
 LLVMBool LLVMLinkModules2(LLVMModuleRef Dest, LLVMModuleRef Src);
+LLVMBool LLVMLinkModules2Needed(LLVMModuleRef Dest, LLVMModuleRef Src);
 
 #ifdef __cplusplus
 }
diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp
index 25f31a3401a..9a34c9ecce8 100644
--- a/lib/Linker/LinkModules.cpp
+++ b/lib/Linker/LinkModules.cpp
@@ -604,3 +604,9 @@ LLVMBool LLVMLinkModules2(LLVMModuleRef Dest, LLVMModuleRef Src) {
   std::unique_ptr<Module> M(unwrap(Src));
   return Linker::linkModules(*D, std::move(M));
 }
+
+LLVMBool LLVMLinkModules2Needed(LLVMModuleRef Dest, LLVMModuleRef Src) {
+  Module *D = unwrap(Dest);
+  std::unique_ptr<Module> M(unwrap(Src));
+  return Linker::linkModules(*D, std::move(M), Linker::Flags::LinkOnlyNeeded);
+}
-- 
2.14.1.536.g6867272d5b.dirty

