[PATCH] D105781: [lld/mac] Use normal Undefined machinery for dyld_stub_binder lookup
Nico Weber via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 11 09:49:59 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG10e28a748493: [lld/mac] Use normal Undefined machinery for dyld_stub_binder lookup (authored by thakis).
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D105781/new/
https://reviews.llvm.org/D105781
Files:
lld/MachO/SyntheticSections.cpp
lld/test/MachO/dyld-stub-binder.s
Index: lld/test/MachO/dyld-stub-binder.s
===================================================================
--- /dev/null
+++ lld/test/MachO/dyld-stub-binder.s
@@ -0,0 +1,59 @@
+# REQUIRES: aarch64
+# RUN: rm -rf %t; split-file %s %t
+# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %t/foo.s -o %t/foo.o
+# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %t/bar.s -o %t/bar.o
+# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %t/test.s -o %t/test.o
+
+## Dylibs that don't do lazy dynamic calls don't need dyld_stub_binder.
+# RUN: %lld -arch arm64 -dylib %t/foo.o -o %t/libfoo.dylib
+# RUN: llvm-nm -m %t/libfoo.dylib | FileCheck --check-prefix=NOSTUB %s
+
+## Dylibs that do lazy dynamic calls do need dyld_stub_binder.
+# RUN: not %lld -arch arm64 -dylib %t/bar.o %t/libfoo.dylib \
+# RUN: -o %t/libbar.dylib 2>&1 | FileCheck --check-prefix=MISSINGSTUB %s
+# RUN: %lld -arch arm64 -lSystem -dylib %t/bar.o %t/libfoo.dylib \
+# RUN: -o %t/libbar.dylib
+# RUN: llvm-nm -m %t/libbar.dylib | FileCheck --check-prefix=STUB %s
+
+## As do executables.
+# RUN: not %lld -arch arm64 %t/libfoo.dylib %t/libbar.dylib %t/test.o \
+# RUN: -o %t/test 2>&1 | FileCheck --check-prefix=MISSINGSTUB %s
+# RUN: %lld -arch arm64 -lSystem %t/libfoo.dylib %t/libbar.dylib %t/test.o \
+# RUN: -o %t/test
+# RUN: llvm-nm -m %t/test | FileCheck --check-prefix=STUB %s
+
+## Test dynamic lookup of dyld_stub_binder.
+# RUN: %lld -arch arm64 %t/libfoo.dylib %t/libbar.dylib %t/test.o \
+# RUN: -o %t/test -undefined dynamic_lookup
+# RUN: llvm-nm -m %t/test | FileCheck --check-prefix=DYNSTUB %s
+# RUN: %lld -arch arm64 %t/libfoo.dylib %t/libbar.dylib %t/test.o \
+# RUN: -o %t/test -U dyld_stub_binder
+# RUN: llvm-nm -m %t/test | FileCheck --check-prefix=DYNSTUB %s
+
+# MISSINGSTUB: error: undefined symbol: dyld_stub_binder
+# MISSINGSTUB-NEXT: >>> referenced by lazy binding (normally in libSystem.dylib)
+
+# NOSTUB-NOT: dyld_stub_binder
+# STUB: (undefined) external dyld_stub_binder (from libSystem)
+# DYNSTUB: (undefined) external dyld_stub_binder (dynamically looked up)
+
+#--- foo.s
+.globl _foo
+_foo:
+
+#--- bar.s
+.text
+.globl _bar
+_bar:
+ bl _foo
+ ret
+
+#--- test.s
+.text
+.globl _main
+
+.p2align 2
+_main:
+ bl _foo
+ bl _bar
+ ret
Index: lld/MachO/SyntheticSections.cpp
===================================================================
--- lld/MachO/SyntheticSections.cpp
+++ lld/MachO/SyntheticSections.cpp
@@ -497,13 +497,17 @@
}
void StubHelperSection::setup() {
- stubBinder = dyn_cast_or_null<DylibSymbol>(symtab->find("dyld_stub_binder"));
- if (stubBinder == nullptr) {
- error("symbol dyld_stub_binder not found (normally in libSystem.dylib). "
- "Needed to perform lazy binding.");
+ Symbol *binder = symtab->addUndefined("dyld_stub_binder", /*file=*/nullptr,
+ /*isWeakRef=*/false);
+ if (auto *undefined = dyn_cast<Undefined>(binder))
+ treatUndefinedSymbol(*undefined,
+ "lazy binding (normally in libSystem.dylib)");
+
+ // treatUndefinedSymbol() can replace binder with a DylibSymbol; re-check.
+ stubBinder = dyn_cast_or_null<DylibSymbol>(binder);
+ if (stubBinder == nullptr)
return;
- }
- stubBinder->reference(RefState::Strong);
+
in.got->addEntry(stubBinder);
inputSections.push_back(in.imageLoaderCache);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105781.357808.patch
Type: text/x-patch
Size: 3392 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210711/dfc0661a/attachment.bin>
More information about the llvm-commits
mailing list