[lld] [lld] check cache before real_path in loadDylib (PR #140791)
Daniel RodrÃguez Troitiño via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 10 12:06:48 PDT 2025
================
@@ -229,19 +229,31 @@ static DenseMap<CachedHashStringRef, DylibFile *> loadedDylibs;
DylibFile *macho::loadDylib(MemoryBufferRef mbref, DylibFile *umbrella,
bool isBundleLoader, bool explicitlyLinked) {
- // Frameworks can be found from different symlink paths, so resolve
- // symlinks before looking up in the dylib cache.
- SmallString<128> realPath;
- std::error_code err = fs::real_path(mbref.getBufferIdentifier(), realPath);
- CachedHashStringRef path(!err ? uniqueSaver().save(StringRef(realPath))
- : mbref.getBufferIdentifier());
+ CachedHashStringRef path(mbref.getBufferIdentifier());
DylibFile *&file = loadedDylibs[path];
if (file) {
if (explicitlyLinked)
file->setExplicitlyLinked();
return file;
}
+ // Frameworks can be found from different symlink paths, so resolve
+ // symlinks and look up in the dylib cache.
+ DylibFile *&realfile = file;
+ SmallString<128> realPath;
+ std::error_code err = fs::real_path(mbref.getBufferIdentifier(), realPath);
+ if (!err) {
+ CachedHashStringRef resolvedPath(uniqueSaver().save(StringRef(realPath)));
+ realfile = loadedDylibs[resolvedPath];
+ if (realfile) {
+ if (explicitlyLinked)
+ realfile->setExplicitlyLinked();
+
+ file = realfile;
----------------
drodriguez wrote:
We should not have added that line then.
I found this about references to `unordered_map` being invalidated: https://eel.is/c++draft/unord.req#general-9 (emphasis mine)
> Rehashing invalidates iterators, changes ordering between elements, and changes which buckets elements appear in, but **does not invalidate pointers or references** to elements
I am not sure if `llvm::DenseMap` follows all the rules of `std::unordered_map`, but that little bit might be something they forgot to keep compatible.
https://github.com/llvm/llvm-project/pull/140791
More information about the llvm-commits
mailing list