[PATCH] D113147: [lld-macho] Fix an assertion failure when -u specifies an undefined section$start symbol
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 3 14:41:42 PDT 2021
MaskRay created this revision.
MaskRay added reviewers: lld-macho, thakis.
Herald added a reviewer: gkm.
Herald added a project: lld-macho.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This matches ld64. Also improve the test for `-dead_strip`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D113147
Files:
lld/MachO/SymbolTable.cpp
lld/test/MachO/start-end.s
Index: lld/test/MachO/start-end.s
===================================================================
--- lld/test/MachO/start-end.s
+++ lld/test/MachO/start-end.s
@@ -67,6 +67,13 @@
## Test that the link succeeds with dead-stripping enabled too.
# RUN: %lld -dead_strip -lSystem %t/main.o -o %t/stripped.out
+# RUN: llvm-objdump --macho --syms --section-headers %t/stripped.out > %t-stripped-dump.txt
+# RUN: llvm-objdump --macho -d --no-symbolic-operands --no-show-raw-insn %t/stripped.out >> %t-stripped-dump.txt
+# RUN: FileCheck --check-prefix=STRIP %s < %t-stripped-dump.txt
+
+## -u 'section$start$*' does not cause an undefined symbol error. This matches ld64.
+# RUN: %lld -dead_strip -lSystem %t/main.o -u 'section$start$__FOO$__bar' -o %t/stripped1.out
+# RUN: cmp %t/stripped.out %t/stripped1.out
## (Fun fact: `-e 'section$start$__TEXT$__text -dead_strip` strips
## everything in the text section because markLive runs well before
@@ -76,6 +83,28 @@
## and the output program crashes when running. This matches ld64's
## behavior.)
+# STRIP-LABEL: Sections:
+# STRIP-NEXT: Idx Name Size VMA Type
+# STRIP-NEXT: 0 __text {{[0-9a-f]*}} [[#%x, TEXTSTART:]] TEXT
+# STRIP-NEXT: 1 __cstring 00000000 [[#%x, CSTRINGSTART:]] DATA
+# STRIP-NEXT: 2 __data 00000000
+# STRIP-NEXT: 3 __llvm_orderfile 00000000
+# STRIP-NEXT: 4 __mybss 00000000
+# STRIP-NEXT: 5 __bar 00000000
+# STRIP-NEXT: 6 __ever 00000000
+# STRIP-NEXT: 7 __lookup 00000000
+# STRIP-NEXT: 8 symbol 00000000
+# STRIP-NEXT: 9 __quux 00000000
+
+# STRIP-LABEL: SYMBOL TABLE:
+# STRIP-NOT: section$start$__FOO$__bar
+
+# STRIP-LABEL: _main:
+# STRIP: [[#%x, PC1:]]:
+# STRIP-SAME: leaq [[#%d, TEXTSTART - PC1 - 7]](%rip), %rax
+# STRIP-NEXT: [[#%x, PC2:]]:
+# STRIP-SAME: leaq [[#%d, CSTRINGSTART - PC2 - 7]](%rip), %rbx
+
# CHECK-LABEL: Sections:
# CHECK-NEXT: Idx Name Size VMA Type
# CHECK: 0 __text {{[0-9a-f]*}} [[#%x, TEXTSTART:]] TEXT
Index: lld/MachO/SymbolTable.cpp
===================================================================
--- lld/MachO/SymbolTable.cpp
+++ lld/MachO/SymbolTable.cpp
@@ -236,7 +236,6 @@
// This runs after markLive() and is only called for Undefineds that are
// live. Marking the isec live ensures an OutputSection is created that the
// start/end symbol can refer to.
- assert(sym.isLive());
isec->live = true;
// This runs after gatherInputSections(), so need to explicitly set parent
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113147.384590.patch
Type: text/x-patch
Size: 2616 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211103/b4573728/attachment.bin>
More information about the llvm-commits
mailing list