COFF: Add /implib option.
authorRui Ueyama <ruiu@google.com>
Thu, 18 Jun 2015 20:27:09 +0000 (20:27 +0000)
committerRui Ueyama <ruiu@google.com>
Thu, 18 Jun 2015 20:27:09 +0000 (20:27 +0000)
llvm-svn: 240045

lld/COFF/Config.h
lld/COFF/Driver.cpp
lld/COFF/DriverUtils.cpp
lld/test/COFF/dll.test

index 46db6de..5b8d414 100644 (file)
@@ -55,6 +55,7 @@ struct Configuration {
 
   // True if we are creating a DLL.
   bool DLL = false;
+  StringRef Implib;
   std::vector<Export> Exports;
 
   // Options for manifest files.
index adf6826..8345728 100644 (file)
@@ -338,6 +338,10 @@ bool LinkerDriver::link(int Argc, const char *Argv[]) {
     if (parseAlternateName(Arg->getValue()))
       return false;
 
+  // Handle /implib
+  if (auto *Arg = Args->getLastArg(OPT_implib))
+    Config->Implib = Arg->getValue();
+
   // Handle /opt
   for (auto *Arg : Args->filtered(OPT_opt)) {
     std::string S = StringRef(Arg->getValue()).lower();
index 05dd62f..e9fc3ed 100644 (file)
@@ -507,14 +507,18 @@ std::error_code writeImportLibrary() {
   std::string Contents = createModuleDefinitionFile();
   std::string Def = writeToTempFile(Contents);
   llvm::FileRemover TempFile(Def);
-  SmallString<128> Out = StringRef(Config->OutputFile);
-  sys::path::replace_extension(Out, ".lib");
 
   Executor E("lib.exe");
   E.add("/nologo");
   E.add("/machine:x64");
   E.add(Twine("/def:") + Def);
-  E.add("/out:" + Out);
+  if (Config->Implib.empty()) {
+    SmallString<128> Out = StringRef(Config->OutputFile);
+    sys::path::replace_extension(Out, ".lib");
+    E.add("/out:" + Out);
+  } else {
+    E.add("/out:" + Config->Implib);
+  }
   return E.run();
 }
 
index 70962a3..dcf3b58 100644 (file)
@@ -28,6 +28,10 @@ EXPORT-LTO-NEXT:       3   0x1030  exportfn3
 # RUN: lld -flavor link2 /out:%t2.exe %t2.obj %t.lib
 # RUN: llvm-readobj -coff-imports %t2.exe | FileCheck -check-prefix=IMPORT %s
 
+# RUN: lld -flavor link2 /out:%t.dll /dll %t.obj /implib:%t2.lib /export:exportfn1 /export:exportfn2
+# RUN: lld -flavor link2 /out:%t2.exe %t2.obj %t2.lib
+# RUN: llvm-readobj -coff-imports %t2.exe | FileCheck -check-prefix=IMPORT %s
+
 # RUN: lld -flavor link2 /out:%t2.lto.exe %t2.obj %t.lto.lib
 # RUN: llvm-readobj -coff-imports %t2.lto.exe | FileCheck -check-prefix=IMPORT %s