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,29 @@ } } +static DenseMap resolvedLibraries; static Optional findLibrary(StringRef name) { + CachedHashStringRef key(name); + auto entry = resolvedLibraries.find(key); + if (entry != resolvedLibraries.end()) + return entry->second; + if (config->searchDylibsFirst) { if (Optional path = findPathCombination( - "lib" + name, config->librarySearchPaths, {".tbd", ".dylib"})) + "lib" + name, config->librarySearchPaths, {".tbd", ".dylib"})) { + resolvedLibraries[key] = *path; return path; - return findPathCombination("lib" + name, config->librarySearchPaths, - {".a"}); + } + auto path = + findPathCombination("lib" + name, config->librarySearchPaths, {".a"}); + if (path) + resolvedLibraries[key] = *path; + return path; } - return findPathCombination("lib" + name, config->librarySearchPaths, - {".tbd", ".dylib", ".a"}); + auto path = findPathCombination("lib" + name, config->librarySearchPaths, + {".tbd", ".dylib", ".a"}); + resolvedLibraries[key] = *path; + return path; } static DenseMap resolvedPaths;