1## Show that yaml2obj supports custom section data for Mach-O YAML inputs.
2
3## Case 1: The size of content is greater than the section size.
4# RUN: not yaml2obj --docnum=1 %s -o %t1 2>&1 | FileCheck %s --check-prefix=CASE1
5# CASE1: error: Section size must be greater than or equal to the content size
6
7--- !mach-o
8FileHeader:
9  magic:           0xFEEDFACF
10  cputype:         0x01000007
11  cpusubtype:      0x00000003
12  filetype:        0x00000001
13  ncmds:           1
14  sizeofcmds:      232
15  flags:           0x00002000
16  reserved:        0x00000000
17LoadCommands:
18  - cmd:             LC_SEGMENT_64
19    cmdsize:         232
20    segname:         ''
21    vmaddr:          0
22    vmsize:          4
23    fileoff:         392
24    filesize:        4
25    maxprot:         7
26    initprot:        7
27    nsects:          1
28    flags:           0
29    Sections:
30      - sectname:        __data
31        segname:         __DATA
32        addr:            0x0000000000000000
33        size:            0
34        offset:          0x00000188
35        align:           2
36        reloff:          0x00000000
37        nreloc:          0
38        flags:           0x00000000
39        reserved1:       0x00000000
40        reserved2:       0x00000000
41        reserved3:       0x00000000
42        content:         CDAB3412
43
44## Case 2: The content size equals the section size.
45# RUN: yaml2obj --docnum=2 %s -o %t2
46# RUN: llvm-readobj --sections --section-data %t2 | FileCheck %s --check-prefix=CASE2
47# CASE2:       Index: 0
48# CASE2-NEXT:  Name: __data (5F 5F 64 61 74 61 00 00 00 00 00 00 00 00 00 00)
49# CASE2-NEXT:  Segment: __DATA (5F 5F 44 41 54 41 00 00 00 00 00 00 00 00 00 00)
50# CASE2-NEXT:  Address: 0x0
51# CASE2-NEXT:  Size: 0x4
52# CASE2-NEXT:  Offset: 392
53# CASE2-NEXT:  Alignment: 2
54# CASE2-NEXT:  RelocationOffset: 0x0
55# CASE2-NEXT:  RelocationCount: 0
56# CASE2-NEXT:  Type: Regular (0x0)
57# CASE2-NEXT:  Attributes [ (0x0)
58# CASE2-NEXT:  ]
59# CASE2-NEXT:  Reserved1: 0x0
60# CASE2-NEXT:  Reserved2: 0x0
61# CASE2-NEXT:  Reserved3: 0x0
62# CASE2-NEXT:  SectionData (
63# CASE2-NEXT:    0000: CDAB3412                             |..4.|
64# CASE2-NEXT:  )
65
66--- !mach-o
67FileHeader:
68  magic:           0xFEEDFACF
69  cputype:         0x01000007
70  cpusubtype:      0x00000003
71  filetype:        0x00000001
72  ncmds:           1
73  sizeofcmds:      232
74  flags:           0x00002000
75  reserved:        0x00000000
76LoadCommands:
77  - cmd:             LC_SEGMENT_64
78    cmdsize:         232
79    segname:         ''
80    vmaddr:          0
81    vmsize:          4
82    fileoff:         392
83    filesize:        4
84    maxprot:         7
85    initprot:        7
86    nsects:          1
87    flags:           0
88    Sections:
89      - sectname:        __data
90        segname:         __DATA
91        addr:            0x0000000000000000
92        size:            4
93        offset:          0x00000188
94        align:           2
95        reloff:          0x00000000
96        nreloc:          0
97        flags:           0x00000000
98        reserved1:       0x00000000
99        reserved2:       0x00000000
100        reserved3:       0x00000000
101        content:         CDAB3412
102
103## Case 3: The content size is less than the section size. In this case, the area
104## after the custom content is filled with zeroes.
105# RUN: yaml2obj --docnum=3 %s -o %t3
106# RUN: llvm-readobj --sections --section-data %t3 | FileCheck %s --check-prefix=CASE3
107# CASE3:       Index: 0
108# CASE3-NEXT:  Name: __data (5F 5F 64 61 74 61 00 00 00 00 00 00 00 00 00 00)
109# CASE3-NEXT:  Segment: __DATA (5F 5F 44 41 54 41 00 00 00 00 00 00 00 00 00 00)
110# CASE3-NEXT:  Address: 0x0
111# CASE3-NEXT:  Size: 0x4
112# CASE3-NEXT:  Offset: 392
113# CASE3-NEXT:  Alignment: 2
114# CASE3-NEXT:  RelocationOffset: 0x0
115# CASE3-NEXT:  RelocationCount: 0
116# CASE3-NEXT:  Type: Regular (0x0)
117# CASE3-NEXT:  Attributes [ (0x0)
118# CASE3-NEXT:  ]
119# CASE3-NEXT:  Reserved1: 0x0
120# CASE3-NEXT:  Reserved2: 0x0
121# CASE3-NEXT:  Reserved3: 0x0
122# CASE3-NEXT:  SectionData (
123# CASE3-NEXT:    0000: AA000000                             |....|
124# CASE3-NEXT:  )
125
126--- !mach-o
127FileHeader:
128  magic:           0xFEEDFACF
129  cputype:         0x01000007
130  cpusubtype:      0x00000003
131  filetype:        0x00000001
132  ncmds:           1
133  sizeofcmds:      232
134  flags:           0x00002000
135  reserved:        0x00000000
136LoadCommands:
137  - cmd:             LC_SEGMENT_64
138    cmdsize:         232
139    segname:         ''
140    vmaddr:          0
141    vmsize:          4
142    fileoff:         392
143    filesize:        4
144    maxprot:         7
145    initprot:        7
146    nsects:          1
147    flags:           0
148    Sections:
149      - sectname:        __data
150        segname:         __DATA
151        addr:            0x0000000000000000
152        size:            4
153        offset:          0x00000188
154        align:           2
155        reloff:          0x00000000
156        nreloc:          0
157        flags:           0x00000000
158        reserved1:       0x00000000
159        reserved2:       0x00000000
160        reserved3:       0x00000000
161        content:         AA
162