[lld] [lld] resolve dylib paths before caching (PR #137649)
Richard Howell via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 28 13:42:24 PDT 2025
https://github.com/rmaz updated https://github.com/llvm/llvm-project/pull/137649
>From c0dd69e0d2b9922920bf33483775ebc502b97eaa 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 | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/lld/MachO/DriverUtils.cpp b/lld/MachO/DriverUtils.cpp
index 69d023c23b3c7..bfd8357ea50d1 100644
--- a/lld/MachO/DriverUtils.cpp
+++ b/lld/MachO/DriverUtils.cpp
@@ -26,6 +26,7 @@
#include "llvm/Support/Path.h"
#include "llvm/TextAPI/InterfaceFile.h"
#include "llvm/TextAPI/TextAPIReader.h"
+#include <system_error>
using namespace llvm;
using namespace llvm::MachO;
@@ -229,7 +230,13 @@ 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.value() == 0
+ ? uniqueSaver().save(StringRef(realPath))
+ : mbref.getBufferIdentifier());
DylibFile *&file = loadedDylibs[path];
if (file) {
if (explicitlyLinked)
More information about the llvm-commits
mailing list