[lld-macho] Bind re-exported symbols directly to implicitly-linked umbrellas
Suppose we are linking against libFoo, which re-exports the
implicitly-bound libSystem, which in turn re-exports some
non-explicitly-bound library like `/usr/lib/system/libsystem_c.dylib`.
Then any bindings we have to a symbol in libsystem_c should use
libSystem (and not libFoo) as the umbrella library.
Reviewed By: #lld-macho, smeenai
Differential Revision: https://reviews.llvm.org/D97865
GitOrigin-RevId: 5d9aafc09ab5ddc4c205609e9ea4a8a9fa8186bb
diff --git a/MachO/InputFiles.cpp b/MachO/InputFiles.cpp
index e33cae8..d754568 100644
--- a/MachO/InputFiles.cpp
+++ b/MachO/InputFiles.cpp
@@ -669,7 +669,7 @@
const auto *c = reinterpret_cast<const dylib_command *>(cmd);
StringRef reexportPath =
reinterpret_cast<const char *>(c) + read32le(&c->dylib.name);
- loadReexport(reexportPath, umbrella, nullptr);
+ loadReexport(reexportPath, exportingFile, nullptr);
}
// FIXME: What about LC_LOAD_UPWARD_DYLIB, LC_LAZY_LOAD_DYLIB,
@@ -741,7 +741,7 @@
interface.getParent() == nullptr ? &interface : interface.getParent();
for (InterfaceFileRef intfRef : interface.reexportedLibraries())
- loadReexport(intfRef.getInstallName(), umbrella, topLevel);
+ loadReexport(intfRef.getInstallName(), exportingFile, topLevel);
}
ArchiveFile::ArchiveFile(std::unique_ptr<object::Archive> &&f)
diff --git a/test/MachO/implicit-dylibs.s b/test/MachO/implicit-dylibs.s
index 5d01fad..f9568f7 100644
--- a/test/MachO/implicit-dylibs.s
+++ b/test/MachO/implicit-dylibs.s
@@ -24,7 +24,7 @@
# RUN: %lld -dylib -lSystem %t/libunused.o -o %t/usr/lib/libunused.dylib -install_name /usr/lib/libunused.dylib
## Bar.framework is nested within Foo.framework.
-# RUN: %lld -dylib -lSystem %t/framework-baz.o -o %t/System/Library/Frameworks/Foo.framework/Frameworks/Bar.framework/Versions/A/Bar \
+# RUN: %lld -dylib -lSystem %t/framework-bar.o -o %t/System/Library/Frameworks/Foo.framework/Frameworks/Bar.framework/Versions/A/Bar \
# RUN: -install_name /System/Library/Frameworks/Foo.framework/Frameworks/Bar.framework/Versions/A/Bar
# RUN: ln -sf %t/System/Library/Frameworks/Foo.framework/Frameworks/Bar.framework/Versions/A/Bar \
# RUN: %t/System/Library/Frameworks/Foo.framework/Frameworks/Bar.framework/Bar
@@ -35,7 +35,7 @@
# RUN: -install_name /System/Library/Frameworks/Foo.framework/Versions/A/Foo
# RUN: ln -sf %t/System/Library/Frameworks/Foo.framework/Versions/A/Foo %t/System/Library/Frameworks/Foo.framework/Foo
-# RUN: %lld -dylib -lSystem %t/framework-bar.o -o %t/Baz.framework/Versions/A/Baz \
+# RUN: %lld -dylib -lSystem %t/framework-baz.o -o %t/Baz.framework/Versions/A/Baz \
# RUN: -install_name %t/Baz.framework/Versions/A/Baz
# RUN: ln -sf %t/Baz.framework/Versions/A/Baz %t/Baz.framework/Baz
@@ -54,7 +54,7 @@
# CHECK-DAG: __DATA __data {{.*}} pointer 0 libtoplevel _toplevel
# CHECK-DAG: __DATA __data {{.*}} pointer 0 libreexporter _sublevel
# CHECK-DAG: __DATA __data {{.*}} pointer 0 Foo _framework_foo
-# CHECK-DAG: __DATA __data {{.*}} pointer 0 libreexporter _framework_bar
+# CHECK-DAG: __DATA __data {{.*}} pointer 0 Foo _framework_bar
# CHECK-DAG: __DATA __data {{.*}} pointer 0 libreexporter _framework_baz
# CHECK-DAG: __DATA __data {{.*}} pointer 0 libc++abi ___gxx_personality_v0