• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1## This file contains test cases for generating sections in Mach-O object files.
2
3## a) Test that yaml2obj emits sections and obj2yaml converts them back.
4
5# RUN: yaml2obj --docnum=1 %s | obj2yaml | FileCheck %s
6
7--- !mach-o
8FileHeader:      
9  magic:           0xFEEDFACF
10  cputype:         0x01000007
11  cpusubtype:      0x80000003
12  filetype:        0x00000002
13  ncmds:           16
14  sizeofcmds:      1408
15  flags:           0x00218085
16  reserved:        0x00000000
17LoadCommands:    
18  - cmd:             LC_SEGMENT_64
19    cmdsize:         72
20    segname:         __PAGEZERO
21    vmaddr:          0
22    vmsize:          4294967296
23    fileoff:         0
24    filesize:        0
25    maxprot:         0
26    initprot:        0
27    nsects:          0
28    flags:           0
29  - cmd:             LC_SEGMENT_64
30    cmdsize:         552
31    segname:         __TEXT
32    vmaddr:          4294967296
33    vmsize:          8192
34    fileoff:         0
35    filesize:        8192
36    maxprot:         7
37    initprot:        5
38    nsects:          6
39    flags:           0
40    Sections:        
41      - sectname:        __text
42        segname:         __TEXT
43        addr:            0x0000000100001160
44        size:            3099
45        offset:          0x00001160
46        align:           4
47        reloff:          0x00000000
48        nreloc:          0
49        flags:           0x80000400
50        reserved1:       0x00000000
51        reserved2:       0x00000000
52        reserved3:       0x00000000
53      - sectname:        __stubs
54        segname:         __TEXT
55        addr:            0x0000000100001D7C
56        size:            90
57        offset:          0x00001D7C
58        align:           1
59        reloff:          0x00000000
60        nreloc:          0
61        flags:           0x80000408
62        reserved1:       0x00000000
63        reserved2:       0x00000006
64        reserved3:       0x00000000
65      - sectname:        __stub_helper
66        segname:         __TEXT
67        addr:            0x0000000100001DD8
68        size:            166
69        offset:          0x00001DD8
70        align:           2
71        reloff:          0x00000000
72        nreloc:          0
73        flags:           0x80000400
74        reserved1:       0x00000000
75        reserved2:       0x00000000
76        reserved3:       0x00000000
77      - sectname:        __gcc_except_tab
78        segname:         __TEXT
79        addr:            0x0000000100001E80
80        size:            240
81        offset:          0x00001E80
82        align:           2
83        reloff:          0x00000000
84        nreloc:          0
85        flags:           0x00000000
86        reserved1:       0x00000000
87        reserved2:       0x00000000
88        reserved3:       0x00000000
89      - sectname:        __cstring
90        segname:         __TEXT
91        addr:            0x0000000100001F70
92        size:            15
93        offset:          0x00001F70
94        align:           0
95        reloff:          0x00000000
96        nreloc:          0
97        flags:           0x00000002
98        reserved1:       0x00000000
99        reserved2:       0x00000000
100        reserved3:       0x00000000
101      - sectname:        __unwind_info
102        segname:         __TEXT
103        addr:            0x0000000100001F80
104        size:            120
105        offset:          0x00001F80
106        align:           2
107        reloff:          0x00000000
108        nreloc:          0
109        flags:           0x00000000
110        reserved1:       0x00000000
111        reserved2:       0x00000000
112        reserved3:       0x00000000
113  - cmd:             LC_SEGMENT_64
114    cmdsize:         312
115    segname:         __DATA
116    vmaddr:          4294975488
117    vmsize:          4096
118    fileoff:         8192
119    filesize:        4096
120    maxprot:         7
121    initprot:        3
122    nsects:          3
123    flags:           0
124    Sections:        
125      - sectname:        __got
126        segname:         __DATA
127        addr:            0x0000000100002000
128        size:            24
129        offset:          0x00002000
130        align:           3
131        reloff:          0x00000000
132        nreloc:          0
133        flags:           0x00000006
134        reserved1:       0x0000000F
135        reserved2:       0x00000000
136        reserved3:       0x00000000
137      - sectname:        __nl_symbol_ptr
138        segname:         __DATA
139        addr:            0x0000000100002018
140        size:            16
141        offset:          0x00002018
142        align:           3
143        reloff:          0x00000000
144        nreloc:          0
145        flags:           0x00000006
146        reserved1:       0x00000012
147        reserved2:       0x00000000
148        reserved3:       0x00000000
149      - sectname:        __la_symbol_ptr
150        segname:         __DATA
151        addr:            0x0000000100002028
152        size:            120
153        offset:          0x00002028
154        align:           3
155        reloff:          0x00000000
156        nreloc:          0
157        flags:           0x00000007
158        reserved1:       0x00000014
159        reserved2:       0x00000000
160        reserved3:       0x00000000
161  - cmd:             LC_SEGMENT_64
162    cmdsize:         72
163    segname:         __LINKEDIT
164    vmaddr:          4294979584
165    vmsize:          4096
166    fileoff:         12288
167    filesize:        2508
168    maxprot:         7
169    initprot:        1
170    nsects:          0
171    flags:           0
172  - cmd:             LC_DYLD_INFO_ONLY
173    cmdsize:         48
174    rebase_off:      12288
175    rebase_size:     8
176    bind_off:        12296
177    bind_size:       96
178    weak_bind_off:   0
179    weak_bind_size:  0
180    lazy_bind_off:   12392
181    lazy_bind_size:  624
182    export_off:      13016
183    export_size:     48
184  - cmd:             LC_SYMTAB
185    cmdsize:         24
186    symoff:          13080
187    nsyms:           30
188    stroff:          13700
189    strsize:         1096
190  - cmd:             LC_DYSYMTAB
191    cmdsize:         80
192    ilocalsym:       0
193    nlocalsym:       9
194    iextdefsym:      9
195    nextdefsym:      2
196    iundefsym:       11
197    nundefsym:       19
198    tocoff:          0
199    ntoc:            0
200    modtaboff:       0
201    nmodtab:         0
202    extrefsymoff:    0
203    nextrefsyms:     0
204    indirectsymoff:  13560
205    nindirectsyms:   35
206    extreloff:       0
207    nextrel:         0
208    locreloff:       0
209    nlocrel:         0
210  - cmd:             LC_LOAD_DYLINKER
211    cmdsize:         32
212    name:            12
213  - cmd:             LC_UUID
214    cmdsize:         24
215    uuid:            461A1B28-822F-3F38-B670-645419E636F5
216  - cmd:             LC_VERSION_MIN_MACOSX
217    cmdsize:         16
218    version:         658176
219    sdk:             658176
220  - cmd:             LC_SOURCE_VERSION
221    cmdsize:         16
222    version:         0
223  - cmd:             LC_MAIN
224    cmdsize:         24
225    entryoff:        4448
226    stacksize:       0
227  - cmd:             LC_LOAD_DYLIB
228    cmdsize:         48
229    dylib:           
230      name:            24
231      timestamp:       2
232      current_version: 7864576
233      compatibility_version: 65536
234  - cmd:             LC_LOAD_DYLIB
235    cmdsize:         56
236    dylib:           
237      name:            24
238      timestamp:       2
239      current_version: 80349697
240      compatibility_version: 65536
241  - cmd:             LC_FUNCTION_STARTS
242    cmdsize:         16
243    dataoff:         13064
244    datasize:        16
245  - cmd:             LC_DATA_IN_CODE
246    cmdsize:         16
247    dataoff:         13080
248    datasize:        0
249...
250
251
252#CHECK:   - cmd:             LC_SEGMENT_64
253#CHECK:     segname:         __PAGEZERO
254#CHECK:   - cmd:             LC_SEGMENT_64
255#CHECK:     segname:         __TEXT
256#CHECK:     Sections:
257#CHECK:       - sectname:        __text
258#CHECK:         segname:         __TEXT
259#CHECK:         addr:            0x100001160
260#CHECK:         size:            3099
261#CHECK:         offset:          0x1160
262#CHECK:         align:           4
263#CHECK:         reloff:          0x0
264#CHECK:         nreloc:          0
265#CHECK:         flags:           0x80000400
266#CHECK:         reserved1:       0x0
267#CHECK:         reserved2:       0x0
268#CHECK:         reserved3:       0x0
269#CHECK:       - sectname:        __stubs
270#CHECK:         segname:         __TEXT
271#CHECK:       - sectname:        __stub_helper
272#CHECK:         segname:         __TEXT
273#CHECK:       - sectname:        __gcc_except_tab
274#CHECK:         segname:         __TEXT
275#CHECK:       - sectname:        __cstring
276#CHECK:         segname:         __TEXT
277#CHECK:       - sectname:        __unwind_info
278#CHECK:         segname:         __TEXT
279#CHECK:   - cmd:             LC_SEGMENT_64
280#CHECK:     segname:         __DATA
281#CHECK:     Sections:
282#CHECK:       - sectname:        __got
283#CHECK:         segname:         __DATA
284#CHECK:       - sectname:        __nl_symbol_ptr
285#CHECK:         segname:         __DATA
286#CHECK:       - sectname:        __la_symbol_ptr
287#CHECK:         segname:         __DATA
288
289## b) Test that yaml2obj emits an error message if we specify an offset that
290## makes the current section and the previous one overlap.
291
292# RUN: not yaml2obj --docnum=2 %s -o %t2.macho 2>&1 | FileCheck %s --check-prefix=OVERLAP
293
294# OVERLAP: yaml2obj: error: wrote too much data somewhere, section offsets don't line up
295
296--- !mach-o
297FileHeader:
298  magic:      0xFEEDFACF
299  cputype:    0x01000007
300  cpusubtype: 0x80000003
301  filetype:   0x00000002
302  ncmds:      1
303  sizeofcmds: 1024
304  flags:      0x00000000
305  reserved:   0x00000000
306LoadCommands:
307  - cmd:      LC_SEGMENT_64
308    cmdsize:  0xff
309    segname:  __SEC
310    vmaddr:   0
311    vmsize:   0
312    fileoff:  0
313    filesize: 0
314    maxprot:  0
315    initprot: 0
316    nsects:   2
317    flags:    0
318    Sections:
319      - sectname:  __sec1
320        segname:   __SEC
321        addr:      0x0000000000000000
322        size:      2
323        offset:    0x00000000
324        align:     0
325        reloff:    0x00000000
326        nreloc:    0
327        flags:     0x00000000
328        reserved1: 0x00000000
329        reserved2: 0x00000000
330        reserved3: 0x00000000
331      - sectname:  __sec2
332        segname:   __SEC
333        addr:      0x0000000000000000
334        size:      2
335        offset:    0x00000001 ## Specify an offset that makes __sec1 and __sec2 overlap.
336        align:     1
337        reloff:    0x00000000
338        nreloc:    0
339        flags:     0x00000000
340        reserved1: 0x00000000
341        reserved2: 0x00000000
342        reserved3: 0x00000000
343