[lld] r226319 - [PECOFF] Remove ResolvableSymbols to simplify.
Rui Ueyama
ruiu at google.com
Fri Jan 16 12:48:46 PST 2015
Author: ruiu
Date: Fri Jan 16 14:48:46 2015
New Revision: 226319
URL: http://llvm.org/viewvc/llvm-project?rev=226319&view=rev
Log:
[PECOFF] Remove ResolvableSymbols to simplify.
We had such class there because of InputGraph abstraction.
Previously, no one except InputGraph itself has complete picture of
input file list. In order to create a set of all defined symbols,
we had to use some indirections there to workaround InputGraph.
It can now be rewritten as simple code. No change in functionality.
Modified:
lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
lld/trunk/lib/Driver/WinLinkDriver.cpp
lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.cpp
lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
Modified: lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h?rev=226319&r1=226318&r2=226319&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h Fri Jan 16 14:48:46 2015
@@ -30,28 +30,6 @@ static const uint8_t DEFAULT_DOS_STUB[12
namespace lld {
-namespace pecoff {
-class ResolvableSymbols {
-public:
- void add(File *file);
-
- const std::set<std::string> &defined() {
- readAllSymbols();
- return _defined;
- }
-
-private:
- // Files are read lazily, so that it has no runtime overhead if
- // no one accesses this class.
- void readAllSymbols();
-
- std::set<std::string> _defined;
- std::set<File *> _seen;
- std::set<File *> _queue;
- std::mutex _mutex;
-};
-} // end namespace pecoff
-
class PECOFFLinkingContext : public LinkingContext {
public:
PECOFFLinkingContext()
@@ -119,6 +97,9 @@ public:
return _machineType == llvm::COFF::IMAGE_FILE_MACHINE_AMD64;
}
+ // Returns a set of all defined symbols in input files.
+ const std::set<std::string> &definedSymbols();
+
/// Page size of x86 processor. Some data needs to be aligned at page boundary
/// when loaded into memory.
uint64_t getPageSize() const {
@@ -345,10 +326,6 @@ public:
std::recursive_mutex &getMutex() { return _mutex; }
- pecoff::ResolvableSymbols *getResolvableSymsFile() {
- return &_resolvableSyms;
- }
-
protected:
/// Method to create a internal file for the entry symbol
std::unique_ptr<File> createEntrySymbolFile() const override;
@@ -461,7 +438,8 @@ private:
// only.
std::string _moduleDefinitionFile;
- pecoff::ResolvableSymbols _resolvableSyms;
+ std::set<std::string> _definedSyms;
+ std::set<Node *> _seen;
};
} // end namespace lld
Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=226319&r1=226318&r2=226319&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Fri Jan 16 14:48:46 2015
@@ -1414,7 +1414,6 @@ bool WinLinkDriver::parse(int argc, cons
File *f = file.get();
ctx.getTaskGroup().spawn([f] { f->parse(); });
}
- ctx.getResolvableSymsFile()->add(file.get());
ctx.getNodes().push_back(llvm::make_unique<FileNode>(std::move(file)));
}
@@ -1431,7 +1430,6 @@ bool WinLinkDriver::parse(int argc, cons
File *f = file.get();
ctx.getTaskGroup().spawn([f] { f->parse(); });
}
- ctx.getResolvableSymsFile()->add(file.get());
ctx.addLibraryFile(llvm::make_unique<FileNode>(std::move(file)));
}
}
Modified: lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.cpp?rev=226319&r1=226318&r2=226319&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.cpp Fri Jan 16 14:48:46 2015
@@ -13,9 +13,9 @@ namespace lld {
namespace pecoff {
// Find decorated symbol, namely /sym@[0-9]+/ or /\?sym@@.+/.
-bool findDecoratedSymbol(PECOFFLinkingContext *ctx, ResolvableSymbols *syms,
+bool findDecoratedSymbol(PECOFFLinkingContext *ctx,
std::string sym, std::string &res) {
- const std::set<std::string> &defined = syms->defined();
+ const std::set<std::string> &defined = ctx->definedSymbols();
// Search for /sym@[0-9]+/
{
std::string s = sym + '@';
Modified: lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h?rev=226319&r1=226318&r2=226319&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h Fri Jan 16 14:48:46 2015
@@ -20,8 +20,7 @@ using llvm::COFF::WindowsSubsystem;
namespace lld {
namespace pecoff {
-class ResolvableSymbols;
-bool findDecoratedSymbol(PECOFFLinkingContext *ctx, ResolvableSymbols *syms,
+bool findDecoratedSymbol(PECOFFLinkingContext *ctx,
std::string sym, std::string &res);
namespace impl {
@@ -206,9 +205,8 @@ private:
// next visit.
class ExportedSymbolRenameFile : public impl::VirtualArchiveLibraryFile {
public:
- ExportedSymbolRenameFile(const PECOFFLinkingContext &ctx,
- ResolvableSymbols *syms)
- : VirtualArchiveLibraryFile("<export>"), _syms(syms),
+ ExportedSymbolRenameFile(const PECOFFLinkingContext &ctx)
+ : VirtualArchiveLibraryFile("<export>"),
_ctx(const_cast<PECOFFLinkingContext *>(&ctx)) {
for (PECOFFLinkingContext::ExportDesc &desc : _ctx->getDllExports())
_exportedSyms.insert(desc.name);
@@ -219,7 +217,7 @@ public:
if (_exportedSyms.count(sym) == 0)
return nullptr;
std::string replace;
- if (!findDecoratedSymbol(_ctx, _syms, sym.str(), replace))
+ if (!findDecoratedSymbol(_ctx, sym.str(), replace))
return nullptr;
for (ExportDesc &exp : _ctx->getDllExports())
@@ -232,7 +230,6 @@ public:
private:
std::set<std::string> _exportedSyms;
- ResolvableSymbols *_syms;
mutable llvm::BumpPtrAllocator _alloc;
mutable PECOFFLinkingContext *_ctx;
};
@@ -244,10 +241,9 @@ private:
// http://msdn.microsoft.com/en-us/library/f9t8842e.aspx
class EntryPointFile : public SimpleFile {
public:
- EntryPointFile(const PECOFFLinkingContext &ctx,
- ResolvableSymbols *syms)
+ EntryPointFile(const PECOFFLinkingContext &ctx)
: SimpleFile("<entry>"), _ctx(const_cast<PECOFFLinkingContext *>(&ctx)),
- _syms(syms), _firstTime(true) {}
+ _firstTime(true) {}
const atom_collection<UndefinedAtom> &undefined() const override {
return const_cast<EntryPointFile *>(this)->getUndefinedAtoms();
@@ -277,7 +273,7 @@ private:
StringRef opt = _ctx->getEntrySymbolName();
if (!opt.empty()) {
std::string mangled;
- if (findDecoratedSymbol(_ctx, _syms, opt, mangled))
+ if (findDecoratedSymbol(_ctx, opt, mangled))
return mangled;
return _ctx->decorateSymbol(opt);
}
@@ -299,10 +295,10 @@ private:
// Returns true if a given name exists in an input object file.
auto defined = [&](StringRef name) -> bool {
StringRef sym = _ctx->decorateSymbol(name);
- if (_syms->defined().count(sym))
+ if (_ctx->definedSymbols().count(sym))
return true;
std::string ignore;
- return findDecoratedSymbol(_ctx, _syms, sym, ignore);
+ return findDecoratedSymbol(_ctx, sym, ignore);
};
switch (_ctx->getSubsystem()) {
@@ -333,7 +329,6 @@ private:
PECOFFLinkingContext *_ctx;
atom_collection_vector<UndefinedAtom> _undefinedAtoms;
std::mutex _mutex;
- ResolvableSymbols *_syms;
llvm::BumpPtrAllocator _alloc;
bool _firstTime;
};
Modified: lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp?rev=226319&r1=226318&r2=226319&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp Fri Jan 16 14:48:46 2015
@@ -78,6 +78,29 @@ bool PECOFFLinkingContext::validateImpl(
return true;
}
+const std::set<std::string> &PECOFFLinkingContext::definedSymbols() {
+ std::lock_guard<std::recursive_mutex> lock(_mutex);
+ for (std::unique_ptr<Node> &node : getNodes()) {
+ if (_seen.count(node.get()) > 0)
+ continue;
+ FileNode *fnode = dyn_cast<FileNode>(node.get());
+ if (!fnode)
+ continue;
+ File *file = fnode->getFile();
+ if (file->parse())
+ continue;
+ if (auto *archive = dyn_cast<ArchiveLibraryFile>(file)) {
+ for (const std::string &sym : archive->getDefinedSymbols())
+ _definedSyms.insert(sym);
+ continue;
+ }
+ for (const DefinedAtom *atom : file->defined())
+ if (!atom->name().empty())
+ _definedSyms.insert(atom->name());
+ }
+ return _definedSyms;
+}
+
std::unique_ptr<File> PECOFFLinkingContext::createEntrySymbolFile() const {
return LinkingContext::createEntrySymbolFile("<command line option /entry>");
}
@@ -112,12 +135,11 @@ void PECOFFLinkingContext::addLibraryFil
bool PECOFFLinkingContext::createImplicitFiles(
std::vector<std::unique_ptr<File>> &) {
- pecoff::ResolvableSymbols* syms = getResolvableSymsFile();
std::vector<std::unique_ptr<Node>> &members = getNodes();
// Create a file for the entry point function.
std::unique_ptr<FileNode> entry(new FileNode(
- llvm::make_unique<pecoff::EntryPointFile>(*this, syms)));
+ llvm::make_unique<pecoff::EntryPointFile>(*this)));
members.insert(members.begin() + getGroupStartPos(members), std::move(entry));
// Create a file for __ImageBase.
@@ -132,7 +154,7 @@ bool PECOFFLinkingContext::createImplici
// Create a file for dllexported symbols.
std::unique_ptr<FileNode> exportNode(new FileNode(
- llvm::make_unique<pecoff::ExportedSymbolRenameFile>(*this, syms)));
+ llvm::make_unique<pecoff::ExportedSymbolRenameFile>(*this)));
addLibraryFile(std::move(exportNode));
return true;
@@ -335,29 +357,4 @@ void PECOFFLinkingContext::addPasses(Pas
pm.add(std::unique_ptr<Pass>(new pecoff::InferSubsystemPass(*this)));
}
-void pecoff::ResolvableSymbols::add(File *file) {
- std::lock_guard<std::mutex> lock(_mutex);
- if (_seen.count(file) > 0)
- return;
- _seen.insert(file);
- _queue.insert(file);
-}
-
-void pecoff::ResolvableSymbols::readAllSymbols() {
- std::lock_guard<std::mutex> lock(_mutex);
- for (File *file : _queue) {
- if (file->parse())
- return;
- if (auto *archive = dyn_cast<ArchiveLibraryFile>(file)) {
- for (const std::string &sym : archive->getDefinedSymbols())
- _defined.insert(sym);
- continue;
- }
- for (const DefinedAtom *atom : file->defined())
- if (!atom->name().empty())
- _defined.insert(atom->name());
- }
- _queue.clear();
-}
-
} // end namespace lld
More information about the llvm-commits
mailing list