1## For regular sections, it is common to specify `Size` and/or `Content` fields in YAML.
2## Here we test the behavior in different cases.
3
4## In this case, we have both `Content` and `Size` fields specified and `Size`
5## is less than content size. Check we report an error.
6
7# RUN: not yaml2obj --docnum=1 %s -o %t1 2>&1 | FileCheck %s --check-prefix=ERR
8# ERR: error: Section size must be greater than or equal to the content size
9
10--- !ELF
11FileHeader:
12  Class: ELFCLASS64
13  Data:  ELFDATA2LSB
14  Type:  ET_DYN
15Sections:
16  - Name:    .foo
17    Type:    SHT_PROGBITS
18    Content: "FF"
19    Size:    0
20
21## In this case, we have both `Content` and `Size` fields specified and
22## `Size` is equal to the content size. We check that this is allowed and
23## that the output section has a correct size value.
24
25# RUN: yaml2obj --docnum=2 %s -o %t2
26# RUN: llvm-readobj --section-data -S %t2 | FileCheck %s --check-prefix=CASE2
27
28# CASE2:      Name: .foo
29# CASE2-NEXT: Type: SHT_PROGBITS
30# CASE2-NEXT: Flags [
31# CASE2-NEXT: ]
32# CASE2-NEXT: Address: 0x0
33# CASE2-NEXT: Offset: 0x40
34# CASE2-NEXT: Size: 1
35# CASE2-NEXT: Link: 0
36# CASE2-NEXT: Info: 0
37# CASE2-NEXT: AddressAlignment: 0
38# CASE2-NEXT: EntrySize: 0
39# CASE2-NEXT: SectionData (
40# CASE2-NEXT:   0000: FF
41# CASE2-NEXT: )
42
43--- !ELF
44FileHeader:
45  Class: ELFCLASS64
46  Data:  ELFDATA2LSB
47  Type:  ET_DYN
48Sections:
49  - Name:    .foo
50    Type:    SHT_PROGBITS
51    Content: "FF"
52    Size:    1
53
54## Check we can specify only `Content`.
55
56# RUN: yaml2obj --docnum=3 %s -o %t3
57# RUN: llvm-readobj --section-data -S %t3 | FileCheck %s --check-prefix=CASE2
58
59--- !ELF
60FileHeader:
61  Class: ELFCLASS64
62  Data:  ELFDATA2LSB
63  Type:  ET_DYN
64Sections:
65  - Name:    .foo
66    Type:    SHT_PROGBITS
67    Content: "FF"
68
69## Check we can specify only `Size`.
70
71# RUN: yaml2obj --docnum=4 %s -o %t4
72# RUN: llvm-readobj --section-data -S %t4 | FileCheck %s --check-prefix=CASE3
73
74# CASE3:      Name: .foo
75# CASE3-NEXT: Type: SHT_PROGBITS
76# CASE3-NEXT: Flags [
77# CASE3-NEXT: ]
78# CASE3-NEXT: Address: 0x0
79# CASE3-NEXT: Offset: 0x40
80# CASE3-NEXT: Size: 1
81# CASE3-NEXT: Link: 0
82# CASE3-NEXT: Info: 0
83# CASE3-NEXT: AddressAlignment: 0
84# CASE3-NEXT: EntrySize: 0
85# CASE3-NEXT: SectionData (
86# CASE3-NEXT:   0000: 00
87# CASE3-NEXT: )
88
89--- !ELF
90FileHeader:
91  Class: ELFCLASS64
92  Data:  ELFDATA2LSB
93  Type:  ET_DYN
94Sections:
95  - Name: .foo
96    Type: SHT_PROGBITS
97    Size: 1
98
99## Check we can specify both `Size` and `Content` when size is greater
100## than content size. In this case zeroes are added as padding
101## after the specified content.
102
103# RUN: yaml2obj --docnum=5 %s -o %t5
104# RUN: llvm-readobj --section-data -S %t5 | FileCheck %s --check-prefix=CASE4
105
106# CASE4:      Name: .foo
107# CASE4-NEXT: Type: SHT_PROGBITS
108# CASE4-NEXT: Flags [
109# CASE4-NEXT: ]
110# CASE4-NEXT: Address: 0x0
111# CASE4-NEXT: Offset: 0x40
112# CASE4-NEXT: Size: 3
113# CASE4-NEXT: Link: 0
114# CASE4-NEXT: Info: 0
115# CASE4-NEXT: AddressAlignment: 0
116# CASE4-NEXT: EntrySize: 0
117# CASE4-NEXT: SectionData (
118# CASE4-NEXT:   0000: FF0000
119# CASE4-NEXT: )
120
121--- !ELF
122FileHeader:
123  Class: ELFCLASS64
124  Data:  ELFDATA2LSB
125  Type:  ET_DYN
126Sections:
127  - Name:    .foo
128    Type:    SHT_PROGBITS
129    Content: "FF"
130    Size:    3
131
132## Check we emit an empty section if neither 'Content' nor 'Size' were set.
133
134# RUN: yaml2obj --docnum=6 %s -o %t6
135# RUN: llvm-readobj %t6 --sections | FileCheck %s --check-prefix=CASE5
136
137# CASE5:      Name: .foo
138# CASE5-NEXT: Type: SHT_PROGBITS
139# CASE5-NEXT: Flags [
140# CASE5-NEXT: ]
141# CASE5-NEXT: Address: 0x0
142# CASE5-NEXT: Offset: 0x40
143# CASE5-NEXT: Size: 0
144
145--- !ELF
146FileHeader:
147  Class: ELFCLASS64
148  Data:  ELFDATA2LSB
149  Type:  ET_DYN
150Sections:
151  - Name: .foo
152    Type: SHT_PROGBITS
153
154# RUN: not yaml2obj --docnum=7 %s 2>&1 | FileCheck %s --check-prefix=ERR2
155
156--- !ELF
157FileHeader:
158  Class: ELFCLASS64
159  Data:  ELFDATA2LSB
160  Type:  ET_REL
161Sections:
162  - Name: .data
163    Type: SHT_PROGBITS
164    Flags: [ SHF_ALLOC ]
165    Content: 0000000000000000
166    Size: 2
167
168# ERR2:      error: Section size must be greater than or equal to the content size
169# ERR2-NEXT: - Name: .data
170# ERR2-NEXT:   ^
171# ERR2-NEXT: error: failed to parse YAML input
172