aboutsummaryrefslogtreecommitdiff
path: root/llvm/test/ObjectYAML/MachO/section_data.yaml
blob: a2d9a3b7e1675b4fa840253d615197cae555b729 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
## Show that yaml2obj supports custom section data for Mach-O YAML inputs.

## Case 1: The size of content is greater than the section size.
# RUN: not yaml2obj --docnum=1 %s -o %t1 2>&1 | FileCheck %s --check-prefix=CASE1
# CASE1: error: Section size must be greater than or equal to the content size

--- !mach-o
FileHeader:
  magic:           0xFEEDFACF
  cputype:         0x01000007
  cpusubtype:      0x00000003
  filetype:        0x00000001
  ncmds:           1
  sizeofcmds:      232
  flags:           0x00002000
  reserved:        0x00000000
LoadCommands:
  - cmd:             LC_SEGMENT_64
    cmdsize:         232
    segname:         ''
    vmaddr:          0
    vmsize:          4
    fileoff:         392
    filesize:        4
    maxprot:         7
    initprot:        7
    nsects:          1
    flags:           0
    Sections:
      - sectname:        __data
        segname:         __DATA
        addr:            0x0000000000000000
        size:            0
        offset:          0x00000188
        align:           2
        reloff:          0x00000000
        nreloc:          0
        flags:           0x00000000
        reserved1:       0x00000000
        reserved2:       0x00000000
        reserved3:       0x00000000
        content:         CDAB3412

## Case 2: The content size equals the section size.
# RUN: yaml2obj --docnum=2 %s -o %t2
# RUN: llvm-readobj --sections --section-data %t2 | FileCheck %s --check-prefix=CASE2
# CASE2:       Index: 0
# CASE2-NEXT:  Name: __data (5F 5F 64 61 74 61 00 00 00 00 00 00 00 00 00 00)
# CASE2-NEXT:  Segment: __DATA (5F 5F 44 41 54 41 00 00 00 00 00 00 00 00 00 00)
# CASE2-NEXT:  Address: 0x0
# CASE2-NEXT:  Size: 0x4
# CASE2-NEXT:  Offset: 392
# CASE2-NEXT:  Alignment: 2
# CASE2-NEXT:  RelocationOffset: 0x0
# CASE2-NEXT:  RelocationCount: 0
# CASE2-NEXT:  Type: Regular (0x0)
# CASE2-NEXT:  Attributes [ (0x0)
# CASE2-NEXT:  ]
# CASE2-NEXT:  Reserved1: 0x0
# CASE2-NEXT:  Reserved2: 0x0
# CASE2-NEXT:  Reserved3: 0x0
# CASE2-NEXT:  SectionData (
# CASE2-NEXT:    0000: CDAB3412                             |..4.|
# CASE2-NEXT:  )

--- !mach-o
FileHeader:
  magic:           0xFEEDFACF
  cputype:         0x01000007
  cpusubtype:      0x00000003
  filetype:        0x00000001
  ncmds:           1
  sizeofcmds:      232
  flags:           0x00002000
  reserved:        0x00000000
LoadCommands:
  - cmd:             LC_SEGMENT_64
    cmdsize:         232
    segname:         ''
    vmaddr:          0
    vmsize:          4
    fileoff:         392
    filesize:        4
    maxprot:         7
    initprot:        7
    nsects:          1
    flags:           0
    Sections:
      - sectname:        __data
        segname:         __DATA
        addr:            0x0000000000000000
        size:            4
        offset:          0x00000188
        align:           2
        reloff:          0x00000000
        nreloc:          0
        flags:           0x00000000
        reserved1:       0x00000000
        reserved2:       0x00000000
        reserved3:       0x00000000
        content:         CDAB3412

## Case 3: The content size is less than the section size. In this case, the area
## after the custom content is filled with zeroes.
# RUN: yaml2obj --docnum=3 %s -o %t3
# RUN: llvm-readobj --sections --section-data %t3 | FileCheck %s --check-prefix=CASE3
# CASE3:       Index: 0
# CASE3-NEXT:  Name: __data (5F 5F 64 61 74 61 00 00 00 00 00 00 00 00 00 00)
# CASE3-NEXT:  Segment: __DATA (5F 5F 44 41 54 41 00 00 00 00 00 00 00 00 00 00)
# CASE3-NEXT:  Address: 0x0
# CASE3-NEXT:  Size: 0x4
# CASE3-NEXT:  Offset: 392
# CASE3-NEXT:  Alignment: 2
# CASE3-NEXT:  RelocationOffset: 0x0
# CASE3-NEXT:  RelocationCount: 0
# CASE3-NEXT:  Type: Regular (0x0)
# CASE3-NEXT:  Attributes [ (0x0)
# CASE3-NEXT:  ]
# CASE3-NEXT:  Reserved1: 0x0
# CASE3-NEXT:  Reserved2: 0x0
# CASE3-NEXT:  Reserved3: 0x0
# CASE3-NEXT:  SectionData (
# CASE3-NEXT:    0000: AA000000                             |....|
# CASE3-NEXT:  )

--- !mach-o
FileHeader:
  magic:           0xFEEDFACF
  cputype:         0x01000007
  cpusubtype:      0x00000003
  filetype:        0x00000001
  ncmds:           1
  sizeofcmds:      232
  flags:           0x00002000
  reserved:        0x00000000
LoadCommands:
  - cmd:             LC_SEGMENT_64
    cmdsize:         232
    segname:         ''
    vmaddr:          0
    vmsize:          4
    fileoff:         392
    filesize:        4
    maxprot:         7
    initprot:        7
    nsects:          1
    flags:           0
    Sections:
      - sectname:        __data
        segname:         __DATA
        addr:            0x0000000000000000
        size:            4
        offset:          0x00000188
        align:           2
        reloff:          0x00000000
        nreloc:          0
        flags:           0x00000000
        reserved1:       0x00000000
        reserved2:       0x00000000
        reserved3:       0x00000000
        content:         AA

## Case 4: Don't validate if size is missing.
# RUN: not yaml2obj --docnum=4 %s -o %t1 2>&1 | FileCheck %s --check-prefix=CASE4 --implicit-check-not=error:
# CASE4: error: missing required key 'size'
# CASE4: error: failed to parse YAML

--- !mach-o
FileHeader:
  magic:           0xFEEDFACF
  cputype:         0x01000007
  cpusubtype:      0x00000003
  filetype:        0x00000001
  ncmds:           1
  sizeofcmds:      232
  flags:           0x00002000
  reserved:        0x00000000
LoadCommands:
  - cmd:             LC_SEGMENT_64
    cmdsize:         232
    segname:         ''
    vmaddr:          0
    vmsize:          4
    fileoff:         392
    filesize:        4
    maxprot:         7
    initprot:        7
    nsects:          1
    flags:           0
    Sections:
      - sectname:        __data
        segname:         __DATA
        addr:            0x0000000000000000
        content:         AA
        offset:          0x00000188
        align:           2
        reloff:          0x00000000
        nreloc:          0
        flags:           0x00000000
        reserved1:       0x00000000
        reserved2:       0x00000000
        reserved3:       0x00000000