[lld] [lld] handle re-exports for full framework paths (PR #137989)

Daniel Rodríguez Troitiño via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 30 13:53:24 PDT 2025


================
@@ -1566,6 +1566,25 @@ static DylibFile *loadDylib(StringRef path, DylibFile *umbrella) {
   return loadDylib(*mbref, umbrella);
 }
 
+static StringRef findFramework(StringRef path, StringRef frameworkName) {
+  // Framework names can be in multiple formats:
+  // - Foo.framework/Foo
+  // - Foo.framework/Versions/A/Foo
+  size_t start;
+  size_t end = path.size();
+  while (true) {
+    start = path.rfind('/', end);
+    if (start == StringRef::npos)
+      return StringRef();
+
+    StringRef component = path.substr(start + 1, end - start - 1);
+    if (component == frameworkName)
+      return path.substr(start + 1);
+
+    end = start;
+  }
----------------
drodriguez wrote:

I think you can just do a `rfind` for the complete thing, maybe even avoiding the need of a function and discussions about function names.

```
start = path.rfind(frameworkName + "/", end);
if (start == StringRef::npos)
  return StrinfRef();
return path.substr(start);
```

(you might even move the calculation of `frameworkName` inside the function , since it is not used again in the caller, just pass in the `stem`).

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


More information about the llvm-commits mailing list