[lld] e07307b - [lld] resolve dylib paths before caching (#137649)

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 29 11:21:08 PDT 2025


Author: Richard Howell
Date: 2025-04-29T11:21:04-07:00
New Revision: e07307b53457095746aa037750a4ac2f9491d71c

URL: https://github.com/llvm/llvm-project/commit/e07307b53457095746aa037750a4ac2f9491d71c
DIFF: https://github.com/llvm/llvm-project/commit/e07307b53457095746aa037750a4ac2f9491d71c.diff

LOG: [lld] resolve dylib paths before caching (#137649)

When loading frameworks it is possible to have load commands for the
same framework through symlinks and the real path. To avoid loading
these multiple times find the real path before checking the dylib cache.

Added: 
    

Modified: 
    lld/MachO/DriverUtils.cpp

Removed: 
    


################################################################################
diff  --git a/lld/MachO/DriverUtils.cpp b/lld/MachO/DriverUtils.cpp
index 69d023c23b3c7..cf874018fa34b 100644
--- a/lld/MachO/DriverUtils.cpp
+++ b/lld/MachO/DriverUtils.cpp
@@ -229,7 +229,12 @@ static DenseMap<CachedHashStringRef, DylibFile *> loadedDylibs;
 
 DylibFile *macho::loadDylib(MemoryBufferRef mbref, DylibFile *umbrella,
                             bool isBundleLoader, bool explicitlyLinked) {
-  CachedHashStringRef path(mbref.getBufferIdentifier());
+  // Frameworks can be found from 
diff erent 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());
   DylibFile *&file = loadedDylibs[path];
   if (file) {
     if (explicitlyLinked)


        


More information about the llvm-commits mailing list