diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -1100,6 +1100,7 @@ resolvedFrameworks.clear(); resolvedLibraries.clear(); + cachedReads.clear(); concatOutputSections.clear(); inputFiles.clear(); inputSections.clear(); diff --git a/lld/MachO/InputFiles.h b/lld/MachO/InputFiles.h --- a/lld/MachO/InputFiles.h +++ b/lld/MachO/InputFiles.h @@ -14,6 +14,7 @@ #include "lld/Common/LLVM.h" #include "lld/Common/Memory.h" +#include "llvm/ADT/CachedHashString.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/SetVector.h" #include "llvm/BinaryFormat/MachO.h" @@ -211,6 +212,7 @@ }; extern llvm::SetVector inputFiles; +extern llvm::DenseMap cachedReads; llvm::Optional readFile(StringRef path); diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -178,12 +178,12 @@ // level, and other files like the filelist that are only read once. // Theoretically this caching could be more efficient by hoisting it, but that // would require altering many callers to track the state. -static DenseMap resolvedReads; +DenseMap macho::cachedReads; // Open a given file path and return it as a memory-mapped file. Optional macho::readFile(StringRef path) { CachedHashStringRef key(path); - auto entry = resolvedReads.find(key); - if (entry != resolvedReads.end()) + auto entry = cachedReads.find(key); + if (entry != cachedReads.end()) return entry->second; ErrorOr> mbOrErr = MemoryBuffer::getFile(path); @@ -203,7 +203,7 @@ read32be(&hdr->magic) != FAT_MAGIC) { if (tar) tar->append(relativeToRoot(path), mbref.getBuffer()); - return resolvedReads[key] = mbref; + return cachedReads[key] = mbref; } // Object files and archive files may be fat files, which contain multiple @@ -228,8 +228,8 @@ error(path + ": slice extends beyond end of file"); if (tar) tar->append(relativeToRoot(path), mbref.getBuffer()); - return resolvedReads[key] = MemoryBufferRef(StringRef(buf + offset, size), - path.copy(bAlloc)); + return cachedReads[key] = MemoryBufferRef(StringRef(buf + offset, size), + path.copy(bAlloc)); } error("unable to find matching architecture in " + path);