332 lines · yaml
1## Here we check that we are able to define sections with a type of "Fill".2## Fills are custom pieces of data that can be placed anywhere just like normal3## output sections, but they are not real output sections and you'll never see them in4## the section headers.5 6## Check we can create named and unnamed fills and use "Pattern" and "Size" fields7## to describe the data emitted.8## Check the data emitted and how it affects regular sections offsets.9## Check that the "Name" field is optional for fills.10## Check that "Size" can be greater than or equal to the pattern data size.11 12# RUN: yaml2obj --docnum=1 %s -o %t113# RUN: llvm-readelf --sections --headers %t1 | FileCheck %s --check-prefix=BASIC14 15# BASIC: Number of section headers: 516# BASIC: Section Headers:17# BASIC-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al18# BASIC-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0 019# BASIC-NEXT: [ 1] .foo PROGBITS 0000000000000000 000043 000002 00 0 0 020# BASIC-NEXT: [ 2] .bar PROGBITS 0000000000000000 000049 000001 00 0 0 021# BASIC-NEXT: [ 3] .strtab STRTAB 0000000000000000 00004b 000001 00 0 0 122# BASIC-NEXT: [ 4] .shstrtab STRTAB 0000000000000000 00004c 00001d 00 0 0 123 24## The fill we dump starts at (offset of .foo - 3), which is (0x43 - 3) = 0x40.25# RUN: od -t x1 -v -j 0x40 -N 11 %t1 | FileCheck %s --ignore-case --check-prefix=DATA26# DATA: aa bb aa 11 22 cc dd cc dd ff ee27 28--- !ELF29FileHeader:30 Class: ELFCLASS6431 Data: ELFDATA2LSB32 Type: ET_DYN33Sections:34 - Type: Fill35 Pattern: "AABB"36 Size: 0x337 - Name: .foo38 Type: SHT_PROGBITS39 Content: "1122"40 - Type: Fill41 Name: unusedName42 Pattern: "CCDD"43 Size: 444 - Name: .bar45 Type: SHT_PROGBITS46 Content: "FF"47 - Type: Fill48 Pattern: "EE"49 Size: 150 51## Check we can have no explicit regular sections in the YAML description, and can52## describe the content with the use of fills only.53## Check that "Size" can be less than the pattern data size.54 55# RUN: yaml2obj --docnum=2 %s -o %t256# RUN: llvm-readelf --sections --headers %t2 | FileCheck %s --check-prefix=NOSECTIONS57 58## The fill we dump starts at (offset of .strtab - 3 - 2), which is (0x45 - 5) = 0x40.59# RUN: od -t x1 -v -j 0x40 -N 6 %t2 | FileCheck %s --ignore-case --check-prefix=NOSECTIONS-DATA60 61# NOSECTIONS: Number of section headers: 362# NOSECTIONS: Section Headers:63# NOSECTIONS-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al64# NOSECTIONS-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0 065# NOSECTIONS-NEXT: [ 1] .strtab STRTAB 0000000000000000 000045 000001 00 0 0 166# NOSECTIONS-NEXT: [ 2] .shstrtab STRTAB 0000000000000000 000046 000013 00 0 0 167 68## .strtab that follows fills starts at 0x46 and always has a null character at the begining.69# NOSECTIONS-DATA: aa bb cc dd ee 0070 71--- !ELF72FileHeader:73 Class: ELFCLASS6474 Data: ELFDATA2LSB75 Type: ET_DYN76Sections:77 - Type: Fill78 Pattern: "AABBCCFF"79 Size: 0x380 - Type: Fill81 Pattern: "DDEEFF"82 Size: 0x283 84## Check we can use named fills when describing program headers.85## Check that fills consume the file size and therefore affect the p_filesz fields of segments.86## Check that the fill does not affect the p_align field of the segment.87 88# RUN: yaml2obj --docnum=3 %s -o %t389# RUN: llvm-readelf --sections --program-headers %t3 | FileCheck %s --check-prefix=PHDR90 91# PHDR: [Nr] Name Type Address Off Size ES Flg Lk Inf Al92# PHDR: [ 0] NULL 0000000000000000 000000 000000 00 0 0 093# PHDR: [ 1] .bar PROGBITS 0000000000000100 0000c0 000005 00 0 0 294# PHDR: [ 2] .strtab STRTAB 0000000000000000 00010a 000001 00 0 0 195# PHDR: [ 3] .shstrtab STRTAB 0000000000000000 00010b 000018 00 0 0 196 97# PHDR: Program Headers:98# PHDR: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align99# PHDR: LOAD 0x0000b0 0x0000000000000100 0x0000000000000100 0x00005a 0x00005a 0x2100# PHDR: GNU_RELRO 0x0000c5 0x0000000000000105 0x0000000000000105 0x000045 0x000045 0x1101 102--- !ELF103FileHeader:104 Class: ELFCLASS64105 Data: ELFDATA2LSB106 Type: ET_DYN107Sections:108 - Type: Fill109 Name: fill1110 Pattern: ""111 Size: 0x10112 - Name: .bar113 Type: SHT_PROGBITS114 Size: 0x5115 Address: 0x100116 AddressAlign: 2117 - Type: Fill118 Name: fill2119 Pattern: ""120 Size: 0x45121ProgramHeaders:122 - Type: PT_LOAD123 VAddr: 0x100124 FirstSec: fill1125 LastSec: fill2126 - Type: PT_GNU_RELRO127 VAddr: 0x105128 FirstSec: fill2129 LastSec: fill2130 131## Check that the "Pattern" field is not mandatory.132# RUN: yaml2obj --docnum=4 2>&1 -o %t4 %s133# RUN: llvm-readelf --sections %t4 | FileCheck %s --check-prefix=NOPATTERN134 135## The fill we dump starts at (offset of .strtab - 1 - 3 - 1), which is (0x45 - 5) = 0x40.136# RUN: od -t x1 -v -j 0x40 -N 5 %t4 | FileCheck %s --ignore-case --check-prefix=NOPATTERN-DATA137 138# NOPATTERN: [Nr] Name Type Address Off139# NOPATTERN: [ 1] .strtab STRTAB 0000000000000000 000045140 141# NOPATTERN-DATA: aa 00 00 00 bb142 143--- !ELF144FileHeader:145 Class: ELFCLASS64146 Data: ELFDATA2LSB147 Type: ET_DYN148Sections:149 - Type: Fill150 Size: 0x1151 Pattern: "AA"152 - Type: Fill153 Size: 0x3154 - Type: Fill155 Size: 0x1156 Pattern: "BB"157 158## Check that the "Size" field is mandatory.159# RUN: not yaml2obj --docnum=5 2>&1 %s | FileCheck %s --check-prefix=NOSIZE --implicit-check-not=error:160 161# NOSIZE: error: missing required key 'Size'162# NOSIZE: error: failed to parse YAML163 164--- !ELF165FileHeader:166 Class: ELFCLASS64167 Data: ELFDATA2LSB168 Type: ET_DYN169Sections:170 - Type: Fill171 Pattern: "00"172 173## Check that fills are not allowed to have duplicate names.174# RUN: not yaml2obj --docnum=6 2>&1 %s | FileCheck %s --check-prefix=UNIQUE-NAME175 176# UNIQUE-NAME: error: repeated section/fill name: 'foo' at YAML section/fill number 2177# UNIQUE-NAME: error: repeated section/fill name: 'foo' at YAML section/fill number 3178 179--- !ELF180FileHeader:181 Class: ELFCLASS64182 Data: ELFDATA2LSB183 Type: ET_DYN184Sections:185 - Type: Fill186 Name: foo187 Pattern: "00"188 Size: 1189 - Type: Fill190 Name: foo191 Pattern: "00"192 Size: 1193 - Name: foo194 Type: SHT_PROGBITS195 196## Check that "Pattern" can be empty, when "Size" is zero.197# RUN: yaml2obj --docnum=7 2>&1 %s -o %t7198# RUN: llvm-readelf --sections %t7 | FileCheck %s --check-prefix=NOOP199 200# NOOP: [Nr] Name Type Address Off201# NOOP: [ 1] begin PROGBITS 0000000000000000 000040202# NOOP: [ 2] end PROGBITS 0000000000000000 000041203 204--- !ELF205FileHeader:206 Class: ELFCLASS64207 Data: ELFDATA2LSB208 Type: ET_DYN209Sections:210 - Name: begin211 Type: SHT_PROGBITS212 Size: 1213 - Type: Fill214 Pattern: ""215 Size: 0216 - Name: end217 Type: SHT_PROGBITS218 Size: 1219 220## Check that we can have an empty "Pattern", but have non-zero "Size".221## In this case we emit Size number of zeroes to the output.222 223# RUN: yaml2obj --docnum=8 2>&1 -o %t8 %s224# RUN: llvm-readelf --sections %t8 | FileCheck %s --check-prefix=EMPTY-PATTERN225 226## The fill we dump starts at (offset of .strtab - 1 - 3 - 1), which is (0x45 - 5) = 0x40.227# RUN: od -t x1 -v -j 0x40 -N 5 %t8 | FileCheck %s --ignore-case --check-prefix=EMPTY-PATTERN-DATA228 229# EMPTY-PATTERN: Section Headers:230# EMPTY-PATTERN-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al231# EMPTY-PATTERN-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0 0232# EMPTY-PATTERN-NEXT: [ 1] .strtab STRTAB 0000000000000000 000045 000001 00 0 0 1233 234# EMPTY-PATTERN-DATA: aa 00 00 00 bb235 236--- !ELF237FileHeader:238 Class: ELFCLASS64239 Data: ELFDATA2LSB240 Type: ET_DYN241Sections:242 - Type: Fill243 Pattern: "AA"244 Size: 0x1245 - Type: Fill246 Size: 3247 Pattern: ""248 - Type: Fill249 Pattern: "BB"250 Size: 0x1251 252## Check that "Size" can't be 0, when "Pattern" is not empty.253# RUN: not yaml2obj --docnum=9 2>&1 %s | FileCheck %s --check-prefix=ZERO-SIZE-ERR254 255# ZERO-SIZE-ERR: error: "Size" can't be 0 when "Pattern" is not empty256 257--- !ELF258FileHeader:259 Class: ELFCLASS64260 Data: ELFDATA2LSB261 Type: ET_DYN262Sections:263 - Type: Fill264 Pattern: "00"265 Size: 0266 267## Check we report an error when a program header references268## an unknown section or fill and have at least one Fill defined.269 270# RUN: not yaml2obj --docnum=10 2>&1 %s | FileCheck %s --check-prefix=UNKNOWN-ERR271# UNKNOWN-ERR: error: unknown section or fill referenced: 'fill' by the 'FirstSec' key of the program header with index 0272# UNKNOWN-ERR: error: unknown section or fill referenced: 'fill' by the 'LastSec' key of the program header with index 0273 274--- !ELF275FileHeader:276 Class: ELFCLASS64277 Data: ELFDATA2LSB278 Type: ET_DYN279Sections:280 - Type: Fill281 Pattern: ""282 Size: 0283ProgramHeaders:284 - Type: PT_LOAD285 FirstSec: fill286 LastSec: fill287 288## Show that we can use the "Offset" key to set an arbitrary offset for a Fill.289 290## 0x41 is the minimal possible valid offset for Fill,291## because the .foo section of size 0x1 is placed at 0x40.292# RUN: yaml2obj --docnum=11 -DOFFSET=0x41 -o %t11 %s293# RUN: llvm-readelf --section-headers %t11 | FileCheck %s --check-prefix=OFFSET-MIN294 295## 0x123 is an arbitrary offset.296# RUN: yaml2obj --docnum=11 -DOFFSET=0x123 -o %t12 %s297# RUN: llvm-readelf --section-headers %t12 | FileCheck %s --check-prefix=OFFSET298 299# OFFSET-MIN: Section Headers:300# OFFSET-MIN-NEXT: [Nr] Name Type Address Off Size301# OFFSET-MIN-NEXT: [ 0] NULL 0000000000000000 000000 000000302# OFFSET-MIN-NEXT: [ 1] .foo PROGBITS 0000000000000000 000040 000001303# OFFSET-MIN-NEXT: [ 2] .bar PROGBITS 0000000000000000 000042 000001304 305# OFFSET: Section Headers:306# OFFSET-NEXT: [Nr] Name Type Address Off Size307# OFFSET-NEXT: [ 0] NULL 0000000000000000 000000 000000308# OFFSET-NEXT: [ 1] .foo PROGBITS 0000000000000000 000040 000001309# OFFSET-NEXT: [ 2] .bar PROGBITS 0000000000000000 000124 000001310 311--- !ELF312FileHeader:313 Class: ELFCLASS64314 Data: ELFDATA2LSB315 Type: ET_DYN316Sections:317 - Name: .foo318 Type: SHT_PROGBITS319 Size: 1320 - Type: Fill321 Pattern: "AA"322 Size: 0x1323 Offset: [[OFFSET]]324 - Name: .bar325 Type: SHT_PROGBITS326 Size: 1327 328## Show that the "Offset" value can't go backward.329# RUN: not yaml2obj --docnum=11 -DOFFSET=0x40 2>&1 %s | FileCheck %s --check-prefix=OFFSET-ERR330 331# OFFSET-ERR: error: the 'Offset' value (0x40) goes backward332