1# RUN: ld64.lld -arch arm64 -r -print_atoms %s -o %t | FileCheck %s \
2# RUN:  && ld64.lld -arch arm64 -r -print_atoms %t -o %t2 | FileCheck %s
3#
4# Test parsing and writing of arm64 text relocations.
5#
6# The first step tests if the supplied mach-o file is parsed into the correct
7# set of references.  The second step verifies relocations can be round-tripped
8# by writing to a new .o file, then parsing that file which should result in
9# the same references.
10#
11#_test:
12
13
14--- !mach-o
15arch:            arm64
16file-type:       MH_OBJECT
17flags:           [  ]
18has-UUID:        false
19OS:              unknown
20sections:
21  - segment:         __TEXT
22    section:         __text
23    type:            S_REGULAR
24    attributes:      [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ]
25    address:         0x0000000000000000
26    content:         [ 0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, 0x94,
27                       0x01, 0x00, 0x00, 0x90, 0x20, 0x00, 0x40, 0x39,
28                       0x20, 0x00, 0x40, 0x79, 0x20, 0x00, 0x40, 0xB9,
29                       0x20, 0x00, 0x40, 0xF9, 0x20, 0x00, 0xC0, 0x3D,
30                       0x01, 0x00, 0x00, 0x90, 0x20, 0x00, 0x40, 0xB9,
31                       0x01, 0x00, 0x00, 0x90, 0x20, 0x00, 0x40, 0xF9,
32                       0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x40, 0xF9 ]
33    relocations:
34      - offset:          0x00000034
35        type:            ARM64_RELOC_TLVP_LOAD_PAGEOFF12
36        length:          2
37        pc-rel:          false
38        extern:          true
39        symbol:          5
40      - offset:          0x00000030
41        type:            ARM64_RELOC_TLVP_LOAD_PAGE21
42        length:          2
43        pc-rel:          true
44        extern:          true
45        symbol:          5
46      - offset:          0x0000002C
47        type:            ARM64_RELOC_GOT_LOAD_PAGEOFF12
48        length:          2
49        pc-rel:          false
50        extern:          true
51        symbol:          6
52      - offset:          0x00000028
53        type:            ARM64_RELOC_GOT_LOAD_PAGE21
54        length:          2
55        pc-rel:          true
56        extern:          true
57        symbol:          6
58      - offset:          0x00000024
59        type:            ARM64_RELOC_ADDEND
60        length:          2
61        pc-rel:          false
62        extern:          false
63        symbol:          16
64      - offset:          0x00000024
65        type:            ARM64_RELOC_PAGEOFF12
66        length:          2
67        pc-rel:          false
68        extern:          true
69        symbol:          2
70      - offset:          0x00000020
71        type:            ARM64_RELOC_ADDEND
72        length:          2
73        pc-rel:          false
74        extern:          false
75        symbol:          16
76      - offset:          0x00000020
77        type:            ARM64_RELOC_PAGE21
78        length:          2
79        pc-rel:          true
80        extern:          true
81        symbol:          2
82      - offset:          0x0000001C
83        type:            ARM64_RELOC_PAGEOFF12
84        length:          2
85        pc-rel:          false
86        extern:          true
87        symbol:          2
88      - offset:          0x00000018
89        type:            ARM64_RELOC_PAGEOFF12
90        length:          2
91        pc-rel:          false
92        extern:          true
93        symbol:          2
94      - offset:          0x00000014
95        type:            ARM64_RELOC_PAGEOFF12
96        length:          2
97        pc-rel:          false
98        extern:          true
99        symbol:          2
100      - offset:          0x00000010
101        type:            ARM64_RELOC_PAGEOFF12
102        length:          2
103        pc-rel:          false
104        extern:          true
105        symbol:          2
106      - offset:          0x0000000C
107        type:            ARM64_RELOC_PAGEOFF12
108        length:          2
109        pc-rel:          false
110        extern:          true
111        symbol:          2
112      - offset:          0x00000008
113        type:            ARM64_RELOC_PAGE21
114        length:          2
115        pc-rel:          true
116        extern:          true
117        symbol:          2
118      - offset:          0x00000004
119        type:            ARM64_RELOC_ADDEND
120        length:          2
121        pc-rel:          false
122        extern:          false
123        symbol:          8
124      - offset:          0x00000004
125        type:            ARM64_RELOC_BRANCH26
126        length:          2
127        pc-rel:          true
128        extern:          true
129        symbol:          4
130      - offset:          0x00000000
131        type:            ARM64_RELOC_BRANCH26
132        length:          2
133        pc-rel:          true
134        extern:          true
135        symbol:          4
136  - segment:         __DATA
137    section:         __data
138    type:            S_REGULAR
139    attributes:      [  ]
140    alignment:       2
141    address:         0x0000000000000038
142    content:         [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
143                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]
144local-symbols:
145  - name:            ltmp0
146    type:            N_SECT
147    sect:            1
148    value:           0x0000000000000000
149  - name:            _func
150    type:            N_SECT
151    sect:            1
152    value:           0x0000000000000000
153  - name:            _v1
154    type:            N_SECT
155    sect:            2
156    value:           0x0000000000000038
157  - name:            ltmp1
158    type:            N_SECT
159    sect:            2
160    value:           0x0000000000000038
161undefined-symbols:
162  - name:            _foo
163    type:            N_UNDF
164    scope:           [ N_EXT ]
165    value:           0x0000000000000000
166  - name:            _tlv
167    type:            N_UNDF
168    scope:           [ N_EXT ]
169    value:           0x0000000000000000
170  - name:            _v2
171    type:            N_UNDF
172    scope:           [ N_EXT ]
173    value:           0x0000000000000000
174...
175
176# CHECK: defined-atoms:
177# CHECK:   - name:            _v1
178# CHECK:     type:            data
179# CHECK:     content:         [ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00,
180# CHECK:                        00, 00, 00, 00 ]
181# CHECK:   - name:            _func
182# CHECK:     content:         [ 00, 00, 00, 94, 00, 00, 00, 94, 01, 00, 00, 90,
183# CHECK:                        20, 00, 40, 39, 20, 00, 40, 79, 20, 00, 40, B9,
184# CHECK:                        20, 00, 40, F9, 20, 00, C0, 3D, 01, 00, 00, 90,
185# CHECK:                        20, 00, 40, B9, 01, 00, 00, 90, 20, 00, 40, F9,
186# CHECK:                        00, 00, 00, 90, 00, 00, 40, F9 ]
187# CHECK:     references:
188# CHECK:       - kind:            branch26
189# CHECK:         offset:          0
190# CHECK:         target:          _foo
191# CHECK:       - kind:            branch26
192# CHECK:         offset:          4
193# CHECK:         target:          _foo
194# CHECK:         addend:          8
195# CHECK:       - kind:            page21
196# CHECK:         offset:          8
197# CHECK:         target:          _v1
198# CHECK:       - kind:            offset12
199# CHECK:         offset:          12
200# CHECK:         target:          _v1
201# CHECK:       - kind:            offset12scale2
202# CHECK:         offset:          16
203# CHECK:         target:          _v1
204# CHECK:       - kind:            offset12scale4
205# CHECK:         offset:          20
206# CHECK:         target:          _v1
207# CHECK:       - kind:            offset12scale8
208# CHECK:         offset:          24
209# CHECK:         target:          _v1
210# CHECK:       - kind:            offset12scale16
211# CHECK:         offset:          28
212# CHECK:         target:          _v1
213# CHECK:       - kind:            page21
214# CHECK:         offset:          32
215# CHECK:         target:          _v1
216# CHECK:         addend:          16
217# CHECK:       - kind:            offset12scale4
218# CHECK:         offset:          36
219# CHECK:         target:          _v1
220# CHECK:         addend:          16
221# CHECK:       - kind:            gotPage21
222# CHECK:         offset:          40
223# CHECK:         target:          _v2
224# CHECK:       - kind:            gotOffset12
225# CHECK:         offset:          44
226# CHECK:         target:          _v2
227# CHECK:       - kind:            tlvPage21
228# CHECK:         offset:          48
229# CHECK:         target:          _tlv
230# CHECK:       - kind:            tlvOffset12
231# CHECK:         offset:          52
232# CHECK:         target:          _tlv
233# CHECK: undefined-atoms:
234# CHECK:   - name:            _foo
235# CHECK:   - name:            _tlv
236# CHECK:   - name:            _v2
237
238