Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / MachO / bind-opcodes.s
blobcf294f2f7f4270ad83dd2b91c3092f1eb5fc42f8
1 # REQUIRES: x86, aarch64
2 # RUN: rm -rf %t; split-file %s %t
3 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/foo.s -o %t/foo.o
4 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin --defsym PTR64=0 %t/test.s -o %t/test.o
5 # RUN: %lld -O2 -dylib %t/foo.o -o %t/libfoo.dylib
6 # RUN: %lld -O2 -lSystem %t/test.o %t/libfoo.dylib -o %t/test-x86_64
8 ## Test (64-bit):
9 ## 1/ We emit exactly one BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM per symbol.
10 ## 2/ Combine BIND_OPCODE_DO_BIND and BIND_OPCODE_ADD_ADDR_ULEB pairs.
11 ## 3/ Compact BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
12 ## 4/ Use BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED if possible.
13 # RUN: obj2yaml %t/test-x86_64 | FileCheck %s
15 # CHECK: BindOpcodes:
16 # CHECK-NEXT: Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
17 # CHECK-NEXT: Imm: 0
18 # CHECK-NEXT: Symbol: _foo
19 # CHECK-NEXT: Opcode: BIND_OPCODE_SET_TYPE_IMM
20 # CHECK-NEXT: Imm: 1
21 # CHECK-NEXT: Symbol: ''
22 # CHECK-NEXT: Opcode: BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
23 # CHECK-NEXT: Imm: 2
24 # CHECK-NEXT: Symbol: ''
25 # CHECK-NEXT: Opcode: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
26 # CHECK-NEXT: Imm: 2
27 # CHECK-NEXT: ULEBExtraData: [ 0x0 ]
28 # CHECK-NEXT: Symbol: ''
29 # CHECK-NEXT: Opcode: BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB
30 # CHECK-NEXT: Imm: 0
31 # CHECK-NEXT: ULEBExtraData: [ 0x2, 0x8 ]
32 # CHECK-NEXT: Symbol: ''
33 # CHECK-NEXT: Opcode: BIND_OPCODE_SET_ADDEND_SLEB
34 # CHECK-NEXT: Imm: 0
35 # CHECK-NEXT: SLEBExtraData: [ 1 ]
36 # CHECK-NEXT: Symbol: ''
37 # CHECK-NEXT: Opcode: BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
38 # CHECK-NEXT: Imm: 0
39 # CHECK-NEXT: ULEBExtraData: [ 0x1008 ]
40 # CHECK-NEXT: Symbol: ''
41 # CHECK-NEXT: Opcode: BIND_OPCODE_SET_ADDEND_SLEB
42 # CHECK-NEXT: Imm: 0
43 # CHECK-NEXT: SLEBExtraData: [ 0 ]
44 # CHECK-NEXT: Symbol: ''
45 # CHECK-NEXT: Opcode: BIND_OPCODE_DO_BIND
46 # CHECK-NEXT: Imm: 0
47 # CHECK-NEXT: Symbol: ''
48 # CHECK-NEXT: Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
49 # CHECK-NEXT: Imm: 0
50 # CHECK-NEXT: Symbol: _bar
51 # CHECK-NEXT: Opcode: BIND_OPCODE_SET_TYPE_IMM
52 # CHECK-NEXT: Imm: 1
53 # CHECK-NEXT: Symbol: ''
54 # CHECK-NEXT: Opcode: BIND_OPCODE_ADD_ADDR_ULEB
55 # CHECK-NEXT: Imm: 0
56 # CHECK-NEXT: ULEBExtraData: [ 0xFFFFFFFFFFFFEFD0 ]
57 # CHECK-NEXT: Symbol: ''
58 # CHECK-NEXT: Opcode: BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED
59 # CHECK-NEXT: Imm: 1
60 # CHECK-NEXT: Symbol: ''
61 # CHECK-NEXT: Opcode: BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
62 # CHECK-NEXT: Imm: 0
63 # CHECK-NEXT: ULEBExtraData: [ 0x1008 ]
64 # CHECK-NEXT: Symbol: ''
65 # CHECK-NEXT: Opcode: BIND_OPCODE_DO_BIND
66 # CHECK-NEXT: Imm: 0
67 # CHECK-NEXT: Symbol: ''
68 # CHECK-NEXT: Opcode: BIND_OPCODE_DONE
69 # CHECK-NEXT: Imm: 0
70 # CHECK-NEXT: Symbol: ''
72 # RUN: llvm-mc -filetype=obj -triple=arm64_32-apple-darwin %t/foo.s -o %t/foo.o
73 # RUN: llvm-mc -filetype=obj -triple=arm64_32-apple-darwin --defsym PTR32=0 %t/test.s -o %t/test.o
74 # RUN: %lld-watchos -O2 -dylib %t/foo.o -o %t/libfoo.dylib
75 # RUN: %lld-watchos -O2 -dylib %t/test.o %t/libfoo.dylib -o %t/libtest-arm64_32.dylib
77 ## Test (32-bit):
78 ## 1/ We emit exactly one BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM per symbol.
79 ## 2/ Combine BIND_OPCODE_DO_BIND and BIND_OPCODE_ADD_ADDR_ULEB pairs.
80 ## 3/ Compact BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
81 ## 4/ Use BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED if possible.
82 # RUN: obj2yaml %t/libtest-arm64_32.dylib | FileCheck %s --check-prefix=CHECK32
84 # CHECK32: BindOpcodes:
85 # CHECK32-NEXT: Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
86 # CHECK32-NEXT: Imm: 0
87 # CHECK32-NEXT: Symbol: _foo
88 # CHECK32-NEXT: Opcode: BIND_OPCODE_SET_TYPE_IMM
89 # CHECK32-NEXT: Imm: 1
90 # CHECK32-NEXT: Symbol: ''
91 # CHECK32-NEXT: Opcode: BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
92 # CHECK32-NEXT: Imm: 2
93 # CHECK32-NEXT: Symbol: ''
94 # CHECK32-NEXT: Opcode: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
95 # CHECK32-NEXT: Imm: 1
96 # CHECK32-NEXT: ULEBExtraData: [ 0x0 ]
97 # CHECK32-NEXT: Symbol: ''
98 # CHECK32-NEXT: Opcode: BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB
99 # CHECK32-NEXT: Imm: 0
100 # CHECK32-NEXT: ULEBExtraData: [ 0x2, 0x4 ]
101 # CHECK32-NEXT: Symbol: ''
102 # CHECK32-NEXT: Opcode: BIND_OPCODE_SET_ADDEND_SLEB
103 # CHECK32-NEXT: Imm: 0
104 # CHECK32-NEXT: SLEBExtraData: [ 1 ]
105 # CHECK32-NEXT: Symbol: ''
106 # CHECK32-NEXT: Opcode: BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
107 # CHECK32-NEXT: Imm: 0
108 # CHECK32-NEXT: ULEBExtraData: [ 0x1004 ]
109 # CHECK32-NEXT: Symbol: ''
110 # CHECK32-NEXT: Opcode: BIND_OPCODE_SET_ADDEND_SLEB
111 # CHECK32-NEXT: Imm: 0
112 # CHECK32-NEXT: SLEBExtraData: [ 0 ]
113 # CHECK32-NEXT: Symbol: ''
114 # CHECK32-NEXT: Opcode: BIND_OPCODE_DO_BIND
115 # CHECK32-NEXT: Imm: 0
116 # CHECK32-NEXT: Symbol: ''
117 # CHECK32-NEXT: Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
118 # CHECK32-NEXT: Imm: 0
119 # CHECK32-NEXT: Symbol: _bar
120 # CHECK32-NEXT: Opcode: BIND_OPCODE_SET_TYPE_IMM
121 # CHECK32-NEXT: Imm: 1
122 # CHECK32-NEXT: Symbol: ''
123 # CHECK32-NEXT: Opcode: BIND_OPCODE_ADD_ADDR_ULEB
124 # CHECK32-NEXT: Imm: 0
125 # CHECK32-NEXT: ULEBExtraData: [ 0xFFFFFFFFFFFFEFE8 ]
126 # CHECK32-NEXT: Symbol: ''
127 # CHECK32-NEXT: Opcode: BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED
128 # CHECK32-NEXT: Imm: 1
129 # CHECK32-NEXT: Symbol: ''
130 # CHECK32-NEXT: Opcode: BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
131 # CHECK32-NEXT: Imm: 0
132 # CHECK32-NEXT: ULEBExtraData: [ 0x1004 ]
133 # CHECK32-NEXT: Symbol: ''
134 # CHECK32-NEXT: Opcode: BIND_OPCODE_DO_BIND
135 # CHECK32-NEXT: Imm: 0
136 # CHECK32-NEXT: Symbol: ''
137 # CHECK32-NEXT: Opcode: BIND_OPCODE_DONE
138 # CHECK32-NEXT: Imm: 0
139 # CHECK32-NEXT: Symbol: ''
141 # RUN: llvm-objdump --macho --bind %t/test-x86_64 | FileCheck %s -D#PTR=8 --check-prefix=BIND
142 # RUN: llvm-objdump --macho --bind %t/libtest-arm64_32.dylib | FileCheck %s -D#PTR=4 --check-prefix=BIND
143 # BIND: Bind table:
144 # BIND-NEXT: segment section address type addend dylib symbol
145 # BIND-NEXT: __DATA __data 0x[[#%X,DATA:]] pointer 0 libfoo _foo
146 # BIND-NEXT: __DATA __data 0x[[#%.8X,DATA + mul(PTR, 2)]] pointer 0 libfoo _foo
147 # BIND-NEXT: __DATA __data 0x[[#%.8X,DATA + mul(PTR, 4)]] pointer 1 libfoo _foo
148 # BIND-NEXT: __DATA __data 0x[[#%.8X,DATA + 4096 + mul(PTR, 6)]] pointer 0 libfoo _foo
149 # BIND-NEXT: __DATA __data 0x[[#%.8X,DATA + PTR]] pointer 0 libfoo _bar
150 # BIND-NEXT: __DATA __data 0x[[#%.8X,DATA + mul(PTR, 3)]] pointer 0 libfoo _bar
151 # BIND-NEXT: __DATA __data 0x[[#%.8X,DATA + 4096 + mul(PTR, 5)]] pointer 0 libfoo _bar
152 # BIND-EMPTY:
154 #--- foo.s
155 .globl _foo, _bar
156 _foo:
157 .space 4
158 _bar:
159 .space 4
161 #--- test.s
162 .ifdef PTR64
163 .macro ptr val
164 .quad \val
165 .endm
166 .endif
168 .ifdef PTR32
169 .macro ptr val
170 .int \val
171 .endm
172 .endif
174 .data
175 ptr _foo
176 ptr _bar
177 ptr _foo
178 ptr _bar
179 ptr _foo+1
180 .zero 0x1000
181 ptr _bar
182 ptr _foo
184 .globl _main
185 .text
186 _main: