diff --git a/lld/include/lld/Core/LinkingContext.h b/lld/include/lld/Core/LinkingContext.h index d6f7bea0362e..2b40bbadaf9b 100644 --- a/lld/include/lld/Core/LinkingContext.h +++ b/lld/include/lld/Core/LinkingContext.h @@ -323,9 +323,11 @@ protected: /// Method to create a internal file for the entry symbol virtual std::unique_ptr createEntrySymbolFile() const; + std::unique_ptr createEntrySymbolFile(StringRef filename) const; /// Method to create a internal file for an undefined symbol virtual std::unique_ptr createUndefinedSymbolFile() const; + std::unique_ptr createUndefinedSymbolFile(StringRef filename) const; StringRef _outputPath; StringRef _entrySymbolName; diff --git a/lld/lib/Core/LinkingContext.cpp b/lld/lib/Core/LinkingContext.cpp index a9072103d8ea..8ac6f591253a 100644 --- a/lld/lib/Core/LinkingContext.cpp +++ b/lld/lib/Core/LinkingContext.cpp @@ -43,20 +43,28 @@ bool LinkingContext::createImplicitFiles( } std::unique_ptr LinkingContext::createEntrySymbolFile() const { + return createEntrySymbolFile("command line option -u"); +} + +std::unique_ptr +LinkingContext::createEntrySymbolFile(StringRef filename) const { if (entrySymbolName().empty()) return nullptr; - std::unique_ptr entryFile( - new SimpleFile("command line option -entry")); + std::unique_ptr entryFile(new SimpleFile(filename)); entryFile->addAtom( *(new (_allocator) SimpleUndefinedAtom(*entryFile, entrySymbolName()))); return std::move(entryFile); } std::unique_ptr LinkingContext::createUndefinedSymbolFile() const { + return createUndefinedSymbolFile("command line option -u"); +} + +std::unique_ptr +LinkingContext::createUndefinedSymbolFile(StringRef filename) const { if (_initialUndefinedSymbols.empty()) return nullptr; - std::unique_ptr undefinedSymFile( - new SimpleFile("command line option -u")); + std::unique_ptr undefinedSymFile(new SimpleFile(filename)); for (auto undefSymStr : _initialUndefinedSymbols) undefinedSymFile->addAtom(*(new (_allocator) SimpleUndefinedAtom( *undefinedSymFile, undefSymStr))); diff --git a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp index 936b5fdd08c8..c5c683331909 100644 --- a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp +++ b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp @@ -97,24 +97,11 @@ bool PECOFFLinkingContext::validateImpl(raw_ostream &diagnostics) { } std::unique_ptr PECOFFLinkingContext::createEntrySymbolFile() const { - if (entrySymbolName().empty()) - return nullptr; - std::unique_ptr entryFile( - new SimpleFile("command line option /entry")); - entryFile->addAtom( - *(new (_allocator) SimpleUndefinedAtom(*entryFile, entrySymbolName()))); - return std::move(entryFile); + return LinkingContext::createEntrySymbolFile("command line option /entry"); } std::unique_ptr PECOFFLinkingContext::createUndefinedSymbolFile() const { - if (_initialUndefinedSymbols.empty()) - return nullptr; - std::unique_ptr undefinedSymFile( - new SimpleFile("command line option /include")); - for (auto undefSymStr : _initialUndefinedSymbols) - undefinedSymFile->addAtom(*(new (_allocator) SimpleUndefinedAtom( - *undefinedSymFile, undefSymStr))); - return std::move(undefinedSymFile); + return LinkingContext::createUndefinedSymbolFile("command line option /include"); } bool PECOFFLinkingContext::createImplicitFiles(