[lld] 005456e - [lld-macho] Fix an assertion failure when -u specifies an undefined section$start symbol
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 4 21:28:39 PDT 2021
Author: Fangrui Song
Date: 2021-11-04T21:28:33-07:00
New Revision: 005456e5fc67f05a3df8f099f3856c6ac049304f
URL: https://github.com/llvm/llvm-project/commit/005456e5fc67f05a3df8f099f3856c6ac049304f
DIFF: https://github.com/llvm/llvm-project/commit/005456e5fc67f05a3df8f099f3856c6ac049304f.diff
LOG: [lld-macho] Fix an assertion failure when -u specifies an undefined section$start symbol
This matches ld64. Also improve the test for `-dead_strip`.
Reviewed By: #lld-macho, Jez Ng
Differential Revision: https://reviews.llvm.org/D113147
Added:
Modified:
lld/MachO/MarkLive.cpp
lld/test/MachO/start-end.s
Removed:
################################################################################
diff --git a/lld/MachO/MarkLive.cpp b/lld/MachO/MarkLive.cpp
index 4b6e2315b942c..e4aba8fb90d42 100644
--- a/lld/MachO/MarkLive.cpp
+++ b/lld/MachO/MarkLive.cpp
@@ -96,8 +96,7 @@ void markLive() {
}
// -u symbols
for (Symbol *sym : config->explicitUndefineds)
- if (auto *defined = dyn_cast<Defined>(sym))
- addSym(defined);
+ addSym(sym);
// local symbols explicitly marked .no_dead_strip
for (const InputFile *file : inputFiles)
if (auto *objFile = dyn_cast<ObjFile>(file))
diff --git a/lld/test/MachO/start-end.s b/lld/test/MachO/start-end.s
index 86e1d900bf3d5..3ca0048939b07 100644
--- a/lld/test/MachO/start-end.s
+++ b/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$__notexist' -o %t/stripped1.out
+# RUN: llvm-objdump --section-headers %t/stripped1.out | FileCheck --check-prefix=STRIP2 %s
## (Fun fact: `-e 'section$start$__TEXT$__text -dead_strip` strips
## everything in the text section because markLive runs well before
@@ -76,6 +83,42 @@
## 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
+
+# STRIP2-LABEL: Sections:
+# STRIP2-NEXT: Idx Name Size VMA Type
+# STRIP2-NEXT: 0 __text {{[0-9a-f]*}} [[#%x, TEXTSTART:]] TEXT
+# STRIP2-NEXT: 1 __cstring 00000000 [[#%x, CSTRINGSTART:]] DATA
+# STRIP2-NEXT: 2 __data 00000000
+# STRIP2-NEXT: 3 __llvm_orderfile 00000000
+# STRIP2-NEXT: 4 __mybss 00000000
+# STRIP2-NEXT: 5 __bar 00000000
+# STRIP2-NEXT: 6 __notexist 00000000
+# STRIP2-NEXT: 7 __ever 00000000
+# STRIP2-NEXT: 8 __lookup 00000000
+# STRIP2-NEXT: 9 symbol 00000000
+# STRIP2-NEXT: 10 __quux 00000000
+
# CHECK-LABEL: Sections:
# CHECK-NEXT: Idx Name Size VMA Type
# CHECK: 0 __text {{[0-9a-f]*}} [[#%x, TEXTSTART:]] TEXT
More information about the llvm-commits
mailing list