xref: /llvm-project/lld/test/MachO/compact-unwind-sym-relocs.s (revision 9d0b237c516f935482cfff5c3df9cb44ee766664)
1# REQUIRES: x86
2
3## Test that we correctly handle symbol relocations in the compact unwind
4## section.
5
6## llvm-mc does not emit such relocations for compact unwind, but `ld -r` does.
7## As such, these yaml files were from an object file produced with 'ld -r',
8## specifically:
9##
10##  // foo.s
11## .globl _foo
12## .text
13## .p2align 2
14## _foo:
15##   .cfi_startproc
16##   .cfi_personality 155, ___gxx_personality_v0
17##   .cfi_lsda 16, _exception0
18##   .cfi_def_cfa_offset 16
19##   ret
20##   .cfi_endproc
21##
22## .section __TEXT,__gcc_except_tab
23## _exception0:
24##   .space 0
25##
26## llvm-mc -filetype=obj -triple=x86_64-apple-macos10.15 -o foo1.o foo.s
27## ld -r -o foo.o foo1.o
28
29# RUN: rm -rf %t; mkdir -p %t
30# RUN: yaml2obj %s -o %t/foo.o
31# RUN: %lld -dylib -lc++ %t/foo.o -o %t/foo
32# RUN: llvm-objdump --macho --syms --unwind-info %t/foo | FileCheck %s
33
34# CHECK:      SYMBOL TABLE:
35# CHECK-DAG:  [[#%x,FOO:]]         g     F __TEXT,__text _foo
36# CHECK-DAG:  [[#%x,EXCEPT0:]]     l     O __TEXT,__gcc_except_tab _exception0
37
38# CHECK:      LSDA descriptors:
39# CHECK-NEXT: [0]: function offset=0x[[#%.8x,FOO]], LSDA offset=0x[[#%.8x,EXCEPT0]]
40
41--- !mach-o
42FileHeader:
43  magic:           0xFEEDFACF
44  cputype:         0x1000007
45  cpusubtype:      0x3
46  filetype:        0x1
47  ncmds:           2
48  sizeofcmds:      464
49  flags:           0x0
50  reserved:        0x0
51LoadCommands:
52  - cmd:             LC_SEGMENT_64
53    cmdsize:         392
54    segname:         ''
55    vmaddr:          0
56    vmsize:          112
57    fileoff:         528
58    filesize:        112
59    maxprot:         7
60    initprot:        7
61    nsects:          4
62    flags:           0
63    Sections:
64      - sectname:        __text
65        segname:         __TEXT
66        addr:            0x0
67        size:            1
68        offset:          0x210
69        align:           2
70        reloff:          0x0
71        nreloc:          0
72        flags:           0x80000400
73        reserved1:       0x0
74        reserved2:       0x0
75        reserved3:       0x0
76        content:         C3
77      - sectname:        __gcc_except_tab
78        segname:         __TEXT
79        addr:            0x1
80        size:            0
81        offset:          0x211
82        align:           0
83        reloff:          0x0
84        nreloc:          0
85        flags:           0x0
86        reserved1:       0x0
87        reserved2:       0x0
88        reserved3:       0x0
89        content:         ''
90      - sectname:        __eh_frame
91        segname:         __TEXT
92        addr:            0x8
93        size:            72
94        offset:          0x218
95        align:           3
96        reloff:          0x280
97        nreloc:          7
98        flags:           0x0
99        reserved1:       0x0
100        reserved2:       0x0
101        reserved3:       0x0
102        content:         1C00000000000000017A504C5200017810079B0400000010100C0708900100002400000004000000F8FFFFFFFFFFFFFF010000000000000008E7FFFFFFFFFFFFFF0E100000000000
103        relocations:
104          - address:         0x13
105            symbolnum:       4
106            pcrel:           true
107            length:          2
108            extern:          true
109            type:            4
110            scattered:       false
111            value:           0
112          - address:         0x24
113            symbolnum:       1
114            pcrel:           false
115            length:          2
116            extern:          true
117            type:            5
118            scattered:       false
119            value:           0
120          - address:         0x24
121            symbolnum:       2
122            pcrel:           false
123            length:          2
124            extern:          true
125            type:            0
126            scattered:       false
127            value:           0
128          - address:         0x28
129            symbolnum:       2
130            pcrel:           false
131            length:          3
132            extern:          true
133            type:            5
134            scattered:       false
135            value:           0
136          - address:         0x28
137            symbolnum:       3
138            pcrel:           false
139            length:          3
140            extern:          true
141            type:            0
142            scattered:       false
143            value:           0
144          - address:         0x39
145            symbolnum:       2
146            pcrel:           false
147            length:          3
148            extern:          true
149            type:            5
150            scattered:       false
151            value:           0
152          - address:         0x39
153            symbolnum:       0
154            pcrel:           false
155            length:          3
156            extern:          true
157            type:            0
158            scattered:       false
159            value:           0
160      - sectname:        __compact_unwind
161        segname:         __LD
162        addr:            0x50
163        size:            32
164        offset:          0x260
165        align:           3
166        reloff:          0x2B8
167        nreloc:          4
168        flags:           0x2000000
169        reserved1:       0x0
170        reserved2:       0x0
171        reserved3:       0x0
172        content:         '0000000000000000010000000000024200000000000000000000000000000000'
173        relocations:
174          - address:         0x0
175            symbolnum:       3
176            pcrel:           false
177            length:          3
178            extern:          true
179            type:            0
180            scattered:       false
181            value:           0
182          - address:         0x18
183            symbolnum:       0
184            pcrel:           false
185            length:          3
186            extern:          true
187            type:            0
188            scattered:       false
189            value:           0
190          - address:         0x10
191            symbolnum:       4
192            pcrel:           false
193            length:          3
194            extern:          true
195            type:            0
196            scattered:       false
197            value:           0
198          - address:         0x18
199            symbolnum:       0
200            pcrel:           false
201            length:          3
202            extern:          true
203            type:            0
204            scattered:       false
205            value:           0
206  - cmd:             LC_SYMTAB
207    cmdsize:         24
208    symoff:          728
209    nsyms:           5
210    stroff:          808
211    strsize:         57
212LinkEditData:
213  NameList:
214    - n_strx:          29
215      n_type:          0xE
216      n_sect:          2
217      n_desc:          32
218      n_value:         1
219    - n_strx:          41
220      n_type:          0xE
221      n_sect:          3
222      n_desc:          0
223      n_value:         8
224    - n_strx:          51
225      n_type:          0xE
226      n_sect:          3
227      n_desc:          0
228      n_value:         40
229    - n_strx:          2
230      n_type:          0xF
231      n_sect:          1
232      n_desc:          32
233      n_value:         0
234    - n_strx:          7
235      n_type:          0x1
236      n_sect:          0
237      n_desc:          0
238      n_value:         0
239  StringTable:
240    - ' '
241    - _foo
242    - ___gxx_personality_v0
243    - _exception0
244    - EH_Frame1
245    - func.eh
246...
247