diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -80,16 +80,30 @@ } } +static DenseMap resolvedLibraries; static Optional findLibrary(StringRef name) { - if (config->searchDylibsFirst) { - if (Optional path = findPathCombination( - "lib" + name, config->librarySearchPaths, {".tbd", ".dylib"})) - return path; + CachedHashStringRef key(name); + auto entry = resolvedLibraries.find(key); + if (entry != resolvedLibraries.end()) + return entry->second; + + auto doFind = [&] { + if (config->searchDylibsFirst) { + if (Optional path = findPathCombination( + "lib" + name, config->librarySearchPaths, {".tbd", ".dylib"})) + return path; + return findPathCombination("lib" + name, config->librarySearchPaths, + {".a"}); + } return findPathCombination("lib" + name, config->librarySearchPaths, - {".a"}); - } - return findPathCombination("lib" + name, config->librarySearchPaths, - {".tbd", ".dylib", ".a"}); + {".tbd", ".dylib", ".a"}); + }; + + Optional path = doFind(); + if (path) + resolvedLibraries[key] = *path; + + return path; } static DenseMap resolvedPaths;