[lld] [lld] check cache in loadDylib before real_path (PR #143595)

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 12 01:39:00 PDT 2025


================
@@ -225,21 +225,44 @@ std::optional<StringRef> macho::resolveDylibPath(StringRef dylibPath) {
 // especially if it's a commonly re-exported core library.
 static DenseMap<CachedHashStringRef, DylibFile *> loadedDylibs;
 
+static StringRef realPathIfDifferent(StringRef path) {
+  SmallString<128> realPathBuf;
+  std::error_code err = fs::real_path(path, realPathBuf);
+  if (err)
+    return StringRef();
+
+  StringRef realPath(realPathBuf);
+  SmallString<128> absPathBuf = path;
+  err = fs::make_absolute(absPathBuf);
+  if (!err && realPath == StringRef(absPathBuf))
----------------
zmodem wrote:

Here too you could fold the `make_absolute` call into the if condition.

Also, I think you could check `realPathBuf == absPathBuf` directly.

In fact, maybe the split into `realPathBuf` and `realPath` and `absPathBuf` and `absPath` is unnecessary. It would be simpler to just use the SmallString's, and convert to StringRef only when necessary, which I think is only when passing it to the string saver (and then it might convert implicitly?).

https://github.com/llvm/llvm-project/pull/143595


More information about the llvm-commits mailing list