summaryrefslogtreecommitdiffstats
path: root/lld/lib
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2015-01-16 20:48:46 +0000
committerRui Ueyama <ruiu@google.com>2015-01-16 20:48:46 +0000
commit6d176f88eac8830f79f3bd4107934142857398d3 (patch)
treea77d03351597720df6a793c945f8ba161fae17d3 /lld/lib
parent3b047e0ee5f0bf58d8d9ecfa4760bcc24be3297d (diff)
downloadbcm5719-llvm-6d176f88eac8830f79f3bd4107934142857398d3.tar.gz
bcm5719-llvm-6d176f88eac8830f79f3bd4107934142857398d3.zip
[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. llvm-svn: 226319
Diffstat (limited to 'lld/lib')
-rw-r--r--lld/lib/Driver/WinLinkDriver.cpp2
-rw-r--r--lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.cpp4
-rw-r--r--lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h23
-rw-r--r--lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp53
4 files changed, 36 insertions, 46 deletions
diff --git a/lld/lib/Driver/WinLinkDriver.cpp b/lld/lib/Driver/WinLinkDriver.cpp
index afd5b6601fa..fc593a9625e 100644
--- a/lld/lib/Driver/WinLinkDriver.cpp
+++ b/lld/lib/Driver/WinLinkDriver.cpp
@@ -1414,7 +1414,6 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
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, const char *argv[],
File *f = file.get();
ctx.getTaskGroup().spawn([f] { f->parse(); });
}
- ctx.getResolvableSymsFile()->add(file.get());
ctx.addLibraryFile(llvm::make_unique<FileNode>(std::move(file)));
}
}
diff --git a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.cpp b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.cpp
index 9825912a2ae..a11410784b8 100644
--- a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.cpp
+++ b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.cpp
@@ -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 + '@';
diff --git a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
index ac295455ca3..81e306a9081 100644
--- a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
+++ b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
@@ -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;
};
diff --git a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
index e7e07f1a51d..dbe0244843e 100644
--- a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
+++ b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
@@ -78,6 +78,29 @@ bool PECOFFLinkingContext::validateImpl(raw_ostream &diagnostics) {
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::addLibraryFile(std::unique_ptr<FileNode> file) {
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::createImplicitFiles(
// 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(PassManager &pm) {
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
OpenPOWER on IntegriCloud