1# RUN: ld64.lld -arch armv7 -r -print_atoms %s \
2# RUN: %p/Inputs/arm-interworking.yaml -o %t  | FileCheck %s \
3# RUN: && ld64.lld -arch armv7 -dylib -print_atoms \
4# RUN:         %p/Inputs/armv7/libSystem.yaml %t -o %t2  | FileCheck %s \
5# RUN: && llvm-readobj -S --section-data %t2 | FileCheck -check-prefix=CODE %s
6#
7# Test thumb and arm branches round trip through -r.
8# Test bl/blx instructions are fixed up properly.
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:         [ 0xFF, 0xF7, 0xFE, 0xFF, 0xC0, 0x46, 0xFF, 0xF7,
24                       0xFC, 0xEF, 0xC0, 0x46, 0xFF, 0xF7, 0xF8, 0xEF,
25                       0xFF, 0xF7, 0xF6, 0xFF, 0xC0, 0x46, 0xFF, 0xF7,
26                       0xF3, 0xFF, 0xC0, 0x46, 0x00, 0xF0, 0x06, 0xE8,
27                       0xC0, 0x46, 0x00, 0xF0, 0x03, 0xF8, 0x00, 0xF0,
28                       0x02, 0xF8, 0x70, 0x47, 0x70, 0x47, 0x70, 0x47 ]
29    relocations:
30      - offset:          0x00000026
31        type:            ARM_THUMB_RELOC_BR22
32        length:          2
33        pc-rel:          true
34        extern:          false
35        symbol:          1
36      - offset:          0x00000022
37        type:            ARM_THUMB_RELOC_BR22
38        length:          2
39        pc-rel:          true
40        extern:          false
41        symbol:          1
42      - offset:          0x0000001C
43        type:            ARM_THUMB_RELOC_BR22
44        length:          2
45        pc-rel:          true
46        extern:          false
47        symbol:          1
48      - offset:          0x00000016
49        type:            ARM_THUMB_RELOC_BR22
50        length:          2
51        pc-rel:          true
52        extern:          false
53        symbol:          1
54      - offset:          0x00000010
55        type:            ARM_THUMB_RELOC_BR22
56        length:          2
57        pc-rel:          true
58        extern:          false
59        symbol:          1
60      - offset:          0x0000000C
61        type:            ARM_THUMB_RELOC_BR22
62        length:          2
63        pc-rel:          true
64        extern:          true
65        symbol:          5
66      - offset:          0x00000006
67        type:            ARM_THUMB_RELOC_BR22
68        length:          2
69        pc-rel:          true
70        extern:          true
71        symbol:          5
72      - offset:          0x00000000
73        type:            ARM_THUMB_RELOC_BR22
74        length:          2
75        pc-rel:          true
76        extern:          true
77        symbol:          4
78  - segment:         __DATA
79    section:         __data
80    type:            S_REGULAR
81    attributes:      [  ]
82    address:         0x0000000000000030
83    content:         [ 0x2D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]
84    relocations:
85      - offset:          0x00000004
86        type:            ARM_RELOC_VANILLA
87        length:          2
88        pc-rel:          false
89        extern:          true
90        symbol:          4
91      - offset:          0x00000000
92        type:            ARM_RELOC_VANILLA
93        length:          2
94        pc-rel:          false
95        extern:          false
96        symbol:          1
97local-symbols:
98  - name:            _t3
99    type:            N_SECT
100    sect:            1
101    desc:            [ N_ARM_THUMB_DEF ]
102    value:           0x000000000000002E
103  - name:            _d1
104    type:            N_SECT
105    sect:            2
106    value:           0x0000000000000030
107global-symbols:
108  - name:            _t1
109    type:            N_SECT
110    scope:           [ N_EXT ]
111    sect:            1
112    desc:            [ N_ARM_THUMB_DEF ]
113    value:           0x0000000000000000
114  - name:            _t2
115    type:            N_SECT
116    scope:           [ N_EXT ]
117    sect:            1
118    desc:            [ N_ARM_THUMB_DEF ]
119    value:           0x000000000000002C
120undefined-symbols:
121  - name:            _a1
122    type:            N_UNDF
123    scope:           [ N_EXT ]
124    value:           0x0000000000000000
125  - name:            _a2
126    type:            N_UNDF
127    scope:           [ N_EXT ]
128    value:           0x0000000000000000
129
130...
131
132
133# CHECK: defined-atoms:
134# CHECK:   - name:            _d1
135# CHECK:     type:            data
136# CHECK:     references:
137# CHECK:       - kind:            pointer32
138# CHECK:         offset:          0
139# CHECK:         target:          _t2
140# CHECK:       - kind:            pointer32
141# CHECK:         offset:          4
142# CHECK:         target:          _a1
143# CHECK:   - name:            _d2
144# CHECK:     type:            data
145# CHECK:     references:
146# CHECK:       - kind:            pointer32
147# CHECK:         offset:          0
148# CHECK:         target:          _t1
149# CHECK:       - kind:            pointer32
150# CHECK:         offset:          4
151# CHECK:         target:          _a1
152# CHECK:   - name:            _t1
153# CHECK:     scope:           global
154# CHECK:     references:
155# CHECK:       - kind:            modeThumbCode
156# CHECK:         offset:          0
157# CHECK:         target:          _t1
158# CHECK:       - kind:            thumb_bl22
159# CHECK:         offset:          0
160# CHECK:         target:          _a1
161# CHECK:       - kind:            thumb_bl22
162# CHECK:         offset:          6
163# CHECK:         target:          _a2
164# CHECK:       - kind:            thumb_bl22
165# CHECK:         offset:          12
166# CHECK:         target:          _a2
167# CHECK:       - kind:            thumb_bl22
168# CHECK:         offset:          16
169# CHECK:         target:          _t1
170# CHECK:       - kind:            thumb_bl22
171# CHECK:         offset:          22
172# CHECK:         target:          _t1
173# CHECK:       - kind:            thumb_bl22
174# CHECK:         offset:          28
175# CHECK:         target:          _t2
176# CHECK:       - kind:            thumb_bl22
177# CHECK:         offset:          34
178# CHECK:         target:          _t2
179# CHECK:       - kind:            thumb_bl22
180# CHECK:         offset:          38
181# CHECK:         target:          _t3
182# CHECK:   - name:            _t2
183# CHECK:     scope:           global
184# CHECK:     content:         [ 70, 47 ]
185# CHECK:     references:
186# CHECK:       - kind:            modeThumbCode
187# CHECK:         offset:          0
188# CHECK:         target:          _t2
189# CHECK:   - name:            _t3
190# CHECK:     content:         [ 70, 47 ]
191# CHECK:     references:
192# CHECK:       - kind:            modeThumbCode
193# CHECK:         offset:          0
194# CHECK:         target:          _t3
195# CHECK:   - name:            _a1
196# CHECK:     scope:           global
197# CHECK:     references:
198# CHECK:       - kind:            arm_bl24
199# CHECK:         offset:          0
200# CHECK:         target:          _a1
201# CHECK:       - kind:            arm_bl24
202# CHECK:         offset:          4
203# CHECK:         target:          _a2
204# CHECK:       - kind:            arm_bl24
205# CHECK:         offset:          8
206# CHECK:         target:          _t1
207# CHECK:       - kind:            arm_bl24
208# CHECK:         offset:          12
209# CHECK:         target:          _t2
210# CHECK:   - name:            _a2
211# CHECK:     scope:           global
212
213# CODE:     Name: __text (5F 5F 74 65 78 74 00 00 00 00 00 00 00 00 00 00)
214# CODE:     Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
215# CODE:     SectionData (
216# CODE:       0000: 00F016E8 C04600F0 1EE8C046 00F01AE8
217# CODE:       0010: FFF7F6FF C046FFF7 F3FFC046 00F006F8
218# CODE:       0020: C04600F0 03F800F0 02F87047 70477047
219# CODE:       0030: FEFFFFEB 020000EB F0FFFFFA FAFFFFFA
220# CODE:       0040: 1EFF2FE1 1EFF2FE1
221# CODE:     )
222
223# CODE:     Name: __data (5F 5F 64 61 74 61 00 00 00 00 00 00 00 00 00 00)
224# CODE:     Segment: __DATA (5F 5F 44 41 54 41 00 00 00 00 00 00 00 00 00 00)
225# CODE:     SectionData (
226# CODE:       0000: E50F0000 E80F0000 B90F0000 E80F0000
227# CODE:     )
228
229# When we get a good mach-o disassembler the above __text section content check can be change to be symbolic.
230# Verify the low (thumb) bit is set on the first and third pointers but not the second and fourth.
231
232
233
234# Input file one:
235#
236#	.align	2
237#	.code	16
238#  .globl _t1
239#  .thumb_func	_t1
240#_t1:
241#    bl  _a1
242#    nop
243#    blx _a2
244#    nop
245#    blx _a2
246#    bl  _t1
247#    nop
248#    bl  _t1
249#    nop
250#    blx _t2
251#    nop
252#    blx  _t2
253#    bx   lr
254#
255#  .globl _t2
256#  .thumb_func	_t2
257#_t2:
258#    bx   lr
259#
260#    .data
261#_d1:  .long _t2
262#      .long _a1
263
264
265
266# Input file two:
267#
268#	.align	2
269#	.code	32
270#  .globl _a1
271#_a1:
272#    bl  _a1
273#    blx _a2
274#    bl  _t1
275#    blx _t2
276#    bx   lr
277#
278#  .globl _a2
279#_a2:
280#    bx   lr
281#
282#    .data
283#_d2:  .long _t1
284#      .long _a1
285
286
287
288
289