[lld] 5d9aafc - [lld-macho] Bind re-exported symbols directly to implicitly-linked umbrellas

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 4 11:37:08 PST 2021


Author: Jez Ng
Date: 2021-03-04T14:36:44-05:00
New Revision: 5d9aafc09ab5ddc4c205609e9ea4a8a9fa8186bb

URL: https://github.com/llvm/llvm-project/commit/5d9aafc09ab5ddc4c205609e9ea4a8a9fa8186bb
DIFF: https://github.com/llvm/llvm-project/commit/5d9aafc09ab5ddc4c205609e9ea4a8a9fa8186bb.diff

LOG: [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

Added: 
    

Modified: 
    lld/MachO/InputFiles.cpp
    lld/test/MachO/implicit-dylibs.s

Removed: 
    


################################################################################
diff  --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index e33cae8d6218..d754568406a3 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -669,7 +669,7 @@ DylibFile::DylibFile(MemoryBufferRef mb, DylibFile *umbrella,
       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 @@ DylibFile::DylibFile(const InterfaceFile &interface, DylibFile *umbrella,
       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/lld/test/MachO/implicit-dylibs.s b/lld/test/MachO/implicit-dylibs.s
index 5d01fadcdc63..f9568f79ad65 100644
--- a/lld/test/MachO/implicit-dylibs.s
+++ b/lld/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
 


        


More information about the llvm-commits mailing list