Skip to content

Commit 413e249

Browse files
committed
[lld-macho][nfc] Test that we don't emit undef symbol errors for dead code
This is what ld64 does too, so we have parity here (though I think ld64 still removes dead code more effectively than we do...) Reviewed By: #lld-macho, thakis Differential Revision: https://reviews.llvm.org/D112485
1 parent b12a864 commit 413e249

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

lld/test/MachO/treat-undef-sym.s

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,42 @@
11
# REQUIRES: x86
2+
# RUN: split-file %s %t
23

3-
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos %s -o %t.o
4-
# RUN: not %lld -undefined bogus -o /dev/null %t.o 2>&1 | \
4+
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos %s -o %t/live.o
5+
# RUN: not %lld -undefined bogus -o /dev/null %t/live.o 2>&1 | \
56
# RUN: FileCheck %s -check-prefix=UNKNOWN
6-
# RUN: not %lld -undefined error -o /dev/null %t.o 2>&1 | \
7+
# RUN: not %lld -undefined error -o /dev/null %t/live.o 2>&1 | \
78
# RUN: FileCheck %s -check-prefix=ERROR
89

9-
# RUN: not %lld -undefined warning -o /dev/null %t.o 2>&1 | \
10+
# RUN: not %lld -undefined warning -o /dev/null %t/live.o 2>&1 | \
1011
# RUN: FileCheck %s -check-prefix=INVAL-WARNING
11-
# RUN: not %lld -undefined suppress -o /dev/null %t.o 2>&1 | \
12+
# RUN: not %lld -undefined suppress -o /dev/null %t/live.o 2>&1 | \
1213
# RUN: FileCheck %s -check-prefix=INVAL-SUPPRESS
13-
# RUN: %lld -undefined dynamic_lookup -lSystem -o %t.out %t.o 2>&1 | count 0
14-
# RUN: llvm-objdump --macho --lazy-bind %t.out \
14+
# RUN: %lld -undefined dynamic_lookup -lSystem -o %t/live.out %t/live.o 2>&1 | count 0
15+
# RUN: llvm-objdump --macho --lazy-bind %t/live.out \
1516
# RUN: | FileCheck --check-prefix=BIND %s
1617

1718
# RUN: %no_fatal_warnings_lld -lSystem -flat_namespace -undefined warning \
18-
# RUN: -o %t.out %t.o 2>&1 | \
19+
# RUN: -o %t/live.out %t/live.o 2>&1 | \
1920
# RUN: FileCheck %s -check-prefix=WARNING
20-
# RUN: llvm-objdump --macho --lazy-bind %t.out \
21+
# RUN: llvm-objdump --macho --lazy-bind %t/live.out \
2122
# RUN: | FileCheck --check-prefix=BIND %s
22-
# RUN: %lld -flat_namespace -lSystem -undefined suppress -o %t.out %t.o 2>&1 | count 0
23-
# RUN: llvm-objdump --macho --lazy-bind %t.out \
23+
# RUN: %lld -flat_namespace -lSystem -undefined suppress -o %t/live.out %t/live.o \
24+
# RUN: 2>&1 | count 0
25+
# RUN: llvm-objdump --macho --lazy-bind %t/live.out \
2426
# RUN: | FileCheck --check-prefix=BIND %s
25-
# RUN: %lld -flat_namespace -lSystem -undefined dynamic_lookup -o %t.out %t.o 2>&1 | count 0
26-
# RUN: llvm-objdump --macho --lazy-bind %t.out \
27+
# RUN: %lld -flat_namespace -lSystem -undefined dynamic_lookup -o \
28+
# RUN: %t/live.out %t/live.o 2>&1 | count 0
29+
# RUN: llvm-objdump --macho --lazy-bind %t/live.out \
2730
# RUN: | FileCheck --check-prefix=BIND %s
2831

32+
## Undefined symbols in dead code should not raise an error iff
33+
## -dead_strip is enabled.
34+
# RUN: not %lld -dylib -undefined error -o /dev/null %t/dead.o 2>&1 \
35+
# RUN: | FileCheck --check-prefix=ERROR %s
36+
# RUN: not %lld -dylib -dead_strip -undefined error -o /dev/null %t/live.o 2>&1\
37+
# RUN: | FileCheck --check-prefix=ERROR %s
38+
# RUN: %lld -dylib -dead_strip -undefined error -o /dev/null %t/dead.o
39+
2940
# ERROR: error: undefined symbol: _bar
3041
# ERROR-NEXT: >>> referenced by
3142

@@ -45,7 +56,13 @@
4556
# BIND: Lazy bind table:
4657
# BIND: __DATA __la_symbol_ptr 0x{{[0-9a-f]*}} flat-namespace _bar
4758

59+
#--- live.s
4860
.globl _main
4961
_main:
5062
callq _bar
5163
ret
64+
65+
#--- dead.s
66+
_dead:
67+
callq _bar
68+
ret

0 commit comments

Comments
 (0)