Index: lld/trunk/include/lld/Driver/Driver.h =================================================================== --- lld/trunk/include/lld/Driver/Driver.h +++ lld/trunk/include/lld/Driver/Driver.h @@ -120,6 +120,14 @@ bool isDirective = false, std::set *undefinedSymbols = nullptr); + // Same as parse(), but restricted to the context of directives. + static bool parseDirectives(int argc, const char *argv[], + PECOFFLinkingContext &info, + raw_ostream &diagnostics = llvm::errs(), + std::set *undefinedSymbols = nullptr) { + return parse(argc, argv, info, diagnostics, true, undefinedSymbols); + } + private: WinLinkDriver() LLVM_DELETED_FUNCTION; }; Index: lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h =================================================================== --- lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h +++ lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h @@ -47,7 +47,8 @@ _manifestUAC(true), _manifestLevel("'asInvoker'"), _manifestUiAccess("'false'"), _isDll(false), _highEntropyVA(true), _requireSEH(false), _noSEH(false), _implib(""), _debug(false), - _pdbFilePath(""), _dosStub(llvm::makeArrayRef(DEFAULT_DOS_STUB)) { + _pdbFilePath(""), _dosStub(llvm::makeArrayRef(DEFAULT_DOS_STUB)), + _parseDirectives(nullptr) { setDeadStripping(true); } @@ -82,6 +83,9 @@ bool isPrivate; }; + typedef bool (*ParseDirectives)(int, const char **, PECOFFLinkingContext &, + raw_ostream &, std::set *); + /// \brief Casting support static inline bool classof(const LinkingContext *info) { return true; } @@ -326,6 +330,14 @@ std::recursive_mutex &getMutex() { return _mutex; } + void setParseDirectives(ParseDirectives parseDirectives) { + _parseDirectives = parseDirectives; + } + + ParseDirectives getParseDirectives() { + return _parseDirectives; + } + protected: /// Method to create a internal file for the entry symbol std::unique_ptr createEntrySymbolFile() const override; @@ -440,6 +452,8 @@ std::set _definedSyms; std::set _seen; + + ParseDirectives _parseDirectives; }; } // end namespace lld Index: lld/trunk/lib/Driver/WinLinkDriver.cpp =================================================================== --- lld/trunk/lib/Driver/WinLinkDriver.cpp +++ lld/trunk/lib/Driver/WinLinkDriver.cpp @@ -855,6 +855,7 @@ return true; PECOFFLinkingContext ctx; + ctx.setParseDirectives(parseDirectives); ctx.registry().addSupportCOFFObjects(ctx); ctx.registry().addSupportCOFFImportLibraries(ctx); ctx.registry().addSupportArchives(ctx.logInputFiles()); Index: lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp =================================================================== --- lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp +++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp @@ -910,9 +910,10 @@ const char **argv = &tokens[0]; std::string errorMessage; llvm::raw_string_ostream stream(errorMessage); - bool parseFailed = !WinLinkDriver::parse(argc, argv, _ctx, stream, - /*isDirective*/ true, - undefinedSymbols); + PECOFFLinkingContext::ParseDirectives parseDirectives = + _ctx.getParseDirectives(); + bool parseFailed = !parseDirectives(argc, argv, _ctx, stream, + undefinedSymbols); stream.flush(); // Print error message if error. if (parseFailed) { Index: lld/trunk/tools/lld/CMakeLists.txt =================================================================== --- lld/trunk/tools/lld/CMakeLists.txt +++ lld/trunk/tools/lld/CMakeLists.txt @@ -4,6 +4,7 @@ target_link_libraries(lld lldDriver + LLVMSupport ) install(TARGETS lld Index: lld/trunk/unittests/DriverTests/CMakeLists.txt =================================================================== --- lld/trunk/unittests/DriverTests/CMakeLists.txt +++ lld/trunk/unittests/DriverTests/CMakeLists.txt @@ -8,4 +8,7 @@ target_link_libraries(DriverTests lldDriver + lldCore + lldPECOFF + lldMachO )