[lld] [lld] resolve dylib paths before caching (PR #137649)
Richard Howell via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 29 08:24:03 PDT 2025
https://github.com/rmaz updated https://github.com/llvm/llvm-project/pull/137649
>From c6b421666f719f286a38303b861b98ff7f40d96c Mon Sep 17 00:00:00 2001
From: Richard Howell <rhow at meta.com>
Date: Mon, 28 Apr 2025 08:22:48 -0700
Subject: [PATCH] [lld] resolve dylib paths before caching
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.
---
lld/MachO/DriverUtils.cpp | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
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 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());
DylibFile *&file = loadedDylibs[path];
if (file) {
if (explicitlyLinked)
More information about the llvm-commits
mailing list