diff options
-rw-r--r-- | lld/include/lld/ReaderWriter/PECOFFLinkingContext.h | 9 | ||||
-rw-r--r-- | lld/lib/Driver/WinLinkDriver.cpp | 4 | ||||
-rw-r--r-- | lld/lib/Driver/WinLinkOptions.td | 2 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp | 8 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp | 8 | ||||
-rw-r--r-- | lld/unittests/DriverTests/WinLinkDriverTest.cpp | 10 |
6 files changed, 32 insertions, 9 deletions
diff --git a/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h b/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h index 19d0b5727cf..0a33c07f109 100644 --- a/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h +++ b/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h @@ -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; diff --git a/lld/lib/Driver/WinLinkDriver.cpp b/lld/lib/Driver/WinLinkDriver.cpp index 7f55dd4acd4..3970cf7a298 100644 --- a/lld/lib/Driver/WinLinkDriver.cpp +++ b/lld/lib/Driver/WinLinkDriver.cpp @@ -1143,6 +1143,10 @@ bool WinLinkDriver::parse(int argc, const char *argv[], 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)) { diff --git a/lld/lib/Driver/WinLinkOptions.td b/lld/lib/Driver/WinLinkOptions.td index eda2e092a73..3d321da18cf 100644 --- a/lld/lib/Driver/WinLinkOptions.td +++ b/lld/lib/Driver/WinLinkOptions.td @@ -37,6 +37,7 @@ def section : P<"section", "Specify section attributes">; 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">; diff --git a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp index b3c66fd78da..474b14829b6 100644 --- a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp +++ b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp @@ -268,6 +268,14 @@ void PECOFFLinkingContext::addDllExport(ExportDesc &desc) { << "' 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))); diff --git a/lld/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp b/lld/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp index 36abe6ac565..5e66a181219 100644 --- a/lld/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp +++ b/lld/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp @@ -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 PECOFFLinkingContext &ctx) { 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()); diff --git a/lld/unittests/DriverTests/WinLinkDriverTest.cpp b/lld/unittests/DriverTests/WinLinkDriverTest.cpp index 9e79a795db9..e49d122ea60 100644 --- a/lld/unittests/DriverTests/WinLinkDriverTest.cpp +++ b/lld/unittests/DriverTests/WinLinkDriverTest.cpp @@ -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 // |