|
| 1 | +## Check how obj2yaml dumps SHT_NOTE sections. |
| 2 | + |
| 3 | +## We can dump the Name, Desc and Type fields when the note section is valid. |
| 4 | + |
| 5 | +# RUN: yaml2obj --docnum=1 %s -o %t1 |
| 6 | +# RUN: obj2yaml %t1 | FileCheck %s --check-prefix=VALID |
| 7 | + |
| 8 | +# VALID: - Name: .note.foo |
| 9 | +# VALID-NEXT: Type: SHT_NOTE |
| 10 | +# VALID-NEXT: Notes: |
| 11 | +# VALID-NEXT: - Name: '' |
| 12 | +# VALID-NEXT: Desc: '' |
| 13 | +# VALID-NEXT: Type: 0x00 |
| 14 | +# VALID-NEXT: - Name: .note.bar |
| 15 | +# VALID-NEXT: Type: SHT_NOTE |
| 16 | +# VALID-NEXT: Notes: |
| 17 | +# VALID-NEXT: - Name: ABC |
| 18 | +# VALID-NEXT: Desc: '001122' |
| 19 | +# VALID-NEXT: Type: 0xAABBCCDD |
| 20 | + |
| 21 | +--- !ELF |
| 22 | +FileHeader: |
| 23 | + Class: ELFCLASS64 |
| 24 | + Data: ELFDATA2LSB |
| 25 | + Type: ET_DYN |
| 26 | + Machine: EM_X86_64 |
| 27 | +Sections: |
| 28 | + - Name: .note.foo |
| 29 | + Type: SHT_NOTE |
| 30 | + Size: 12 |
| 31 | + - Name: .note.bar |
| 32 | + Type: SHT_NOTE |
| 33 | + Notes: |
| 34 | + - Name: ABC |
| 35 | + Desc: '001122' |
| 36 | + Type: 0xAABBCCDD |
| 37 | + |
| 38 | +## Check we dump hex digit pairs if the note section is invalid. |
| 39 | + |
| 40 | +# RUN: yaml2obj --docnum=2 %s -o %t2 |
| 41 | +# RUN: obj2yaml %t2 | FileCheck %s --check-prefix=INVALID |
| 42 | + |
| 43 | +# INVALID: - Name: .note.tooShortNote |
| 44 | +# INVALID-NEXT: Type: SHT_NOTE |
| 45 | +# INVALID-NEXT: Content: '0000000000000000000000' |
| 46 | +# INVALID-NEXT: - Name: .note.tooLongNameSize |
| 47 | +# INVALID-NEXT: Type: SHT_NOTE |
| 48 | +# INVALID-NEXT: Content: 0100000000000000FF00000000 |
| 49 | +# INVALID-NEXT: - Name: .note.tooLongDescSize |
| 50 | +# INVALID-NEXT: Type: SHT_NOTE |
| 51 | +# INVALID-NEXT: Content: 0000000001000000FF00000000 |
| 52 | + |
| 53 | +--- !ELF |
| 54 | +FileHeader: |
| 55 | + Class: ELFCLASS64 |
| 56 | + Data: ELFDATA2LSB |
| 57 | + Type: ET_DYN |
| 58 | + Machine: EM_X86_64 |
| 59 | +Sections: |
| 60 | +## Content is less than 12 bytes in size. |
| 61 | +## (12 is the size of n_namesz, n_descsz and n_type 4-bytes fields that must always present). |
| 62 | + - Name: .note.tooShortNote |
| 63 | + Type: SHT_NOTE |
| 64 | + Size: 11 |
| 65 | +## We can't dump the Name, Desc and Type fields when the |
| 66 | +## content is shorter than the computed size. |
| 67 | +## |
| 68 | +## Too long name size. |
| 69 | + - Name: .note.tooLongNameSize |
| 70 | + Type: SHT_NOTE |
| 71 | + Content: "0100000000000000ff00000000" |
| 72 | +## Too long description size. |
| 73 | + - Name: .note.tooLongDescSize |
| 74 | + Type: SHT_NOTE |
| 75 | + Content: "0000000001000000ff00000000" |
| 76 | + |
| 77 | +## Check we do not crash when dumping a description that has bytes |
| 78 | +## on its bounds that do not fit into signed byte. |
| 79 | +## This is a completely normal case, but we had a crash before. |
| 80 | + |
| 81 | +# RUN: yaml2obj --docnum=3 %s -o %t3 |
| 82 | +# RUN: obj2yaml %t3 | FileCheck %s --check-prefix=HEX-DESC |
| 83 | + |
| 84 | +# HEX-DESC: Desc: FE0000FE |
| 85 | + |
| 86 | +--- !ELF |
| 87 | +FileHeader: |
| 88 | + Class: ELFCLASS64 |
| 89 | + Data: ELFDATA2MSB |
| 90 | + Type: ET_DYN |
| 91 | + Machine: EM_MIPS |
| 92 | +Sections: |
| 93 | + - Name: .note.tag |
| 94 | + Type: SHT_NOTE |
| 95 | + Flags: [ SHF_ALLOC ] |
| 96 | + Notes: |
| 97 | + - Desc: 'FE0000FE' |
| 98 | + Type: 0 |
0 commit comments