diff --git a/lld/MachO/DriverUtils.cpp b/lld/MachO/DriverUtils.cpp --- a/lld/MachO/DriverUtils.cpp +++ b/lld/MachO/DriverUtils.cpp @@ -186,20 +186,32 @@ depTracker->logFileNotFound(path); } +static DenseMap resolvedDylibs; std::optional macho::resolveDylibPath(StringRef dylibPath) { + CachedHashStringRef key(dylibPath); + auto entry = resolvedDylibs.find(key); + if (entry != resolvedDylibs.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; path::replace_extension(tbdPath, ".tbd"); bool tbdExists = fs::exists(tbdPath); searchedDylib(tbdPath, tbdExists); - if (tbdExists) - return saver().save(tbdPath.str()); + if (tbdExists) { + StringRef file = saver().save(tbdPath.str()); + resolvedDylibs[key] = file; + return file; + } bool dylibExists = fs::exists(dylibPath); searchedDylib(dylibPath, dylibExists); - if (dylibExists) - return saver().save(dylibPath); + if (dylibExists) { + StringRef file = saver().save(dylibPath); + resolvedDylibs[key] = file; + return file; + } return {}; } @@ -253,7 +265,10 @@ return newFile; } -void macho::resetLoadedDylibs() { loadedDylibs.clear(); } +void macho::resetLoadedDylibs() { + resolvedDylibs.clear(); + loadedDylibs.clear(); +} std::optional macho::findPathCombination(const Twine &name,