[PATCH] D147960: [lld-macho] Cache discovered dylib paths
Keith Smiley via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 10 20:03:29 PDT 2023
keith updated this revision to Diff 512319.
keith marked 2 inline comments as done.
keith added a comment.
modify value
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D147960/new/
https://reviews.llvm.org/D147960
Files:
lld/MachO/DriverUtils.cpp
Index: lld/MachO/DriverUtils.cpp
===================================================================
--- lld/MachO/DriverUtils.cpp
+++ lld/MachO/DriverUtils.cpp
@@ -186,7 +186,19 @@
depTracker->logFileNotFound(path);
}
+// It's not uncommon to have multiple attempts to load a single dylib,
+// especially if it's a commonly re-exported core library.
+static DenseMap<CachedHashStringRef, StringRef> resolvedDylibPaths;
std::optional<StringRef> macho::resolveDylibPath(StringRef dylibPath) {
+ CachedHashStringRef key(dylibPath);
+ auto entry = resolvedDylibPaths.find(key);
+ if (entry != resolvedDylibPaths.end()) {
+ if (entry->second.empty())
+ return {};
+ return entry->second;
+ }
+
+ StringRef &path = resolvedDylibPaths[key];
// TODO: if a tbd and dylib are both present, we should check to make sure
// they are consistent.
SmallString<261> tbdPath = dylibPath;
@@ -194,17 +206,15 @@
bool tbdExists = fs::exists(tbdPath);
searchedDylib(tbdPath, tbdExists);
if (tbdExists)
- return saver().save(tbdPath.str());
+ return path = saver().save(tbdPath.str());
bool dylibExists = fs::exists(dylibPath);
searchedDylib(dylibPath, dylibExists);
if (dylibExists)
- return saver().save(dylibPath);
+ return path = saver().save(dylibPath);
return {};
}
-// It's not uncommon to have multiple attempts to load a single dylib,
-// especially if it's a commonly re-exported core library.
static DenseMap<CachedHashStringRef, DylibFile *> loadedDylibs;
DylibFile *macho::loadDylib(MemoryBufferRef mbref, DylibFile *umbrella,
@@ -253,7 +263,10 @@
return newFile;
}
-void macho::resetLoadedDylibs() { loadedDylibs.clear(); }
+void macho::resetLoadedDylibs() {
+ resolvedDylibPaths.clear();
+ loadedDylibs.clear();
+}
std::optional<StringRef>
macho::findPathCombination(const Twine &name,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147960.512319.patch
Type: text/x-patch
Size: 1868 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230411/20f8d78b/attachment.bin>
More information about the llvm-commits
mailing list