diff --git a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h index 131d55d18d9c..14576e2695fb 100644 --- a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h +++ b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h @@ -232,14 +232,13 @@ private: // next visit. class ExportedSymbolRenameFile : public impl::VirtualArchiveLibraryFile { public: - ExportedSymbolRenameFile(const PECOFFLinkingContext &ctx) - : VirtualArchiveLibraryFile("") { + ExportedSymbolRenameFile(const PECOFFLinkingContext &ctx, + std::shared_ptr syms) + : VirtualArchiveLibraryFile(""), _syms(syms) { for (const PECOFFLinkingContext::ExportDesc &desc : ctx.getDllExports()) _exportedSyms.insert(desc.name); } - void addResolvableSymbols(File *file) { _syms.add(file); } - const File *find(StringRef sym, bool dataSymbolOnly) const override { if (_exportedSyms.count(sym) == 0) return nullptr; @@ -254,7 +253,7 @@ private: // by @number suffix. bool findSymbolWithAtsignSuffix(std::string sym, std::string &res) const { sym.append("@"); - const std::set &defined = _syms.defined(); + const std::set &defined = _syms->defined(); auto it = defined.lower_bound(sym); for (auto e = defined.end(); it != e; ++it) { if (!StringRef(*it).startswith(sym)) @@ -271,7 +270,7 @@ private: } std::set _exportedSyms; - mutable ResolvableSymbols _syms; + mutable std::shared_ptr _syms; mutable llvm::BumpPtrAllocator _alloc; }; diff --git a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp index 67cc919d6530..0ac986937850 100644 --- a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp +++ b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp @@ -119,14 +119,15 @@ bool PECOFFLinkingContext::createImplicitFiles( getInputGraph().insertElementAt(std::move(impFileNode), InputGraph::Position::END); + std::shared_ptr syms( + new pecoff::ResolvableSymbols()); + getInputGraph().registerObserver([=](File *file) { syms->add(file); }); + // Create a file for dllexported symbols. std::unique_ptr exportNode(new SimpleFileNode("")); - pecoff::ExportedSymbolRenameFile *renameFile = - new pecoff::ExportedSymbolRenameFile(*this); + auto *renameFile = new pecoff::ExportedSymbolRenameFile(*this, syms); exportNode->appendInputFile(std::unique_ptr(renameFile)); getLibraryGroup()->addFile(std::move(exportNode)); - getInputGraph().registerObserver( - [=](File *file) { renameFile->addResolvableSymbols(file); }); return true; }