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# RUN: llvm-objdump -r -s --section="__eh_frame" --macho %t | FileCheck --check-prefix=CODE %s
4# RUN: llvm-objdump -r -s --section="__eh_frame" --macho %t2 | FileCheck --check-prefix=CODE %s
5
6
7--- !mach-o
8arch:            arm64
9file-type:       MH_OBJECT
10flags:           [ MH_SUBSECTIONS_VIA_SYMBOLS ]
11compat-version:  0.0
12current-version: 0.0
13has-UUID:        false
14OS:              unknown
15sections:
16  - segment:         __TEXT
17    section:         __text
18    type:            S_REGULAR
19    attributes:      [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ]
20    alignment:       4
21    address:         0x0000000000000000
22    content:         [ 0xFD, 0x7B, 0xBF, 0xA9, 0xFD, 0x03, 0x00, 0x91,
23                       0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x91,
24                       0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x80, 0x52,
25                       0xFD, 0x7B, 0xC1, 0xA8, 0xC0, 0x03, 0x5F, 0xD6 ]
26    relocations:
27      - offset:          0x00000010
28        type:            ARM64_RELOC_BRANCH26
29        length:          2
30        pc-rel:          true
31        extern:          true
32        symbol:          9
33      - offset:          0x0000000C
34        type:            ARM64_RELOC_PAGEOFF12
35        length:          2
36        pc-rel:          false
37        extern:          true
38        symbol:          1
39      - offset:          0x00000008
40        type:            ARM64_RELOC_PAGE21
41        length:          2
42        pc-rel:          true
43        extern:          true
44        symbol:          1
45  - segment:         __TEXT
46    section:         __cstring
47    type:            S_CSTRING_LITERALS
48    attributes:      [  ]
49    address:         0x0000000000000020
50    content:         [ 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F,
51                       0x72, 0x6C, 0x64, 0x00 ]
52  - segment:         __LD
53    section:         __compact_unwind
54    type:            S_REGULAR
55    attributes:      [  ]
56    alignment:       8
57    address:         0x0000000000000030
58    content:         [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59                       0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
60                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]
62    relocations:
63      - offset:          0x00000000
64        type:            ARM64_RELOC_UNSIGNED
65        length:          3
66        pc-rel:          false
67        extern:          false
68        symbol:          1
69  - segment:         __TEXT
70    section:         __eh_frame
71    type:            S_COALESCED
72    attributes:      [  ]
73    alignment:       8
74    address:         0x0000000000000050
75    content:         [ 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
76                       0x01, 0x7A, 0x50, 0x4C, 0x52, 0x00, 0x01, 0x78,
77                       0x1E, 0x07, 0x00, 0x9D, 0xFF, 0xFF, 0xFF, 0xFF,
78                       0xFF, 0xFF, 0xFF, 0x00, 0x10, 0x0C, 0x1F, 0x00,
79                       0x24, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
80                       0x88, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
81                       0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
82                       0x08, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83                       0x00, 0x48, 0x0E, 0x10, 0x9E, 0x01, 0x9D, 0x02 ]
84  - segment:         __TEXT
85    section:         __gcc_except_tab
86    type:            S_REGULAR
87    attributes:      [  ]
88    address:         0x00000000000000A0
89    content:         [ 0x00, 0x00, 0x00, 0x00 ]
90local-symbols:
91  - name:            ltmp0
92    type:            N_SECT
93    sect:            1
94    value:           0x0000000000000000
95  - name:            L_str
96    type:            N_SECT
97    sect:            2
98    value:           0x0000000000000020
99  - name:            ltmp1
100    type:            N_SECT
101    sect:            2
102    value:           0x0000000000000020
103  - name:            ltmp2
104    type:            N_SECT
105    sect:            3
106    value:           0x0000000000000030
107  - name:            ltmp3
108    type:            N_SECT
109    sect:            4
110    value:           0x0000000000000050
111  - name:            ltmp4
112    type:            N_SECT
113    sect:            4
114    value:           0x0000000000000070
115global-symbols:
116  - name:            __Z3fooi
117    type:            N_SECT
118    scope:           [ N_EXT ]
119    sect:            1
120    value:           0x0000000000000000
121undefined-symbols:
122  - name:            __gxx_personality_v0
123    type:            N_UNDF
124    scope:           [ N_EXT ]
125    value:           0x0000000000000000
126  - name:            _bar
127    type:            N_UNDF
128    scope:           [ N_EXT ]
129    value:           0x0000000000000000
130  - name:            _puts
131    type:            N_UNDF
132    scope:           [ N_EXT ]
133    value:           0x0000000000000000
134page-size:       0x00000000
135
136# CHECK: defined-atoms:
137# CHECK:   - ref-name:        L{{[0-9]*}}
138# CHECK:     scope:           hidden
139# CHECK:     type:            c-string
140# CHECK:     content:         [ 48, 65, 6C, 6C, 6F, 20, 77, 6F, 72, 6C, 64, 00 ]
141# CHECK:     merge:           by-content
142# CHECK:   - ref-name:        L{{[0-9]*}}
143# CHECK:     type:            unwind-cfi
144# CHECK:     content:         [ 1C, 00, 00, 00, 00, 00, 00, 00, 01, 7A, 50, 4C,
145# CHECK:                        52, 00, 01, 78, 1E, 07, 00, {{..}}, {{..}}, {{..}}, {{..}}, {{..}},
146# CHECK:                        {{..}}, {{..}}, {{..}}, 00, 10, 0C, 1F, 00 ]
147# CHECK:   - type:            unwind-cfi
148# CHECK:     content:         [ 24, 00, 00, 00, 24, 00, 00, 00, {{..}}, {{..}}, {{..}}, {{..}},
149# CHECK:                        {{..}}, {{..}}, {{..}}, {{..}}, 20, 00, 00, 00, 00, 00, 00, 00,
150# CHECK:                        08, {{..}}, {{..}}, {{..}}, {{..}}, {{..}}, {{..}}, {{..}}, {{..}}, 48, 0E, 10,
151# CHECK:                        9E, 01, 9D, 02 ]
152# CHECK:     references:
153# CHECK:       - kind:            negDelta32
154# CHECK:         offset:          4
155# CHECK:         target:          L{{[0-9]*}}
156# CHECK:       - kind:            unwindFDEToFunction
157# CHECK:         offset:          8
158# CHECK:         target:          __Z3fooi
159# CHECK:       - kind:            unwindFDEToFunction
160# CHECK:         offset:          25
161# CHECK:         target:          L{{[0-9]*}}
162# CHECK:   - ref-name:        L{{[0-9]*}}
163# CHECK:     type:            unwind-lsda
164# CHECK:     content:         [ 00, 00, 00, 00 ]
165# CHECK:   - type:            compact-unwind
166# CHECK:     content:         [ 00, 00, 00, 00, 00, 00, 00, 00, 20, 00, 00, 00,
167# CHECK:                        00, 00, 00, 03, 00, 00, 00, 00, 00, 00, 00, 00,
168# CHECK:                        00, 00, 00, 00, 00, 00, 00, 00 ]
169# CHECK:     alignment:       8
170# CHECK:     references:
171# CHECK:       - kind:            pointer64
172# CHECK:         offset:          0
173# CHECK:         target:          __Z3fooi
174# CHECK:   - name:            __Z3fooi
175# CHECK:     scope:           global
176# CHECK:     content:         [ FD, 7B, BF, A9, FD, 03, 00, 91, 00, 00, 00, 90,
177# CHECK:                        00, 00, 00, 91, 00, 00, 00, 94, 00, 00, 80, 52,
178# CHECK:                        FD, 7B, C1, A8, C0, 03, 5F, D6 ]
179# CHECK:     alignment:       4
180# CHECK:     references:
181# CHECK:       - kind:            page21
182# CHECK:         offset:          8
183# CHECK:         target:          L{{[0-9]*}}
184# CHECK:       - kind:            offset12
185# CHECK:         offset:          12
186# CHECK:         target:          L{{[0-9]*}}
187# CHECK:       - kind:            branch26
188# CHECK:         offset:          16
189# CHECK:         target:          _puts
190
191# Make sure we don't have any relocations in the __eh_frame section
192# CODE-NOT: RELOCATION RECORDS FOR [__eh_frame]
193
194# Also make sure the reloc for the FDE->function is the correct offset
195# It should be the offset from the fixup location back to the address
196# of the function we are referencing
197# CODE: Contents of section __TEXT,__eh_frame:
198# This is the CIE:
199# CODE-NEXT: {{[0-9abcdef]*}} 1c000000 00000000 017a504c 52000178
200# CODE-NEXT: {{[0-9abcdef]*}} 1e0700bd ffffffff ffffff00 100c1f00
201# This is the FDE:
202# CODE-NEXT: {{[0-9abcdef]*}} 24000000 24000000 a8ffffff ffffffff
203# This is the important offset for FDE->func    ^~~~~~~~ ~~~~~~~~
204
205# CODE-NEXT: {{[0-9abcdef]*}} 20000000 00000000 08c3ffff ffffffff
206# And this is the offset for FDE->lsda            ^~~~~~~~ ~~~~~~
207# CODE-NEXT: {{[0-9abcdef]*}} ff480e10 9e019d02
208# And this byte               ^~
209