Skip to content

Commit

Permalink
[lld-macho] Clear resolvedReads cache
Browse files Browse the repository at this point in the history
  • Loading branch information
keith committed Nov 5, 2021
1 parent 9714444 commit 0bce3e3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions lld/MachO/Driver.cpp
Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions lld/MachO/InputFiles.cpp
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions lld/MachO/InputFiles.h
Expand Up @@ -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"
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 0bce3e3

Please sign in to comment.