Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / MachO / flat-namespace-dysyms.s
blob2ac3b2979efd5070c3c17f2d5462e4cca0842fb4
1 # REQUIRES: x86
2 # RUN: rm -rf %t; split-file %s %t
4 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t/foo.o %t/foo.s
5 # RUN: %lld -dylib -o %t/foo.dylib %t/foo.o
7 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t/bar.o %t/bar.s
8 # RUN: %lld -lSystem -dylib -o %t/bar.dylib %t/bar.o %t/foo.dylib
10 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t/baz.o %t/baz.s
11 # RUN: %lld -lSystem -dylib -o %t/baz.dylib %t/baz.o %t/bar.dylib
13 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t/main.o %t/main.s
15 ## With flat_namespace, the linker automatically looks in foo.dylib and
16 ## bar.dylib too, but it doesn't add a LC_LOAD_DYLIB for it.
17 # RUN: %lld -flat_namespace -lSystem %t/main.o %t/baz.dylib -o %t/out -t \
18 # RUN: --reproduce %t/repro.tar | FileCheck --check-prefix=T %s
19 ## FIXME: The `bar.dylib` line should use `T-NEXT`, but on Windows we load
20 ## libSystem.tbd with different slash styles and end up loading it twice
21 ## for that reason.
22 # T: main.o
23 # T-NEXT: baz.dylib
24 # T: bar.dylib
25 # T-NEXT: foo.dylib
26 # RUN: llvm-objdump --macho --all-headers %t/out \
27 # RUN: | FileCheck --check-prefix=HEADERBITS %s
28 # RUN: llvm-objdump --macho --bind --lazy-bind --weak-bind %t/out \
29 # RUN: | FileCheck --check-prefix=FLAT %s
30 # RUN: llvm-nm -m %t/out | FileCheck --check-prefix=FLATSYM %s
31 # RUN: llvm-readobj --syms %t/out | FileCheck --check-prefix=FLATSYM-READOBJ %s
32 # RUN: cd %t
33 # RUN: tar -tf repro.tar | FileCheck -DPATH='%:t.dir' --check-prefix=REPRO %s
34 # RUN: tar -xf repro.tar repro/response.txt
35 # RUN: FileCheck --implicit-check-not=dylib --check-prefix=RESPONSE %s \
36 # RUN: < %t/repro/response.txt
38 # HEADERBITS-NOT: NOUNDEFS
39 # HEADERBITS-NOT: TWOLEVEL
40 # HEADERBITS: DYLDLINK
41 # HEADERBITS-NOT: foo.dylib
42 # HEADERBITS-NOT: bar.dylib
44 # FLAT: Bind table:
45 # FLAT: __DATA_CONST __got 0x{{[0-9a-f]*}} pointer 0 flat-namespace dyld_stub_binder
46 # FLAT: Lazy bind table:
47 # FLAT-DAG: __DATA __la_symbol_ptr 0x{{[0-9a-f]*}} flat-namespace _bar
48 # FLAT-DAG: __DATA __la_symbol_ptr 0x{{[0-9a-f]*}} flat-namespace _baz
49 # FLAT-DAG: __DATA __la_symbol_ptr 0x{{[0-9a-f]*}} flat-namespace _foo
51 ## No "(dynamically looked up)" because llvm-nm -m doesn't print that
52 ## for files without MH_TWOLEVEL for some reason.
53 # FLATSYM: (undefined) external _bar
54 # FLATSYM: (undefined) external _baz
55 # FLATSYM: (undefined) external _foo
57 ## ...but `llvm-readobj --syms` does, so verify we put the right thing there.
58 # FLATSYM-READOBJ: Flags [ (0xFE00)
60 ## All 3 .dylibs should be in a --reproduce archive.
61 # REPRO: baz.dylib
62 # REPRO: bar.dylib
63 # REPRO: foo.dylib
65 ## ...but only baz.dylib should be in the response file:
66 # RESPONSE: baz.dylib
68 # Undefined symbols should still cause errors by default.
69 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
70 # RUN: -o %t/main-with-undef.o %t/main-with-undef.s
71 # RUN: not %lld -flat_namespace -lSystem %t/main-with-undef.o %t/bar.dylib \
72 # RUN: -o %t/out 2>&1 | FileCheck --check-prefix=UNDEF %s
73 # UNDEF: error: undefined symbol: _quux
75 #--- foo.s
76 .globl _foo
77 _foo:
78 ret
80 #--- bar.s
81 .globl _bar
82 _bar:
83 callq _foo
84 ret
86 #--- baz.s
87 .globl _baz
88 _baz:
89 callq _bar
90 ret
92 #--- main.s
93 .globl _main
94 _main:
95 callq _foo
96 callq _bar
97 callq _baz
98 ret
100 #--- main-with-undef.s
101 .globl _main
102 _main:
103 callq _foo
104 callq _bar
105 callq _baz
106 callq _quux