[lld] r231395 - Resolver: Update preload map after File::beforeLink().
Rui Ueyama
ruiu at google.com
Thu Mar 5 11:25:58 PST 2015
Author: ruiu
Date: Thu Mar 5 13:25:58 2015
New Revision: 231395
URL: http://llvm.org/viewvc/llvm-project?rev=231395&view=rev
Log:
Resolver: Update preload map after File::beforeLink().
We maintain a map from symbols to archive files for the archive file
pre-loading. That map is created at the beginning of the resolve()
and is never updated. However, the input file list may be updated by
File::beforeLink(). This is a patch to update the map after beforeLink.
Modified:
lld/trunk/include/lld/Core/Resolver.h
lld/trunk/lib/Core/Resolver.cpp
Modified: lld/trunk/include/lld/Core/Resolver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Resolver.h?rev=231395&r1=231394&r2=231395&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Resolver.h (original)
+++ lld/trunk/include/lld/Core/Resolver.h Thu Mar 5 13:25:58 2015
@@ -18,6 +18,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include <set>
+#include <unordered_set>
#include <vector>
namespace lld {
@@ -64,7 +65,7 @@ private:
void maybeAddSectionGroupOrGnuLinkOnce(const DefinedAtom &atom);
/// \brief The main function that iterates over the files to resolve
- void makePreloadArchiveMap();
+ void updatePreloadArchiveMap();
bool resolveUndefines();
void updateReferences();
void deadStripOptimize();
@@ -99,6 +100,7 @@ private:
// Preloading
std::map<StringRef, ArchiveLibraryFile *> _archiveMap;
+ std::unordered_set<ArchiveLibraryFile *> _archiveSeen;
};
} // namespace lld
Modified: lld/trunk/lib/Core/Resolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Resolver.cpp?rev=231395&r1=231394&r2=231395&view=diff
==============================================================================
--- lld/trunk/lib/Core/Resolver.cpp (original)
+++ lld/trunk/lib/Core/Resolver.cpp Thu Mar 5 13:25:58 2015
@@ -83,6 +83,7 @@ bool Resolver::handleArchiveFile(File &f
if (File *member = archiveFile->find(undefName, dataSymbolOnly)) {
member->setOrdinal(_ctx.getNextOrdinalAndIncrement());
member->beforeLink();
+ updatePreloadArchiveMap();
undefAdded = handleFile(*member) || undefAdded;
}
});
@@ -274,14 +275,21 @@ File *Resolver::getFile(int &index) {
return cast<FileNode>(inputs[index++].get())->getFile();
}
-// Make a map of Symbol -> ArchiveFile.
-void Resolver::makePreloadArchiveMap() {
+// Update a map of Symbol -> ArchiveFile. The map is used for speculative
+// file loading.
+void Resolver::updatePreloadArchiveMap() {
std::vector<std::unique_ptr<Node>> &nodes = _ctx.getNodes();
- for (int i = nodes.size() - 1; i >= 0; --i)
- if (auto *fnode = dyn_cast<FileNode>(nodes[i].get()))
- if (auto *archive = dyn_cast<ArchiveLibraryFile>(fnode->getFile()))
- for (StringRef sym : archive->getDefinedSymbols())
- _archiveMap[sym] = archive;
+ for (int i = nodes.size() - 1; i >= 0; --i) {
+ auto *fnode = dyn_cast<FileNode>(nodes[i].get());
+ if (!fnode)
+ continue;
+ auto *archive = dyn_cast<ArchiveLibraryFile>(fnode->getFile());
+ if (!archive || _archiveSeen.count(archive))
+ continue;
+ _archiveSeen.insert(archive);
+ for (StringRef sym : archive->getDefinedSymbols())
+ _archiveMap[sym] = archive;
+ }
}
// Keep adding atoms until _ctx.getNextFile() returns an error. This
@@ -301,6 +309,7 @@ bool Resolver::resolveUndefines() {
return false;
}
file->beforeLink();
+ updatePreloadArchiveMap();
switch (file->kind()) {
case File::kindObject:
// The same file may be visited more than once if the file is
@@ -477,7 +486,7 @@ void Resolver::removeCoalescedAwayAtoms(
}
bool Resolver::resolve() {
- makePreloadArchiveMap();
+ updatePreloadArchiveMap();
if (!resolveUndefines())
return false;
updateReferences();
More information about the llvm-commits
mailing list