568 lines · yaml
1## Check how yaml2obj produces SHT_NOTE sections.2 3## Check we can describe SHT_NOTE using the "Notes" tag. We can define4## notes using names, descriptions and types.5## Check we produce a valid name size and description size fields.6## Check we produce valid paddings.7 8# RUN: yaml2obj --docnum=1 %s -o %t19# RUN: llvm-readobj --sections --section-data %t1 | FileCheck %s --check-prefix=NOTE10 11# NOTE: Section {12# NOTE: Index: 113# NOTE-NEXT: Name: .note.foo (1)14# NOTE-NEXT: Type: SHT_NOTE (0x7)15# NOTE-NEXT: Flags [ (0x2)16# NOTE-NEXT: SHF_ALLOC (0x2)17# NOTE-NEXT: ]18# NOTE-NEXT: Address:19# NOTE-NEXT: Offset:20# NOTE-NEXT: Size: 3621# NOTE-NEXT: Link: 022# NOTE-NEXT: Info: 023# NOTE-NEXT: AddressAlignment: 024# NOTE-NEXT: EntrySize: 025# NOTE-NEXT: SectionData (26## namesz == (0x03000000) == sizeof("AB") + NUL terminator.27## descsz == (0x00000000) for an empty description.28## Check we produce a valid 2 bytes zeroes padding after the Name.29# NOTE-NEXT: 0000: 03000000 00000000 FF000000 41420000 |............AB..|30## namesz == (0x04000000) == sizeof("ABC") + NUL terminator.31## descsz == (0x06000000) == sizeof("123456").32## Check we produce a valid (zero align to 4) 1 byte padding after the Name.33## Check we produce a valid (zero align to 4) 2 bytes padding after the Desc.34# NOTE-NEXT: 0010: 04000000 03000000 FE000000 41424300 |............ABC.|35# NOTE-NEXT: 0020: 12345600 |.4V.|36# NOTE-NEXT: )37 38--- !ELF39FileHeader:40 Class: ELFCLASS6441 Data: ELFDATA2LSB42 Type: ET_REL43Sections:44 - Name: .note.foo45 Type: SHT_NOTE46 Flags: [ SHF_ALLOC ]47 Notes:48 - Name: AB49 Desc: ''50 Type: 0xFF51 - Name: ABC52 Desc: '123456'53 Type: 25454 55## Check that for 32-bit little-endian case we produce the same section content.56 57# RUN: yaml2obj --docnum=2 %s -o %t258# RUN: llvm-readobj --sections --section-data %t2 | FileCheck %s --check-prefix=NOTE59 60--- !ELF61FileHeader:62 Class: ELFCLASS3263 Data: ELFDATA2LSB64 Type: ET_REL65Sections:66 - Name: .note.foo67 Type: SHT_NOTE68 Flags: [ SHF_ALLOC ]69 Notes:70 - Name: AB71 Desc: ''72 Type: 0xFF73 - Name: ABC74 Desc: '123456'75 Type: 25476 77## Check big-endian 32/64 bit cases.78## Check they produce the same content.79 80# RUN: yaml2obj --docnum=3 %s -o %t381# RUN: llvm-readobj --sections --section-data %t3 | FileCheck %s --check-prefix=NOTE-BE82# RUN: yaml2obj --docnum=4 %s -o %t483# RUN: llvm-readobj --sections --section-data %t4 | FileCheck %s --check-prefix=NOTE-BE84 85# NOTE-BE: Name: .note.foo86# NOTE-BE: SectionData (87# NOTE-BE-NEXT: 0000: 00000004 00000003 000000FE 41424300 |88# NOTE-BE-NEXT: 0010: 12345600 |89# NOTE-BE-NEXT: )90 91--- !ELF92FileHeader:93 Class: ELFCLASS3294 Data: ELFDATA2MSB95 Type: ET_REL96Sections:97 - Name: .note.foo98 Type: SHT_NOTE99 Notes:100 - Name: ABC101 Desc: '123456'102 Type: 254103 104--- !ELF105FileHeader:106 Class: ELFCLASS64107 Data: ELFDATA2MSB108 Type: ET_REL109Sections:110 - Name: .note.foo111 Type: SHT_NOTE112 Notes:113 - Name: ABC114 Desc: '123456'115 Type: 254116 117## Check that 'Type' field is mandatory. 118 119# RUN: not yaml2obj --docnum=5 %s 2>&1 | FileCheck %s --check-prefix=TYPE-REQ120# TYPE-REQ: error: missing required key 'Type'121 122--- !ELF123FileHeader:124 Class: ELFCLASS64125 Data: ELFDATA2LSB126 Type: ET_REL127Sections:128 - Name: .note.foo129 Type: SHT_NOTE130 Notes:131 - Name: ''132 Desc: ''133 134## Check that neither `Name` nor `Desc` are mandatory fields.135 136# RUN: yaml2obj --docnum=6 %s -o %t6137# RUN: llvm-readobj --sections --section-data %t6 | FileCheck %s --check-prefix=NAME-DESC138 139# NAME-DESC: Name: .note.foo140# NAME-DESC: SectionData (141# NAME-DESC-NEXT: 0000: 00000000 00000000 FF000000 |142# NAME-DESC-NEXT: )143 144--- !ELF145FileHeader:146 Class: ELFCLASS64147 Data: ELFDATA2LSB148 Type: ET_REL149Sections:150 - Name: .note.foo151 Type: SHT_NOTE152 Notes:153 - Type: 0xFF154 155## Check we can use the "Content" tag to specify any data for SHT_NOTE sections.156 157# RUN: yaml2obj --docnum=7 %s -o %t7158# RUN: llvm-readobj --sections --section-data %t7 | FileCheck %s --check-prefix=CONTENT159 160# CONTENT: Name: .note.foo161# CONTENT: SectionData (162# CONTENT-NEXT: 0000: 11223344 55 |163# CONTENT-NEXT: )164 165--- !ELF166FileHeader:167 Class: ELFCLASS64168 Data: ELFDATA2LSB169 Type: ET_DYN170Sections:171 - Name: .note.foo172 Type: SHT_NOTE173 Content: "1122334455"174 175## Check we emit an empty section if neither "Content", "Size" nor "Notes" were set.176 177# RUN: yaml2obj --docnum=8 %s -o %t8178# RUN: llvm-readelf --sections %t8 | FileCheck %s --check-prefix=NO-TAGS179 180# NO-TAGS: [Nr] Name Type Address Off Size181# NO-TAGS: [ 1] .note.foo NOTE 0000000000000000 000040 000000182 183--- !ELF184FileHeader:185 Class: ELFCLASS64186 Data: ELFDATA2LSB187 Type: ET_DYN188Sections:189 - Name: .note.foo190 Type: SHT_NOTE191 192## "Content" and "Notes" cannot be used together to describe the SHT_NOTE section.193 194# RUN: not yaml2obj --docnum=9 %s 2>&1 | FileCheck %s --check-prefix=CONTENT-NOTES195 196# CONTENT-NOTES: error: "Notes" cannot be used with "Content" or "Size"197 198--- !ELF199FileHeader:200 Class: ELFCLASS64201 Data: ELFDATA2LSB202 Type: ET_DYN203Sections:204 - Name: .note.foo205 Type: SHT_NOTE206 Content: ""207 Notes: []208 209## "Size" and "Notes" cannot be used together to describe the SHT_NOTE section.210 211# RUN: not yaml2obj --docnum=10 %s 2>&1 | FileCheck %s --check-prefix=CONTENT-NOTES212 213--- !ELF214FileHeader:215 Class: ELFCLASS64216 Data: ELFDATA2LSB217 Type: ET_DYN218Sections:219 - Name: .note.foo220 Type: SHT_NOTE221 Size: 1222 Notes: []223 224## Check we can use only "Size" to create a SHT_NOTE section.225 226# RUN: yaml2obj --docnum=11 %s -o %t11227# RUN: llvm-readobj --sections --section-data %t11 | FileCheck %s --check-prefix=SIZE228 229# SIZE: Name: .note.foo230# SIZE: SectionData (231# SIZE-NEXT: 0000: 00000000 00000000 00000000 00000000 |232# SIZE-NEXT: 0010: 00 |233# SIZE-NEXT: )234 235--- !ELF236FileHeader:237 Class: ELFCLASS64238 Data: ELFDATA2LSB239 Type: ET_EXEC240Sections:241 - Name: .note.foo242 Type: SHT_NOTE243 Size: 0x11244 245## Check we can use "Size" and "Content" together to create a SHT_NOTE section.246 247# RUN: yaml2obj --docnum=12 %s -o %t12248# RUN: llvm-readobj --sections --section-data %t12 | FileCheck %s --check-prefix=SIZE-CONTENT249 250# SIZE-CONTENT: Name: .note.sizegr251# SIZE-CONTENT: SectionData (252# SIZE-CONTENT-NEXT: 0000: 11223300 00 |253# SIZE-CONTENT-NEXT: )254 255# SIZE-CONTENT: Name: .note.sizeeq256# SIZE-CONTENT: SectionData (257# SIZE-CONTENT-NEXT: 0000: 112233 |258# SIZE-CONTENT-NEXT: )259 260--- !ELF261FileHeader:262 Class: ELFCLASS64263 Data: ELFDATA2LSB264 Type: ET_EXEC265Sections:266 - Name: .note.sizegr267 Type: SHT_NOTE268 Size: 0x5269 Content: "112233"270 - Name: .note.sizeeq271 Type: SHT_NOTE272 Size: 0x3273 Content: "112233"274 275## Check that when "Size" and "Content" are used together, the size276## must be greater than or equal to the content size.277 278# RUN: not yaml2obj --docnum=13 %s 2>&1 | FileCheck %s --check-prefix=SIZE-CONTENT-ERR279# SIZE-CONTENT-ERR: error: Section size must be greater than or equal to the content size280 281--- !ELF282FileHeader:283 Class: ELFCLASS64284 Data: ELFDATA2LSB285 Type: ET_EXEC286Sections:287 - Name: .note288 Type: SHT_NOTE289 Size: 0x1290 Content: "1122"291 292## Check we can't use "Size" and "Notes" tags together.293 294# RUN: not yaml2obj --docnum=14 %s 2>&1 | FileCheck %s --check-prefix=CONTENT-NOTES295 296--- !ELF297FileHeader:298 Class: ELFCLASS64299 Data: ELFDATA2LSB300 Type: ET_EXEC301Sections:302 - Name: .note303 Type: SHT_NOTE304 Size: 0x1305 Notes: []306 307## Check that we can use NT_* names for the note type.308 309# RUN: yaml2obj --docnum=15 %s -o %t15310# RUN: llvm-readobj --sections --section-data %t15 | FileCheck %s --check-prefix=TEXTUAL-TYPE311 312# TEXTUAL-TYPE: Name: .note.foo313# TEXTUAL-TYPE: SectionData (314# TEXTUAL-TYPE-NEXT: 0000: 03000000 00000000 03000000 41420000 |............AB..|315# TEXTUAL-TYPE-NEXT: 0010: 04000000 03000000 01000000 41424300 |............ABC.|316# TEXTUAL-TYPE-NEXT: 0020: 12345600 |.4V.|317# TEXTUAL-TYPE-NEXT: )318 319 320--- !ELF321FileHeader:322 Class: ELFCLASS64323 Data: ELFDATA2LSB324 Type: ET_EXEC325Sections:326 - Name: .note.foo327 Type: SHT_NOTE328 Flags: [ SHF_ALLOC ]329 Notes:330 - Name: AB331 Desc: ''332 Type: NT_GNU_BUILD_ID333 - Name: ABC334 Desc: '123456'335 Type: NT_VERSION336 337## Check that an incorrect alignment is reported.338 339# RUN: not yaml2obj --docnum=16 %s 2>&1 | FileCheck %s --check-prefix=ERR_ALIGN1340# ERR_ALIGN1: error: .note.foo: invalid alignment for a note section: 0x1341 342--- !ELF343FileHeader:344 Class: ELFCLASS64345 Data: ELFDATA2LSB346 Type: ET_EXEC347Sections:348 - Name: .note.foo349 Type: SHT_NOTE350 AddressAlign: 1351 Notes:352 - Type: 0x1353 354## Check that note entries and their "Desc" fields are aligned according to the355## specified section alignment.356 357# RUN: yaml2obj --docnum=17 -D ELFCLASS=64 %s -o - | \358# RUN: llvm-readobj --sections --section-data --notes - | \359# RUN: FileCheck %s --check-prefix=TEST17360 361# RUN: yaml2obj --docnum=17 -D ELFCLASS=32 %s -o - | \362# RUN: llvm-readobj --sections --section-data --notes - | \363# RUN: FileCheck %s --check-prefix=TEST17364 365# TEST17: Name: .note.foo4366# TEST17: SectionData (367# TEST17-NEXT: 0000: 05000000 02000000 01000000 41424344 |............ABCD|368# TEST17-NEXT: 0010: 00000000 01020000 00000000 03000000 |................|369# TEST17-NEXT: 0020: 02000000 03040500 04000000 00000000 |................|370# TEST17-NEXT: 0030: 03000000 474E5500 |....GNU.|371# TEST17-NEXT: )372# TEST17: Name: .note.foo8373# TEST17: SectionData (374# TEST17-NEXT: 0000: 05000000 02000000 01000000 41424344 |............ABCD|375# TEST17-NEXT: 0010: 00000000 00000000 01020000 00000000 |................|376# TEST17-NEXT: 0020: 00000000 03000000 02000000 00000000 |................|377# TEST17-NEXT: 0030: 03040500 00000000 04000000 00000000 |................|378# TEST17-NEXT: 0040: 03000000 474E5500 |....GNU.|379# TEST17-NEXT: )380# TEST17: NoteSections [381# TEST17-NEXT: NoteSection {382# TEST17-NEXT: Name: .note.foo4383# TEST17-NEXT: Offset:384# TEST17-NEXT: Size:385# TEST17-NEXT: Notes [386# TEST17-NEXT: {387# TEST17-NEXT: Owner: ABCD388# TEST17-NEXT: Data size: 0x2389# TEST17-NEXT: Type: NT_VERSION (version)390# TEST17-NEXT: Description data (391# TEST17-NEXT: 0000: 0102 |..|392# TEST17-NEXT: )393# TEST17-NEXT: }394# TEST17-NEXT: {395# TEST17-NEXT: Owner: 396# TEST17-NEXT: Data size: 0x3397# TEST17-NEXT: Type: NT_ARCH (architecture)398# TEST17-NEXT: Description data (399# TEST17-NEXT: 0000: 030405 |...|400# TEST17-NEXT: )401# TEST17-NEXT: }402# TEST17-NEXT: {403# TEST17-NEXT: Owner: GNU404# TEST17-NEXT: Data size: 0x0405# TEST17-NEXT: Type: NT_GNU_BUILD_ID (unique build ID bitstring)406# TEST17-NEXT: Build ID: 407# TEST17-NEXT: }408# TEST17-NEXT: ]409# TEST17-NEXT: }410# TEST17-NEXT: NoteSection {411# TEST17-NEXT: Name: .note.foo8412# TEST17-NEXT: Offset:413# TEST17-NEXT: Size:414# TEST17-NEXT: Notes [415# TEST17-NEXT: {416# TEST17-NEXT: Owner: ABCD417# TEST17-NEXT: Data size: 0x2418# TEST17-NEXT: Type: NT_VERSION (version)419# TEST17-NEXT: Description data (420# TEST17-NEXT: 0000: 0102 |..|421# TEST17-NEXT: )422# TEST17-NEXT: }423# TEST17-NEXT: {424# TEST17-NEXT: Owner: 425# TEST17-NEXT: Data size: 0x3426# TEST17-NEXT: Type: NT_ARCH (architecture)427# TEST17-NEXT: Description data (428# TEST17-NEXT: 0000: 030405 |...|429# TEST17-NEXT: )430# TEST17-NEXT: }431# TEST17-NEXT: {432# TEST17-NEXT: Owner: GNU433# TEST17-NEXT: Data size: 0x0434# TEST17-NEXT: Type: NT_GNU_BUILD_ID (unique build ID bitstring)435# TEST17-NEXT: Build ID: 436# TEST17-NEXT: }437# TEST17-NEXT: ]438# TEST17-NEXT: }439# TEST17-NEXT: ]440 441--- !ELF442FileHeader:443 Class: ELFCLASS[[ELFCLASS]]444 Data: ELFDATA2LSB445 Type: ET_EXEC446Sections:447 - Name: .note.foo4448 Type: SHT_NOTE449 AddressAlign: 4450 Notes:451 - Name: ABCD452 Type: NT_VERSION453 Desc: 0102454 - Type: NT_ARCH455 Desc: 030405456 - Name: GNU457 Type: NT_GNU_BUILD_ID458 - Name: .note.foo8459 Type: SHT_NOTE460 AddressAlign: 8461 Notes:462 - Name: ABCD463 Type: NT_VERSION464 Desc: 0102465 - Type: NT_ARCH466 Desc: 030405467 - Name: GNU468 Type: NT_GNU_BUILD_ID469 470## Check that the alignment for note entries is taken from the "AddressAlign"471## field even if "ShAddrAlign" is also specified; an unexpected value in the472## "ShAddrAlign" property does not trigger an incorrect alignment error.473 474# RUN: yaml2obj --docnum=18 -D ADDRALIGN=0 -D SHADDRALIGN=8 %s -o - | \475# RUN: llvm-readobj --sections --section-data --notes - | \476# RUN: FileCheck %s --check-prefixes=TEST18,TEST18_4477 478# RUN: yaml2obj --docnum=18 -D ADDRALIGN=4 -D SHADDRALIGN=3 %s -o - | \479# RUN: llvm-readobj --sections --section-data --notes - | \480# RUN: FileCheck %s --check-prefixes=TEST18,TEST18_4481 482# RUN: yaml2obj --docnum=18 -D ADDRALIGN=8 -D SHADDRALIGN=4 %s -o - | \483# RUN: llvm-readobj --sections --section-data --notes - | \484# RUN: FileCheck %s --check-prefixes=TEST18,TEST18_8485 486# TEST18: Name: .note487# TEST18: SectionData (488# TEST18_4-NEXT: 0000: 05000000 02000000 01000000 41424344 |............ABCD|489# TEST18_4-NEXT: 0010: 00000000 01020000 00000000 03000000 |................|490# TEST18_4-NEXT: 0020: 02000000 03040500 04000000 00000000 |................|491# TEST18_4-NEXT: 0030: 03000000 474E5500 |....GNU.|492# TEST18_8-NEXT: 0000: 05000000 02000000 01000000 41424344 |............ABCD|493# TEST18_8-NEXT: 0010: 00000000 00000000 01020000 00000000 |................|494# TEST18_8-NEXT: 0020: 00000000 03000000 02000000 00000000 |................|495# TEST18_8-NEXT: 0030: 03040500 00000000 04000000 00000000 |................|496# TEST18_8-NEXT: 0040: 03000000 474E5500 |....GNU.|497# TEST18-NEXT: )498 499--- !ELF500FileHeader:501 Class: ELFCLASS64502 Data: ELFDATA2LSB503 Type: ET_EXEC504Sections:505 - Name: .note506 Type: SHT_NOTE507 AddressAlign: [[ADDRALIGN]]508 ShAddrAlign: [[SHADDRALIGN]]509 Notes:510 - Name: ABCD511 Type: NT_VERSION512 Desc: 0102513 - Type: NT_ARCH514 Desc: 030405515 - Name: GNU516 Type: NT_GNU_BUILD_ID517 518## Check that an incorrect offset for generating notes is reported.519 520# RUN: not yaml2obj --docnum=19 %s 2>&1 | FileCheck %s --check-prefix=ERR_OFFSET521# ERR_OFFSET: error: .note: invalid offset of a note section: 0x501, should be aligned to 4522 523--- !ELF524FileHeader:525 Class: ELFCLASS32526 Data: ELFDATA2LSB527 Type: ET_EXEC528Sections:529 - Name: .note530 Type: SHT_NOTE531 Offset: 0x501532 Notes:533 - Type: 0x1534 535## Do not issue an error if the notes array is empty.536 537# RUN: yaml2obj --docnum=20 %s -o - | \538# RUN: llvm-readobj --sections --section-data - | \539# RUN: FileCheck %s --check-prefix=TEST20540 541# TEST20: Section {542# TEST20: Name: .note543# TEST20-NEXT: Type: SHT_NOTE544# TEST20-NEXT: Flags [ (0x0)545# TEST20-NEXT: ]546# TEST20-NEXT: Address:547# TEST20-NEXT: Offset: 0x501548# TEST20-NEXT: Size: 0549# TEST20-NEXT: Link:550# TEST20-NEXT: Info:551# TEST20-NEXT: AddressAlignment: 5552# TEST20-NEXT: EntrySize:553# TEST20-NEXT: SectionData (554# TEST20-NEXT: )555# TEST20-NEXT: }556 557--- !ELF558FileHeader:559 Class: ELFCLASS32560 Data: ELFDATA2LSB561 Type: ET_EXEC562Sections:563 - Name: .note564 Type: SHT_NOTE565 Offset: 0x501566 AddressAlign: 5567 Notes: []568