[lld] r207175 - [PECOFF] Add /IMPLIB command line option.

Rui Ueyama ruiu at google.com
Thu Apr 24 20:35:13 PDT 2014


Author: ruiu
Date: Thu Apr 24 22:35:13 2014
New Revision: 207175

URL: http://llvm.org/viewvc/llvm-project?rev=207175&view=rev
Log:
[PECOFF] Add /IMPLIB command line option.

This option is to override the default import file path.

Modified:
    lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
    lld/trunk/lib/Driver/WinLinkDriver.cpp
    lld/trunk/lib/Driver/WinLinkOptions.td
    lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
    lld/trunk/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp
    lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp

Modified: lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h?rev=207175&r1=207174&r2=207175&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h Thu Apr 24 22:35:13 2014
@@ -49,7 +49,8 @@ public:
         _createManifest(true), _embedManifest(false), _manifestId(1),
         _manifestUAC(true), _manifestLevel("'asInvoker'"),
         _manifestUiAccess("'false'"), _isDll(false), _requireSEH(false),
-        _noSEH(false), _dosStub(llvm::makeArrayRef(DEFAULT_DOS_STUB)) {
+        _noSEH(false), _implib(""),
+        _dosStub(llvm::makeArrayRef(DEFAULT_DOS_STUB)) {
     setDeadStripping(true);
   }
 
@@ -209,6 +210,9 @@ public:
   bool requireSEH() const { return _requireSEH; }
   bool noSEH() const { return _noSEH; }
 
+  void setOutputImportLibraryPath(const std::string &val) { _implib = val; }
+  std::string getOutputImportLibraryPath() const;
+
   StringRef getOutputSectionName(StringRef sectionName) const;
   bool addSectionRenaming(raw_ostream &diagnostics,
                           StringRef from, StringRef to);
@@ -330,6 +334,9 @@ private:
   // compatible with SEH.
   bool _noSEH;
 
+  // /IMPLIB command line option.
+  std::string _implib;
+
   // The set to store /nodefaultlib arguments.
   std::set<std::string> _noDefaultLibs;
 

Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=207175&r1=207174&r2=207175&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Thu Apr 24 22:35:13 2014
@@ -1143,6 +1143,10 @@ bool WinLinkDriver::parse(int argc, cons
       ctx.setSwapRunFromNet(true);
       break;
 
+    case OPT_implib:
+      ctx.setOutputImportLibraryPath(inputArg->getValue());
+      break;
+
     case OPT_stub: {
       ArrayRef<uint8_t> contents;
       if (!readFile(ctx, inputArg->getValue(), contents)) {

Modified: lld/trunk/lib/Driver/WinLinkOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkOptions.td?rev=207175&r1=207174&r2=207175&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkOptions.td (original)
+++ lld/trunk/lib/Driver/WinLinkOptions.td Thu Apr 24 22:35:13 2014
@@ -37,6 +37,7 @@ def section : P<"section", "Specify sect
 def subsystem : P<"subsystem", "Specify subsystem">;
 def stub    : P<"stub", "Specify DOS stub file">;
 def opt     : P<"opt", "Control optimizations">;
+def implib  : P<"implib", "Import library name">;
 
 def manifest : F<"manifest">;
 def manifest_colon : P<"manifest", "Create manifest file">;
@@ -104,7 +105,6 @@ def delayload : QF<"delayload">;
 def errorreport : QF<"errorreport">;
 def idlout : QF<"idlout">;
 def ignore : QF<"ignore">;
-def implib : QF<"implib">;
 def pdb : QF<"pdb">;
 def pdbaltpath : QF<"pdbaltpath">;
 def tlbid : QF<"tlbid">;

Modified: lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp?rev=207175&r1=207174&r2=207175&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp Thu Apr 24 22:35:13 2014
@@ -268,6 +268,14 @@ void PECOFFLinkingContext::addDllExport(
                << "' specified more than once.\n";
 }
 
+std::string PECOFFLinkingContext::getOutputImportLibraryPath() const {
+  if (!_implib.empty())
+    return _implib;
+  SmallString<128> path = outputPath();
+  llvm::sys::path::replace_extension(path, ".lib");
+  return path.str();
+}
+
 void PECOFFLinkingContext::addPasses(PassManager &pm) {
   pm.add(std::unique_ptr<Pass>(new pecoff::SetSubsystemPass(*this)));
   pm.add(std::unique_ptr<Pass>(new pecoff::EdataPass(*this)));

Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp?rev=207175&r1=207174&r2=207175&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp Thu Apr 24 22:35:13 2014
@@ -20,12 +20,6 @@
 namespace lld {
 namespace pecoff {
 
-static std::string getOutputPath(const PECOFFLinkingContext &ctx) {
-  SmallString<128> path = ctx.outputPath();
-  llvm::sys::path::replace_extension(path, ".lib");
-  return path.str();
-}
-
 /// Creates a .def file containing the list of exported symbols.
 static std::string
 createModuleDefinitionFile(const PECOFFLinkingContext &ctx,
@@ -65,7 +59,7 @@ void writeImportLibrary(const PECOFFLink
   std::string defArg = "/def:";
   defArg.append(createModuleDefinitionFile(ctx, tmpFile));
   std::string outputArg = "/out:";
-  outputArg.append(getOutputPath(ctx));
+  outputArg.append(ctx.getOutputImportLibraryPath());
 
   std::vector<const char *> args;
   args.push_back(programPath.c_str());

Modified: lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp?rev=207175&r1=207174&r2=207175&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp Thu Apr 24 22:35:13 2014
@@ -329,6 +329,16 @@ TEST_F(WinLinkParserTest, Merge_Circular
                      "a.out", nullptr));
 }
 
+TEST_F(WinLinkParserTest, Implib) {
+  EXPECT_TRUE(parse("link.exe", "/implib:foo.dll.lib", "a.out", nullptr));
+  EXPECT_EQ("foo.dll.lib", _context.getOutputImportLibraryPath());
+}
+
+TEST_F(WinLinkParserTest, ImplibDefault) {
+  EXPECT_TRUE(parse("link.exe", "/out:foobar.dll", "a.out", nullptr));
+  EXPECT_EQ("foobar.lib", _context.getOutputImportLibraryPath());
+}
+
 //
 // Tests for /section
 //





More information about the llvm-commits mailing list