1# REQUIRES: arm
2# RUN: ld64.lld -arch armv7 -r -print_atoms %s -o %t  | FileCheck %s
3# RUN: ld64.lld -arch armv7 -dylib -print_atoms %t -o %t2 \
4# RUN:     %p/Inputs/armv7/libSystem.yaml -sectalign __TEXT __text 0x1000  | FileCheck %s
5# RUN: llvm-objdump -d --macho --no-symbolic-operands %t2 | FileCheck --check-prefix=CODE %s
6#
7# Test thumb and arm branches round trip through -r.
8# Test movw/movt pairs have low bit set properly for thumb vs arm.
9#
10#
11
12--- !mach-o
13arch:            armv7
14file-type:       MH_OBJECT
15flags:           [ MH_SUBSECTIONS_VIA_SYMBOLS ]
16sections:
17  - segment:         __TEXT
18    section:         __text
19    type:            S_REGULAR
20    attributes:      [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ]
21    alignment:       2
22    address:         0x0000000000000000
23    content:         [ 0x40, 0xF2, 0x25, 0x00, 0xC0, 0xF2, 0x00, 0x00,
24                       0x40, 0xF2, 0x01, 0x01, 0xC0, 0xF2, 0x00, 0x01,
25                       0x40, 0xF2, 0x4E, 0x02, 0xC0, 0xF2, 0x00, 0x02,
26                       0x40, 0xF2, 0x2A, 0x03, 0xC0, 0xF2, 0x00, 0x03,
27                       0x78, 0x44, 0x70, 0x47, 0x70, 0x47, 0x25, 0x00,
28                       0x00, 0xE3, 0x00, 0x00, 0x40, 0xE3, 0xD7, 0x1F,
29                       0x0F, 0xE3, 0xFF, 0x1F, 0x4F, 0xE3, 0x4E, 0x20,
30                       0x00, 0xE3, 0x00, 0x20, 0x40, 0xE3, 0x00, 0x30,
31                       0x00, 0xE3, 0x00, 0x30, 0x40, 0xE3, 0x0F, 0x00,
32                       0x80, 0xE0, 0x1E, 0xFF, 0x2F, 0xE1, 0x1E, 0xFF,
33                       0x2F, 0xE1 ]
34    relocations:
35      - offset:          0x00000042
36        scattered:       true
37        type:            ARM_RELOC_HALF_SECTDIFF
38        length:          1
39        pc-rel:          false
40        value:           0x0000004E
41      - offset:          0x00000000
42        scattered:       true
43        type:            ARM_RELOC_PAIR
44        length:          1
45        pc-rel:          false
46        value:           0x00000046
47      - offset:          0x0000003E
48        scattered:       true
49        type:            ARM_RELOC_HALF_SECTDIFF
50        length:          0
51        pc-rel:          false
52        value:           0x0000004E
53      - offset:          0x00000000
54        scattered:       true
55        type:            ARM_RELOC_PAIR
56        length:          0
57        pc-rel:          false
58        value:           0x00000046
59      - offset:          0x0000003A
60        type:            ARM_RELOC_HALF
61        length:          1
62        pc-rel:          false
63        extern:          false
64        symbol:          1
65      - offset:          0x0000004E
66        type:            ARM_RELOC_PAIR
67        length:          1
68        pc-rel:          false
69        extern:          false
70        symbol:          16777215
71      - offset:          0x00000036
72        type:            ARM_RELOC_HALF
73        length:          0
74        pc-rel:          false
75        extern:          false
76        symbol:          1
77      - offset:          0x00000000
78        type:            ARM_RELOC_PAIR
79        length:          0
80        pc-rel:          false
81        extern:          false
82        symbol:          16777215
83      - offset:          0x00000032
84        scattered:       true
85        type:            ARM_RELOC_HALF_SECTDIFF
86        length:          1
87        pc-rel:          false
88        value:           0x00000024
89      - offset:          0x0000FFD6
90        scattered:       true
91        type:            ARM_RELOC_PAIR
92        length:          1
93        pc-rel:          false
94        value:           0x00000046
95      - offset:          0x0000002E
96        scattered:       true
97        type:            ARM_RELOC_HALF_SECTDIFF
98        length:          0
99        pc-rel:          false
100        value:           0x00000024
101      - offset:          0x0000FFFF
102        scattered:       true
103        type:            ARM_RELOC_PAIR
104        length:          0
105        pc-rel:          false
106        value:           0x00000046
107      - offset:          0x0000002A
108        type:            ARM_RELOC_HALF
109        length:          1
110        pc-rel:          false
111        extern:          false
112        symbol:          1
113      - offset:          0x00000025
114        type:            ARM_RELOC_PAIR
115        length:          1
116        pc-rel:          false
117        extern:          false
118        symbol:          16777215
119      - offset:          0x00000026
120        type:            ARM_RELOC_HALF
121        length:          0
122        pc-rel:          false
123        extern:          false
124        symbol:          1
125      - offset:          0x00000000
126        type:            ARM_RELOC_PAIR
127        length:          0
128        pc-rel:          false
129        extern:          false
130        symbol:          16777215
131      - offset:          0x0000001C
132        scattered:       true
133        type:            ARM_RELOC_HALF_SECTDIFF
134        length:          3
135        pc-rel:          false
136        value:           0x0000004E
137      - offset:          0x0000002A
138        scattered:       true
139        type:            ARM_RELOC_PAIR
140        length:          3
141        pc-rel:          false
142        value:           0x00000020
143      - offset:          0x00000018
144        scattered:       true
145        type:            ARM_RELOC_HALF_SECTDIFF
146        length:          2
147        pc-rel:          false
148        value:           0x0000004E
149      - offset:          0x00000000
150        scattered:       true
151        type:            ARM_RELOC_PAIR
152        length:          2
153        pc-rel:          false
154        value:           0x00000020
155      - offset:          0x00000014
156        type:            ARM_RELOC_HALF
157        length:          3
158        pc-rel:          false
159        extern:          false
160        symbol:          1
161      - offset:          0x0000004E
162        type:            ARM_RELOC_PAIR
163        length:          3
164        pc-rel:          false
165        extern:          false
166        symbol:          16777215
167      - offset:          0x00000010
168        type:            ARM_RELOC_HALF
169        length:          2
170        pc-rel:          false
171        extern:          false
172        symbol:          1
173      - offset:          0x00000000
174        type:            ARM_RELOC_PAIR
175        length:          2
176        pc-rel:          false
177        extern:          false
178        symbol:          16777215
179      - offset:          0x0000000C
180        scattered:       true
181        type:            ARM_RELOC_HALF_SECTDIFF
182        length:          3
183        pc-rel:          false
184        value:           0x00000024
185      - offset:          0x00000000
186        scattered:       true
187        type:            ARM_RELOC_PAIR
188        length:          3
189        pc-rel:          false
190        value:           0x00000020
191      - offset:          0x00000008
192        scattered:       true
193        type:            ARM_RELOC_HALF_SECTDIFF
194        length:          2
195        pc-rel:          false
196        value:           0x00000024
197      - offset:          0x00000000
198        scattered:       true
199        type:            ARM_RELOC_PAIR
200        length:          2
201        pc-rel:          false
202        value:           0x00000020
203      - offset:          0x00000004
204        type:            ARM_RELOC_HALF
205        length:          3
206        pc-rel:          false
207        extern:          false
208        symbol:          1
209      - offset:          0x00000025
210        type:            ARM_RELOC_PAIR
211        length:          3
212        pc-rel:          false
213        extern:          false
214        symbol:          16777215
215      - offset:          0x00000000
216        type:            ARM_RELOC_HALF
217        length:          2
218        pc-rel:          false
219        extern:          false
220        symbol:          1
221      - offset:          0x00000000
222        type:            ARM_RELOC_PAIR
223        length:          2
224        pc-rel:          false
225        extern:          false
226        symbol:          16777215
227local-symbols:
228  - name:            _t1
229    type:            N_SECT
230    sect:            1
231    desc:            [ N_ARM_THUMB_DEF ]
232    value:           0x0000000000000000
233  - name:            _t2
234    type:            N_SECT
235    sect:            1
236    desc:            [ N_ARM_THUMB_DEF ]
237    value:           0x0000000000000024
238  - name:            _a2
239    type:            N_SECT
240    sect:            1
241    value:           0x000000000000004E
242  - name:            _a1
243    type:            N_SECT
244    sect:            1
245    value:           0x0000000000000026
246...
247
248# CHECK: defined-atoms:
249# CHECK:   - name:            _t1
250# CHECK:     references:
251# CHECK:       - kind:            modeThumbCode
252# CHECK:         offset:          0
253# CHECK:         target:          _t1
254# CHECK:       - kind:            thumb_movw
255# CHECK:         offset:          0
256# CHECK:         target:          _t2
257# CHECK-NOT:     addend:
258# CHECK:       - kind:            thumb_movt
259# CHECK:         offset:          4
260# CHECK:         target:          _t2
261# CHECK-NOT:     addend:
262# CHECK:       - kind:            thumb_movw_funcRel
263# CHECK:         offset:          8
264# CHECK:         target:          _t2
265# CHECK:         addend:          -36
266# CHECK:       - kind:            thumb_movt_funcRel
267# CHECK:         offset:          12
268# CHECK:         target:          _t2
269# CHECK:         addend:          -36
270# CHECK:       - kind:            thumb_movw
271# CHECK:         offset:          16
272# CHECK:         target:          _a2
273# CHECK-NOT:     addend:
274# CHECK:       - kind:            thumb_movt
275# CHECK:         offset:          20
276# CHECK:         target:          _a2
277# CHECK-NOT:     addend:
278# CHECK:       - kind:            thumb_movw_funcRel
279# CHECK:         offset:          24
280# CHECK:         target:          _a2
281# CHECK:         addend:          -36
282# CHECK:       - kind:            thumb_movt_funcRel
283# CHECK:         offset:          28
284# CHECK:         target:          _a2
285# CHECK:         addend:          -36
286# CHECK:   - name:            _t2
287# CHECK:     references:
288# CHECK:       - kind:            modeThumbCode
289# CHECK:         offset:          0
290# CHECK:         target:          _t2
291# CHECK:   - name:            _a1
292# CHECK:     references:
293# CHECK:       - kind:            arm_movw
294# CHECK:         offset:          0
295# CHECK:         target:          _t2
296# CHECK-NOT:     addend:
297# CHECK:       - kind:            arm_movt
298# CHECK:         offset:          4
299# CHECK:         target:          _t2
300# CHECK-NOT:     addend:
301# CHECK:       - kind:            arm_movw_funcRel
302# CHECK:         offset:          8
303# CHECK:         target:          _t2
304# CHECK:         addend:          -40
305# CHECK:       - kind:            arm_movt_funcRel
306# CHECK:         offset:          12
307# CHECK:         target:          _t2
308# CHECK:         addend:          -40
309# CHECK:       - kind:            arm_movw
310# CHECK:         offset:          16
311# CHECK:         target:          _a2
312# CHECK-NOT:     addend:
313# CHECK:       - kind:            arm_movt
314# CHECK:         offset:          20
315# CHECK:         target:          _a2
316# CHECK-NOT:     addend:
317# CHECK:       - kind:            arm_movw_funcRel
318# CHECK:         offset:          24
319# CHECK:         target:          _a2
320# CHECK:         addend:          -40
321# CHECK:       - kind:            arm_movt_funcRel
322# CHECK:         offset:          28
323# CHECK:         target:          _a2
324# CHECK:         addend:          -40
325# CHECK:   - name:            _a2
326
327
328# CODE: _t1:
329# CODE-NEXT:                 	 movw	r0, #4133
330# CODE-NEXT:                   movt	r0, #0
331# CODE-NEXT:                   movw	r1, #1
332# CODE-NEXT:                   movt	r1, #0
333# CODE-NEXT:                   movw	r2, #4174
334# CODE-NEXT:                   movt	r2, #0
335# CODE-NEXT:                   movw	r3, #42
336# CODE-NEXT:                   movt	r3, #0
337
338
339# CODE: _a1:
340# CODE-NEXT:                 	 movw	r0, #4133
341# CODE-NEXT:                   movt	r0, #0
342# CODE-NEXT:                   movw	r1, #65495
343# CODE-NEXT:                   movt	r1, #65535
344# CODE-NEXT:                   movw	r2, #4174
345# CODE-NEXT:                   movt	r2, #0
346# CODE-NEXT:                   movw	r3, #0
347# CODE-NEXT:                   movt	r3, #0
348
349
350
351#	.syntax unified
352#	.align	2
353#
354#	.code	16
355#  .thumb_func	_t1
356#_t1:
357#	movw	r0, :lower16:(_t2)
358#	movt	r0, :upper16:(_t2)
359#	movw	r1, :lower16:(_t2-(L0+4))
360#	movt	r1, :upper16:(_t2-(L0+4))
361#	movw	r2, :lower16:(_a2)
362#	movt	r2, :upper16:(_a2)
363#	movw	r3, :lower16:(_a2-(L0+4))
364#	movt	r3, :upper16:(_a2-(L0+4))
365#L0:
366#	add	r0, pc
367#	bx	lr
368#
369#
370#	.code	16
371#	.thumb_func	_t2
372#_t2:
373#	bx	lr
374#
375#
376#
377# 	.code	32
378#_a1:
379#	movw	r0, :lower16:(_t2)
380#	movt	r0, :upper16:(_t2)
381#	movw	r1, :lower16:(_t2-(L1+8))
382#	movt	r1, :upper16:(_t2-(L1+8))
383#	movw	r2, :lower16:(_a2)
384#	movt	r2, :upper16:(_a2)
385#	movw	r3, :lower16:(_a2-(L1+8))
386#	movt	r3, :upper16:(_a2-(L1+8))
387#L1:
388#	add	r0, pc
389#	bx	lr
390#
391#_a2:
392#	bx	lr
393
394