diff --git a/lld/MachO/DriverUtils.cpp b/lld/MachO/DriverUtils.cpp --- a/lld/MachO/DriverUtils.cpp +++ b/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 resolvedDylibPaths; std::optional 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 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 macho::findPathCombination(const Twine &name,