Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / MachO / compact-unwind-both-local-and-dylib-personality.s
blob676577d6b17e9f2a78a9a79d44c03501b2a3e202
1 ## Tests that lld-macho can handle the case where personality symbols with the same name
2 ## are both from a dylib and locally defined in an object file.
4 # REQUIRES: x86
5 # RUN: rm -rf %t; split-file %s %t
6 # RUN: llvm-mc -emit-compact-unwind-non-canonical=true -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/user_2.s -o %t/user_2.o
7 # RUN: llvm-mc -emit-compact-unwind-non-canonical=true -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/user_3.s -o %t/user_3.o
9 ## Test case for linking 3+ personaltiies (all globals) without crashing because all the non-canonical are DWARFs
10 # RUN: llvm-mc -emit-compact-unwind-non-canonical=false -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/user_4.s -o %t/user_4.o
12 # RUN: yaml2obj %t/combined.yaml > %t/combined.o
14 ## Pre-condition: check that ___gxx_personality_v0 really is locally defined in combined.o before we proceed.
15 # RUN: llvm-nm %t/combined.o | grep '___gxx_personality_v0' | FileCheck %s --check-prefix=PRECHECK
16 # PRECHECK: {{.*}} t ___gxx_personality_v0
17 # PRECHECK-NOT: {{.*}} U ___gxx_personality_v0
18 # PRECHECK-NOT: {{.*}} T ___gxx_personality_v0
20 ## check that we can link with 4 personalities without crashing:
21 ## ___gxx_personality_v0 (libc++.tbd), ___gxx_personality_v0(local), _personality_1, and _personality_2
22 # RUN: %lld -lSystem -lc++ %t/user_2.o %t/combined.o -o %t/a.out
23 ## ___gxx_personality_v0 (global), ___gxx_personality_v0(libc++.tbd), _personality_1, and _personality_2
24 # RUN: %lld -lSystem -lc++ %t/user_3.o %t/user_2.o -o %t/b.out
25 ## ___gxx_personality_v0 (global), ___gxx_personality_v0(local), _personality_1, and _personality_2
26 # RUN: %lld -lSystem -dylib %t/user_3.o %t/combined.o %t/user_2.o -o %t/c.out
28 ## check that we can link with 3+ personalities without crashing because
29 ## non-canonical personalities are dwarf.
30 ## This has ___gxx_personality_v0(global), ___gxx_personality_v0(local), and _personality_{1,2,3,4}
31 ## Only the ___gxx_personality_v0(global) should have compact-unwind. The rest should have DWARFs.
32 # RUN: %lld -lSystem -lc++ %t/user_4.o %t/combined.o -o %t/d.out
34 ## Postlink checks.
35 # RUN: llvm-nm %t/a.out | FileCheck %s --check-prefix=POSTCHECK
36 # POSTCHECK: {{.*}} U ___gxx_personality_v0
37 # POSTCHECK: {{.*}} t ___gxx_personality_v0
39 # RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --bind %t/a.out | FileCheck %s --check-prefixes=A,CHECK -D#%x,OFF=0x100000000
40 # RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --bind %t/b.out | FileCheck %s --check-prefixes=BC,CHECK -D#%x,OFF=0x100000000
41 # RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --bind %t/c.out | FileCheck %s --check-prefixes=BC,C,CHECK -D#%x,OFF=0
43 # RUN: llvm-objdump --macho --indirect-symbols --unwind-info --bind %t/d.out | FileCheck %s --check-prefixes=D -D#%x,OFF=0x100000000
45 # A: Indirect symbols for (__DATA_CONST,__got)
46 # A-NEXT: address index name
47 # A: 0x[[#%x,GXX_PERSONALITY_LO:]] [[#]] ___gxx_personality_v0
48 # A: 0x[[#%x,GXX_PERSONALITY_HI:]] [[#]] ___gxx_personality_v0
49 # A: 0x[[#%x,PERSONALITY_1:]] LOCAL
50 # A: 0x[[#%x,PERSONALITY_2:]] LOCAL
52 # BC: Indirect symbols for (__DATA_CONST,__got)
53 # BC-NEXT: address index name
54 # C: 0x[[#%x,GXX_PERSONALITY_HI:]] LOCAL
55 # BC: 0x[[#%x,GXX_PERSONALITY_LO:]] LOCAL
56 # BC: 0x[[#%x,PERSONALITY_1:]] LOCAL
57 # BC: 0x[[#%x,PERSONALITY_2:]] LOCAL
59 # CHECK: Personality functions: (count = 3)
60 # CHECK-DAG: personality[{{[0-9]+}}]: 0x{{0*}}[[#GXX_PERSONALITY_LO-OFF]]
61 # CHECK-DAG: personality[{{[0-9]+}}]: 0x{{0*}}[[#PERSONALITY_1-OFF]]
62 # CHECK-DAG: personality[{{[0-9]+}}]: 0x{{0*}}[[#PERSONALITY_2-OFF]]
64 # A: Bind table
65 # A-NEXT: segment section address type addend dylib symbol
66 # A-NEXT: __DATA_CONST __got 0x[[#GXX_PERSONALITY_LO-0]] pointer 0 libc++abi ___gxx_personality_v0
69 # D: Indirect symbols for (__DATA_CONST,__got)
70 # D-NEXT: address index name
71 # D: 0x[[#%x,GXX_PERSONALITY_HI:]] [[#]] ___gxx_personality_v0
72 # D: 0x[[#%x,PERSONALITY_1:]] [[#]] _personality_1
73 # D: 0x[[#%x,PERSONALITY_2:]] [[#]] _personality_2
74 # D: 0x[[#%x,PERSONALITY_3:]] [[#]] _personality_3
75 # D: 0x[[#%x,PERSONALITY_4:]] [[#]] _personality_4
76 # D: 0x[[#%x,GXX_PERSONALITY_LO:]] [[#]] ___gxx_personality_v0
78 # D: Contents of __unwind_info section:
79 # D: Personality functions: (count = 1)
80 personality[1]: 0x{{0*}}[[#GXX_PERSONALITY_HI-OFF]]
82 # D: Bind table:
83 # D: segment section address type addend dylib symbol
84 # D: __DATA_CONST __got 0x[[#GXX_PERSONALITY_HI-0]] pointer 0 libc++abi ___gxx_personality_v0
87 ## Error cases.
88 ## Check that dylib symbols are picked (which means without libc++, we'd get an undefined symbol error.
89 # RUN: not %lld -lSystem %t/user_2.o %t/combined.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERRORCHECK
90 # ERRORCHECK: {{.*}} undefined symbol: ___gxx_personality_v0
92 #--- user_4.s
93 .globl _main, _personality_1, _personality_2, _personality_3, _personality_4
95 .text
97 _baz1:
98 .cfi_startproc
99 .cfi_personality 155, _personality_1
100 .cfi_def_cfa_offset 16
101 retq
102 .cfi_endproc
104 _baz2:
105 .cfi_startproc
106 .cfi_personality 155, _personality_2
107 .cfi_def_cfa_offset 16
108 retq
109 .cfi_endproc
111 _baz3:
112 .cfi_startproc
113 .cfi_personality 155, _personality_3
114 .cfi_def_cfa_offset 16
115 retq
116 .cfi_endproc
119 _baz4:
120 .cfi_startproc
121 .cfi_personality 155, _personality_4
122 .cfi_def_cfa_offset 16
123 retq
124 .cfi_endproc
126 _main:
127 .cfi_startproc
128 .cfi_personality 155, ___gxx_personality_v0
129 .cfi_def_cfa_offset 16
130 retq
131 .cfi_endproc
133 _personality_1:
134 retq
135 _personality_2:
136 retq
137 _personality_3:
138 retq
139 _personality_4:
140 retq
142 #--- user_3.s
143 .globl _baz3
144 .private_extern ___gxx_personality_v0
146 .text
147 _baz3:
148 .cfi_startproc
149 .cfi_personality 155, ___gxx_personality_v0
150 .cfi_def_cfa_offset 16
151 retq
152 .cfi_endproc
154 .text
155 .no_dead_strip ___gxx_personality_v0
156 ___gxx_personality_v0:
159 .subsections_via_symbols
162 #--- user_2.s
163 .globl _main, _personality_1, _personality_2
165 .text
167 _bar:
168 .cfi_startproc
169 .cfi_personality 155, _personality_1
170 .cfi_def_cfa_offset 16
171 retq
172 .cfi_endproc
174 _baz:
175 .cfi_startproc
176 .cfi_personality 155, _personality_2
177 .cfi_def_cfa_offset 16
178 retq
179 .cfi_endproc
181 _main:
182 .cfi_startproc
183 .cfi_personality 155, ___gxx_personality_v0
184 .cfi_def_cfa_offset 16
185 retq
186 .cfi_endproc
188 _personality_1:
189 retq
190 _personality_2:
191 retq
193 ## This yaml was created from the combined.o object file described in this comment:
194 ## https://reviews.llvm.org/D107533#2935217
195 #--- combined.yaml
196 --- !mach-o
197 FileHeader:
198 magic: 0xFEEDFACF
199 cputype: 0x1000007
200 cpusubtype: 0x3
201 filetype: 0x1
202 ncmds: 4
203 sizeofcmds: 384
204 flags: 0x2000
205 reserved: 0x0
206 LoadCommands:
207 - cmd: LC_SEGMENT_64
208 cmdsize: 312
209 segname: ''
210 vmaddr: 0
211 vmsize: 152
212 fileoff: 448
213 filesize: 152
214 maxprot: 7
215 initprot: 7
216 nsects: 3
217 flags: 0
218 Sections:
219 - sectname: __text
220 segname: __TEXT
221 addr: 0x0
222 size: 5
223 offset: 0x1C0
224 align: 2
225 reloff: 0x0
226 nreloc: 0
227 flags: 0x80000400
228 reserved1: 0x0
229 reserved2: 0x0
230 reserved3: 0x0
231 content: 90909090C3
232 - sectname: __eh_frame
233 segname: __TEXT
234 addr: 0x8
235 size: 80
236 offset: 0x1C8
237 align: 3
238 reloff: 0x258
239 nreloc: 5
240 flags: 0x0
241 reserved1: 0x0
242 reserved2: 0x0
243 reserved3: 0x0
244 content: 1400000000000000017A520001781001100C0708900100001800000000000000017A505200017810069B04000000100C070890011800000004000000F8FFFFFFFFFFFFFF0100000000000000000E1000
245 relocations:
246 - address: 0x2A
247 symbolnum: 0
248 pcrel: true
249 length: 2
250 extern: true
251 type: 4
252 scattered: false
253 value: 0
254 - address: 0x38
255 symbolnum: 2
256 pcrel: false
257 length: 2
258 extern: true
259 type: 5
260 scattered: false
261 value: 0
262 - address: 0x38
263 symbolnum: 3
264 pcrel: false
265 length: 2
266 extern: true
267 type: 0
268 scattered: false
269 value: 0
270 - address: 0x3C
271 symbolnum: 3
272 pcrel: false
273 length: 3
274 extern: true
275 type: 5
276 scattered: false
277 value: 0
278 - address: 0x3C
279 symbolnum: 4
280 pcrel: false
281 length: 3
282 extern: true
283 type: 0
284 scattered: false
285 value: 0
286 - sectname: __compact_unwind
287 segname: __LD
288 addr: 0x58
289 size: 64
290 offset: 0x218
291 align: 3
292 reloff: 0x280
293 nreloc: 3
294 flags: 0x2000000
295 reserved1: 0x0
296 reserved2: 0x0
297 reserved3: 0x0
298 content: '00000000000000000100000000000202000000000000000000000000000000000000000000000000010000000000020200000000000000000000000000000000'
299 relocations:
300 - address: 0x0
301 symbolnum: 0
302 pcrel: false
303 length: 3
304 extern: true
305 type: 0
306 scattered: false
307 value: 0
308 - address: 0x20
309 symbolnum: 4
310 pcrel: false
311 length: 3
312 extern: true
313 type: 0
314 scattered: false
315 value: 0
316 - address: 0x30
317 symbolnum: 0
318 pcrel: false
319 length: 3
320 extern: true
321 type: 0
322 scattered: false
323 value: 0
324 - cmd: LC_SYMTAB
325 cmdsize: 24
326 symoff: 664
327 nsyms: 5
328 stroff: 744
329 strsize: 48
330 - cmd: LC_BUILD_VERSION
331 cmdsize: 32
332 platform: 1
333 minos: 659200
334 sdk: 720896
335 ntools: 1
336 Tools:
337 - tool: 3
338 version: 39913472
339 - cmd: LC_DATA_IN_CODE
340 cmdsize: 16
341 dataoff: 664
342 datasize: 0
343 LinkEditData:
344 NameList:
345 - n_strx: 7
346 n_type: 0x1E
347 n_sect: 1
348 n_desc: 32
349 n_value: 0
350 - n_strx: 29
351 n_type: 0xE
352 n_sect: 2
353 n_desc: 0
354 n_value: 8
355 - n_strx: 29
356 n_type: 0xE
357 n_sect: 2
358 n_desc: 0
359 n_value: 32
360 - n_strx: 39
361 n_type: 0xE
362 n_sect: 2
363 n_desc: 0
364 n_value: 60
365 - n_strx: 2
366 n_type: 0xF
367 n_sect: 1
368 n_desc: 0
369 n_value: 4
370 StringTable:
371 - ' '
372 - _foo
373 - ___gxx_personality_v0
374 - EH_Frame1
375 - func.eh
376 - ''