1## In this test we check that can redefine the null section in the YAML. 2 3## Test the default output first. 4 5# RUN: yaml2obj --docnum=1 %s -o %t1 6# RUN: llvm-readelf --sections %t1 | FileCheck %s --check-prefix=DEFAULT 7 8# DEFAULT: Section Headers: 9# DEFAULT-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al 10# DEFAULT-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 11# DEFAULT-NEXT: [ 1] .strtab STRTAB 0000000000000000 000040 000001 00 0 0 1 12# DEFAULT-NEXT: [ 2] .shstrtab STRTAB 0000000000000000 000041 000013 00 0 0 1 13 14--- !ELF 15FileHeader: 16 Class: ELFCLASS64 17 Data: ELFDATA2LSB 18 Type: ET_REL 19 20## Now define a SHT_NULL section with fields all zeroed. 21## In this case it is equal to the section created by default. 22 23# RUN: yaml2obj --docnum=2 %s -o %t2 24# RUN: llvm-readelf --sections %t2 | FileCheck %s --check-prefix=DEFAULT 25 26--- !ELF 27FileHeader: 28 Class: ELFCLASS64 29 Data: ELFDATA2LSB 30 Type: ET_REL 31Sections: 32 - Type: SHT_NULL 33 Name: '' 34 Flags: [ ] 35 AddressAlign: 0x0 36 Size: 0x0 37 EntSize: 0x0 38 Link: 0 39 Info: 0 40 Address: 0x0 41 42## Check we can redefine fields of the first SHT_NULL section. 43 44# RUN: yaml2obj --docnum=3 %s -o %t3 45# RUN: llvm-readelf --sections %t3 | FileCheck %s --check-prefix=REDEFINE 46 47# REDEFINE: Section Headers: 48# REDEFINE-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al 49# REDEFINE-NEXT: [ 0] .foo NULL 0000000000000006 000000 000002 03 A 4 5 1 50 51--- !ELF 52FileHeader: 53 Class: ELFCLASS64 54 Data: ELFDATA2LSB 55 Type: ET_REL 56Sections: 57 - Type: SHT_NULL 58 Name: .foo 59 Flags: [ SHF_ALLOC ] 60 AddressAlign: 0x1 61 Size: 0x2 62 EntSize: 0x3 63 Link: 4 64 Info: 5 65 Address: 0x6 66 67## Check that file size does not change if we redefine the Size 68## of the first SHT_NULL section. 69 70# RUN: yaml2obj --docnum=4 %s -o %t4 71# RUN: wc -c < %t3 > %t.txt 72# RUN: wc -c < %t4 >> %t.txt 73# RUN: FileCheck %s --input-file=%t.txt --check-prefix=SIZE 74 75# SIZE: [[FILESIZE:.*]] 76# SIZE: [[FILESIZE]] 77 78--- !ELF 79FileHeader: 80 Class: ELFCLASS64 81 Data: ELFDATA2LSB 82 Type: ET_REL 83Sections: 84 - Type: SHT_NULL 85 Name: .foo 86 Flags: [ SHF_ALLOC ] 87 AddressAlign: 0x1 88 Size: 0xFFFF 89 EntSize: 0x3 90 Link: 4 91 Info: 5 92 Address: 0x6 93 94## Check we are still able to describe other sections too. 95 96# RUN: yaml2obj --docnum=5 %s -o %t5 97# RUN: llvm-readelf --sections %t5 | FileCheck %s --check-prefix=OTHER-SECTION 98 99# OTHER-SECTION: Section Headers: 100# OTHER-SECTION-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al 101# OTHER-SECTION-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 102# OTHER-SECTION-NEXT: [ 1] foo PROGBITS 0000000000000000 000040 000000 00 0 0 0 103# OTHER-SECTION-NEXT: [ 2] .strtab STRTAB 0000000000000000 000040 000001 00 0 0 1 104# OTHER-SECTION-NEXT: [ 3] .shstrtab STRTAB 0000000000000000 000041 000017 00 0 0 1 105 106--- !ELF 107FileHeader: 108 Class: ELFCLASS64 109 Data: ELFDATA2LSB 110 Type: ET_REL 111Sections: 112 - Type: SHT_NULL 113 Name: '' 114 Flags: [ ] 115 AddressAlign: 0x0 116 Size: 0x0 117 EntSize: 0x0 118 Link: 0 119 - Type: SHT_PROGBITS 120 Name: 'foo' 121 122## Check we report an error if null section sh_link field refers to an unknown section. 123 124# RUN: not yaml2obj --docnum=6 %s -o %t6 2>&1 | FileCheck %s --check-prefix=CASE4 125 126# CASE4: error: unknown section referenced: '.foo' by YAML section '(index 0)' 127# CASE4-NEXT: error: unknown section referenced: '.bar' by YAML section '(index 1)' 128 129--- !ELF 130FileHeader: 131 Class: ELFCLASS64 132 Data: ELFDATA2LSB 133 Type: ET_REL 134Sections: 135 - Type: SHT_NULL 136 Link: .foo 137 - Type: SHT_NULL 138 Link: .bar 139 140## Check that null section fields are set to zero, if they are unspecified. 141 142# RUN: yaml2obj --docnum=7 %s -o %t7 143# RUN: llvm-readelf --sections %t7 | FileCheck %s --check-prefix=DEFAULT 144 145--- !ELF 146FileHeader: 147 Class: ELFCLASS64 148 Data: ELFDATA2LSB 149 Type: ET_REL 150Sections: 151 - Type: SHT_NULL 152 153## Check we do not crash if we have more than one SHT_NULL section. 154 155# RUN: yaml2obj --docnum=8 %s -o %t8 156# RUN: llvm-readelf --sections %t8 | FileCheck %s --check-prefix=MULTIPLE 157 158# MULTIPLE: Section Headers: 159# MULTIPLE-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al 160# MULTIPLE-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 161# MULTIPLE-NEXT: [ 1] .foo NULL 0000000000000123 000040 000020 10 A 1 2 0 162 163--- !ELF 164FileHeader: 165 Class: ELFCLASS64 166 Data: ELFDATA2LSB 167 Type: ET_REL 168Sections: 169 - Type: SHT_NULL 170 - Type: SHT_NULL 171 Name: .foo 172 Flags: [ SHF_ALLOC ] 173 Size: 0x20 174 EntSize: 0x10 175 Link: 1 176 Info: 2 177 Address: 0x123 178 179## Check we can override the sh_offset/sh_size fields of the first SHT_NULL section if requested. 180 181# RUN: yaml2obj --docnum=9 %s -o %t9 182# RUN: llvm-readelf --sections %t9 | FileCheck %s --check-prefix=OVERRIDE 183 184# OVERRIDE: Section Headers: 185# OVERRIDE-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al 186# OVERRIDE-NEXT: [ 0] NULL 0000000000000000 000007 000008 00 0 0 0 187 188--- !ELF 189FileHeader: 190 Class: ELFCLASS64 191 Data: ELFDATA2LSB 192 Type: ET_REL 193Sections: 194 - Type: SHT_NULL 195 Size: 0x2 196 ShOffset: 0x7 197 ShSize: 0x8 198 199## Check that we can set an offset for the SHT_NULL section explicitly using the "Offset" key. 200## Check it affects the section header table offset. 201# RUN: yaml2obj --docnum=10 %s -DOFFSET=0x100 -o %t10 202# RUN: llvm-readelf --headers --sections %t10 | FileCheck %s --check-prefix=EXPLICIT-OFFSET-A 203# RUN: yaml2obj --docnum=10 %s -DOFFSET=0x200 -o %t11 204# RUN: llvm-readelf --headers --sections %t11 | FileCheck %s --check-prefix=EXPLICIT-OFFSET-B 205 206# EXPLICIT-OFFSET-A: Start of section headers: 280 (bytes into file) 207# EXPLICIT-OFFSET-A: [Nr] Name Type Address Off 208# EXPLICIT-OFFSET-A-NEXT: [ 0] NULL 0000000000000000 000100 209 210# EXPLICIT-OFFSET-B: Start of section headers: 536 (bytes into file) 211# EXPLICIT-OFFSET-B: [Nr] Name Type Address Off 212# EXPLICIT-OFFSET-B-NEXT: [ 0] NULL 0000000000000000 000200 213 214--- !ELF 215FileHeader: 216 Class: ELFCLASS64 217 Data: ELFDATA2LSB 218 Type: ET_REL 219Sections: 220 - Type: SHT_NULL 221 Offset: [[OFFSET]] 222