[lld] 0bce3e3 - [lld-macho] Clear resolvedReads cache
Keith Smiley via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 4 18:08:50 PDT 2021
Author: Keith Smiley
Date: 2021-11-04T18:02:34-07:00
New Revision: 0bce3e3b843f205e085b635c0e1ebc28c5c6d708
URL: https://github.com/llvm/llvm-project/commit/0bce3e3b843f205e085b635c0e1ebc28c5c6d708
DIFF: https://github.com/llvm/llvm-project/commit/0bce3e3b843f205e085b635c0e1ebc28c5c6d708.diff
LOG: [lld-macho] Clear resolvedReads cache
https://reviews.llvm.org/D113153#3108083
smeenai, int3
Differential Revision: https://reviews.llvm.org/D113198
Added:
Modified:
lld/MachO/Driver.cpp
lld/MachO/InputFiles.cpp
lld/MachO/InputFiles.h
Removed:
################################################################################
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 255f0f2520da..5aa19a7cfbda 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1100,6 +1100,7 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
resolvedFrameworks.clear();
resolvedLibraries.clear();
+ cachedReads.clear();
concatOutputSections.clear();
inputFiles.clear();
inputSections.clear();
diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 8d76116eec50..361f24a8531b 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -178,12 +178,12 @@ static bool checkCompatibility(const InputFile *input) {
// 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<CachedHashStringRef, MemoryBufferRef> resolvedReads;
+DenseMap<CachedHashStringRef, MemoryBufferRef> macho::cachedReads;
// Open a given file path and return it as a memory-mapped file.
Optional<MemoryBufferRef> 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<std::unique_ptr<MemoryBuffer>> mbOrErr = MemoryBuffer::getFile(path);
@@ -203,7 +203,7 @@ Optional<MemoryBufferRef> macho::readFile(StringRef path) {
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 @@ Optional<MemoryBufferRef> macho::readFile(StringRef path) {
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);
diff --git a/lld/MachO/InputFiles.h b/lld/MachO/InputFiles.h
index e51e5d557d3b..e5f12ad9c6d9 100644
--- 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 @@ class BitcodeFile final : public InputFile {
};
extern llvm::SetVector<InputFile *> inputFiles;
+extern llvm::DenseMap<llvm::CachedHashStringRef, MemoryBufferRef> cachedReads;
llvm::Optional<MemoryBufferRef> readFile(StringRef path);
More information about the llvm-commits
mailing list