[PATCH] D102143: [lld-macho] Treat an undefined entry symbol like any other undefined
Jez Ng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun May 9 17:29:30 PDT 2021
int3 updated this revision to Diff 343943.
int3 added a comment.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D102143/new/
https://reviews.llvm.org/D102143
Files:
lld/MachO/Driver.cpp
lld/MachO/Writer.cpp
lld/test/MachO/entry-symbol.s
Index: lld/test/MachO/entry-symbol.s
===================================================================
--- lld/test/MachO/entry-symbol.s
+++ lld/test/MachO/entry-symbol.s
@@ -22,7 +22,11 @@
# CHECK-NEXT: entryoff [[#ENTRYOFF]]
# RUN: %lld -lSystem -o %t/dysym-main %t/not-main.o %t/libfoo.dylib -e _dysym_main
-# RUN: llvm-objdump --macho --all-headers --indirect-symbols --lazy-bind %t/dysym-main | FileCheck %s --check-prefix=DYSYM
+# RUN: llvm-objdump --macho --all-headers --indirect-symbols --lazy-bind %t/dysym-main | FileCheck %s --check-prefix=DYSYM -DDYLIB=libfoo
+
+# RUN: %lld -lSystem -o %t/dyn-lookup %t/not-main.o -e _dysym_main -undefined dynamic_lookup
+# RUN: llvm-objdump --macho --all-headers --indirect-symbols --lazy-bind %t/dyn-lookup | FileCheck %s --check-prefix=DYSYM -DDYLIB=flat-namespace
+
# DYSYM-LABEL: Indirect symbols for (__TEXT,__stubs) 1 entries
# DYSYM-NEXT: address index name
# DYSYM-NEXT: 0x[[#%x,DYSYM_ENTRY_ADDR:]] [[#]] _dysym_main
@@ -30,8 +34,8 @@
# DYSYM-NEXT: cmdsize 24
# DYSYM-NEXT: entryoff [[#%u, DYSYM_ENTRY_ADDR - 0x100000000]]
# DYSYM-LABEL: Lazy bind table:
-# DYSYM-NEXT: segment section address dylib symbol
-# DYSYM-NEXT: __DATA __la_symbol_ptr {{.*}} libfoo _dysym_main
+# DYSYM-NEXT: segment section address dylib symbol
+# DYSYM-NEXT: __DATA __la_symbol_ptr {{.*}} [[DYLIB]] _dysym_main
# RUN: %lld -lSystem -o %t/weak-dysym-main %t/not-main.o %t/libfoo.dylib -e _weak_dysym_main
# RUN: llvm-objdump --macho --all-headers --indirect-symbols --bind --weak-bind %t/weak-dysym-main | FileCheck %s --check-prefix=WEAK-DYSYM
@@ -42,8 +46,8 @@
# WEAK-DYSYM-NEXT: cmdsize 24
# WEAK-DYSYM-NEXT: entryoff [[#%u, DYSYM_ENTRY_ADDR - 0x100000000]]
# WEAK-DYSYM-LABEL: Bind table:
-# WEAK-DYSYM-NEXT: segment section address type addend dylib symbol
-# WEAK-DYSYM: __DATA __la_symbol_ptr {{.*}} pointer 0 libfoo _weak_dysym_main
+# WEAK-DYSYM-NEXT: segment section address type addend dylib symbol
+# WEAK-DYSYM: __DATA __la_symbol_ptr {{.*}} pointer 0 libfoo _weak_dysym_main
# WEAK-DYSYM-LABEL: Weak bind table:
# WEAK-DYSYM-NEXT: segment section address type addend symbol
# WEAK-DYSYM-NEXT: __DATA __la_symbol_ptr {{.*}} pointer 0 _weak_dysym_main
Index: lld/MachO/Writer.cpp
===================================================================
--- lld/MachO/Writer.cpp
+++ lld/MachO/Writer.cpp
@@ -1049,8 +1049,13 @@
}
template <class LP> void Writer::run() {
- if (config->entry)
- prepareBranchTarget(config->entry);
+ if (config->entry) {
+ if (auto *undefined = dyn_cast<Undefined>(config->entry))
+ treatUndefinedSymbol(*undefined);
+ if (!isa<Undefined>(config->entry))
+ prepareBranchTarget(config->entry);
+ }
+
scanRelocations();
if (in.stubHelper->isNeeded())
in.stubHelper->setup();
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -1138,10 +1138,6 @@
if (!orderFile.empty())
parseOrderFile(orderFile);
- if (config->outputType == MH_EXECUTE && isa<Undefined>(config->entry)) {
- error("undefined symbol: " + toString(*config->entry));
- return false;
- }
// FIXME: This prints symbols that are undefined both in input files and
// via -u flag twice.
for (const Symbol *undefined : config->explicitUndefineds) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102143.343943.patch
Type: text/x-patch
Size: 3601 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210510/c045ccf4/attachment.bin>
More information about the llvm-commits
mailing list