[PATCH] D147960: [lld-macho] Cache discovered dylib paths

Keith Smiley via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 10 16:55:30 PDT 2023


keith updated this revision to Diff 512286.
keith marked an inline comment as done.
keith added a comment.

Improve naming, move comment


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,15 @@
     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())
+    return entry->second;
+
   // TODO: if a tbd and dylib are both present, we should check to make sure
   // they are consistent.
   SmallString<261> tbdPath = dylibPath;
@@ -194,17 +202,15 @@
   bool tbdExists = fs::exists(tbdPath);
   searchedDylib(tbdPath, tbdExists);
   if (tbdExists)
-    return saver().save(tbdPath.str());
+    return resolvedDylibPaths[key] = saver().save(tbdPath.str());
 
   bool dylibExists = fs::exists(dylibPath);
   searchedDylib(dylibPath, dylibExists);
   if (dylibExists)
-    return saver().save(dylibPath);
+    return resolvedDylibPaths[key] = 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 +259,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.512286.patch
Type: text/x-patch
Size: 1803 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230410/3bd9b4ae/attachment.bin>


More information about the llvm-commits mailing list