1## Test tools are able to dump different types of notes. 2 3# RUN: yaml2obj --docnum=1 %s -o %t1.so 4# RUN: llvm-readelf --notes %t1.so | FileCheck %s --check-prefix=GNU --strict-whitespace --match-full-lines 5# RUN: llvm-readobj --notes %t1.so | FileCheck %s --check-prefix=LLVM 6# RUN: llvm-objcopy --strip-sections %t1.so %t1.stripped.so 7# RUN: llvm-readelf --notes %t1.stripped.so | FileCheck %s --check-prefix=GNU-STRIPPED --strict-whitespace --match-full-lines 8# RUN: llvm-readobj --notes %t1.stripped.so | FileCheck %s --check-prefix=LLVM-STRIPPED 9 10# GNU:Displaying notes found in: .note.ABI-tag 11# GNU-NEXT: Owner Data size Description 12# GNU-NEXT: GNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag) 13# GNU-NEXT: OS: Linux, ABI: 2.6.32 14 15# GNU:Displaying notes found in: .note.gnu.build-id 16# GNU-NEXT: Owner Data size Description 17# GNU-NEXT: GNU 0x00000010 NT_GNU_BUILD_ID (unique build ID bitstring) 18# GNU-NEXT: Build ID: 4fcb712aa6387724a9f465a32cd8c14b 19 20# GNU:Displaying notes found in: .note.gnu.gold-version 21# GNU-NEXT: Owner Data size Description 22# GNU-NEXT: GNU 0x00000009 NT_GNU_GOLD_VERSION (gold version) 23# GNU-NEXT: Version: gold 1.11 24 25# LLVM: Notes [ 26# LLVM-NEXT: NoteSection { 27# LLVM-NEXT: Name: .note.ABI-tag 28# LLVM-NEXT: Offset: 0x78 29# LLVM-NEXT: Size: 0x20 30# LLVM-NEXT: Note { 31# LLVM-NEXT: Owner: GNU 32# LLVM-NEXT: Data size: 0x10 33# LLVM-NEXT: Type: NT_GNU_ABI_TAG (ABI version tag) 34# LLVM-NEXT: OS: Linux 35# LLVM-NEXT: ABI: 2.6.32 36# LLVM-NEXT: } 37# LLVM-NEXT: } 38# LLVM-NEXT: NoteSection { 39# LLVM-NEXT: Name: .note.gnu.build-id 40# LLVM-NEXT: Offset: 0x98 41# LLVM-NEXT: Size: 0x20 42# LLVM-NEXT: Note { 43# LLVM-NEXT: Owner: GNU 44# LLVM-NEXT: Data size: 0x10 45# LLVM-NEXT: Type: NT_GNU_BUILD_ID (unique build ID bitstring) 46# LLVM-NEXT: Build ID: 4fcb712aa6387724a9f465a32cd8c14b 47# LLVM-NEXT: } 48# LLVM-NEXT: } 49# LLVM-NEXT: NoteSection { 50# LLVM-NEXT: Name: .note.gnu.gold-version 51# LLVM-NEXT: Offset: 0xB8 52# LLVM-NEXT: Size: 0x1C 53# LLVM-NEXT: Note { 54# LLVM-NEXT: Owner: GNU 55# LLVM-NEXT: Data size: 0x9 56# LLVM-NEXT: Type: NT_GNU_GOLD_VERSION (gold version) 57# LLVM-NEXT: Version: gold 1.11 58# LLVM-NEXT: } 59# LLVM-NEXT: } 60# LLVM-NEXT: ] 61 62## Note: the section name is <?> here because the section header table is not present. 63# LLVM-STRIPPED: Notes [ 64# LLVM-STRIPPED-NEXT: NoteSection { 65# LLVM-STRIPPED-NEXT: Name: <?> 66# LLVM-STRIPPED-NEXT: Offset: 0x78 67# LLVM-STRIPPED-NEXT: Size: 0x20 68# LLVM-STRIPPED-NEXT: Note { 69# LLVM-STRIPPED-NEXT: Owner: GNU 70# LLVM-STRIPPED-NEXT: Data size: 0x10 71# LLVM-STRIPPED-NEXT: Type: NT_GNU_BUILD_ID (unique build ID bitstring) 72# LLVM-STRIPPED-NEXT: Build ID: 4fcb712aa6387724a9f465a32cd8c14b 73# LLVM-STRIPPED-NEXT: } 74# LLVM-STRIPPED-NEXT: } 75# LLVM-STRIPPED-NEXT: ] 76 77## Note: offset and length printed instead of "found in: .note.gnu.build-id" 78## because the section header table is not present. 79# GNU-STRIPPED:Displaying notes found at file offset 0x00000078 with length 0x00000020: 80# GNU-STRIPPED-NEXT: Owner Data size Description 81# GNU-STRIPPED-NEXT: GNU 0x00000010 NT_GNU_BUILD_ID (unique build ID bitstring) 82# GNU-STRIPPED-NEXT: Build ID: 4fcb712aa6387724a9f465a32cd8c14b 83 84--- !ELF 85FileHeader: 86 Class: ELFCLASS64 87 Data: ELFDATA2LSB 88 Type: ET_EXEC 89 EPhEntSize: [[PHENTSIZE=<none>]] 90 EShNum: [[SHNUM=<none>]] 91Sections: 92 - Name: .note.ABI-tag 93 Type: SHT_NOTE 94 AddressAlign: 0x0000000000000004 95 Content: 040000001000000001000000474E550000000000020000000600000020000000 96 - Name: .note.gnu.build-id 97 Type: SHT_NOTE 98 Flags: [ SHF_ALLOC ] 99 Address: 0x0000000000400120 100 AddressAlign: 0x0000000000000004 101 Content: 040000001000000003000000474E55004FCB712AA6387724A9F465A32CD8C14B 102 - Name: .note.gnu.gold-version 103 Type: SHT_NOTE 104 AddressAlign: 0x0000000000000004 105 Content: 040000000900000004000000474E5500676F6C6420312E3131000000 106ProgramHeaders: 107 - Type: PT_NOTE 108 FileSize: 0x20 109 FirstSec: .note.gnu.build-id 110 LastSec: .note.gnu.build-id 111 112## Test tools report an error if a note section has an invalid offset 113## that goes past the end of file. 114 115# RUN: yaml2obj --docnum=2 -DSHOFFSET=0xffff0000 %s -o %t2.so 116# RUN: llvm-readelf --notes %t2.so 2>&1 | FileCheck -DFILE=%t2.so %s --check-prefix=ERR1-GNU 117# RUN: llvm-readobj --notes %t2.so 2>&1 | FileCheck -DFILE=%t2.so %s --check-prefix=ERR1-LLVM 118 119# ERR1-GNU: Displaying notes found in: .note 120# ERR1-GNU-NEXT: Owner Data size Description 121# ERR1-GNU-NEXT: warning: '[[FILE]]': unable to read notes from the SHT_NOTE section with index 1: invalid offset (0xffff0000) or size (0x0) 122# ERR1-GNU-NOT: {{.}} 123 124# ERR1-LLVM: Notes [ 125# ERR1-LLVM-NEXT: NoteSection { 126# ERR1-LLVM-NEXT: Name: .note 127# ERR1-LLVM-NEXT: Offset: 0xFFFF0000 128# ERR1-LLVM-NEXT: Size: 0x0 129# ERR1-LLVM-NEXT: warning: '[[FILE]]': unable to read notes from the SHT_NOTE section with index 1: invalid offset (0xffff0000) or size (0x0) 130# ERR1-LLVM-NEXT: } 131# ERR1-LLVM-NEXT: ] 132 133--- !ELF 134FileHeader: 135 Class: ELFCLASS64 136 Data: ELFDATA2LSB 137 Type: ET_EXEC 138Sections: 139 - Name: .note 140 Type: SHT_NOTE 141 Notes: [] 142 ShOffset: [[SHOFFSET=<none>]] 143 ShSize: [[SHSIZE=<none>]] 144 145## Test tools report an error if a note section has invalid size 146## that goes past the end of file. 147 148# RUN: yaml2obj --docnum=2 -DSHSIZE=0xffff0000 %s -o %t3.so 149# RUN: llvm-readelf --notes %t3.so 2>&1 | FileCheck -DFILE=%t3.so %s --check-prefix=ERR2-GNU 150# RUN: llvm-readobj --notes %t3.so 2>&1 | FileCheck -DFILE=%t3.so %s --check-prefix=ERR2-LLVM 151 152# ERR2-GNU: Displaying notes found in: .note 153# ERR2-GNU-NEXT: Owner Data size Description 154# ERR2-GNU-NEXT: warning: '[[FILE]]': unable to read notes from the SHT_NOTE section with index 1: invalid offset (0x40) or size (0xffff0000) 155# ERR2-GNU-NOT: {{.}} 156 157# ERR2-LLVM: Notes [ 158# ERR2-LLVM-NEXT: NoteSection { 159# ERR2-LLVM-NEXT: Name: .note 160# ERR2-LLVM-NEXT: Offset: 0x40 161# ERR2-LLVM-NEXT: Size: 0xFFFF0000 162# ERR2-LLVM-NEXT: warning: '[[FILE]]': unable to read notes from the SHT_NOTE section with index 1: invalid offset (0x40) or size (0xffff0000) 163# ERR2-LLVM-NEXT: } 164# ERR2-LLVM-NEXT: ] 165 166## Test tools report an error if a note program header has an invalid offset that 167## goes past the end of file. 168 169# RUN: yaml2obj --docnum=3 -DPHOFFSET=0xffff0000 %s -o %t4.so 170# RUN: llvm-readelf --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3-GNU 171# RUN: llvm-readobj --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3-LLVM 172 173# ERR3-GNU: Displaying notes found at file offset 0xffff0000 with length 0x00000000: 174# ERR3-GNU-NEXT: Owner Data size Description 175# ERR3-GNU-NEXT: warning: '[[FILE]]': unable to read notes from the PT_NOTE segment with index 0: invalid offset (0xffff0000) or size (0x0) 176# ERR3-GNU-NOT: {{.}} 177 178# ERR3-LLVM: Notes [ 179# ERR3-LLVM-NEXT: NoteSection { 180# ERR3-LLVM-NEXT: Name: <?> 181# ERR3-LLVM-NEXT: Offset: 0xFFFF0000 182# ERR3-LLVM-NEXT: Size: 0x0 183# ERR3-LLVM-NEXT: warning: '[[FILE]]': unable to read notes from the PT_NOTE segment with index 0: invalid offset (0xffff0000) or size (0x0) 184# ERR3-LLVM-NEXT: } 185# ERR3-LLVM-NEXT: ] 186 187--- !ELF 188FileHeader: 189 Class: ELFCLASS64 190 Data: ELFDATA2LSB 191 Type: ET_CORE 192ProgramHeaders: 193 - Type: PT_NOTE 194 Offset: [[PHOFFSET=<none>]] 195 FileSize: [[PHFILESIZE=<none>]] 196 197## Test tools report an error if a note program header has an invalid size that 198## goes past the end of file. 199 200# RUN: yaml2obj --docnum=3 -DPHFILESIZE=0xffff0000 %s -o %t5.so 201# RUN: llvm-readelf --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so %s --check-prefix=ERR4-GNU 202# RUN: llvm-readobj --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so %s --check-prefix=ERR4-LLVM 203 204# ERR4-GNU: Displaying notes found at file offset 0x00000000 with length 0xffff0000: 205# ERR4-GNU-NEXT: Owner Data size Description 206# ERR4-GNU-NEXT: warning: '[[FILE]]': unable to read notes from the PT_NOTE segment with index 0: invalid offset (0x0) or size (0xffff0000) 207# ERR4-GNU-NOT: {{.}} 208 209# ERR4-LLVM: Notes [ 210# ERR4-LLVM-NEXT: NoteSection { 211# ERR4-LLVM-NEXT: Name: <?> 212# ERR4-LLVM-NEXT: Offset: 0x0 213# ERR4-LLVM-NEXT: Size: 0xFFFF0000 214# ERR4-LLVM-NEXT: warning: '[[FILE]]': unable to read notes from the PT_NOTE segment with index 0: invalid offset (0x0) or size (0xffff0000) 215# ERR4-LLVM-NEXT: } 216# ERR4-LLVM-NEXT: ] 217 218## Check we report a warning when we are unable to locate the PT_NOTE 219## segment because of broken program headers. 220# RUN: yaml2obj --docnum=1 -DPHENTSIZE=1 -DSHNUM=0 %s -o %t6.so 221# RUN: llvm-readelf --notes %t6.so 2>&1 | FileCheck %s -DFILE=%t6.so --check-prefix=PHENTSIZE-WARN-GNU 222# RUN: llvm-readobj --notes %t6.so 2>&1 | FileCheck %s -DFILE=%t6.so --check-prefix=PHENTSIZE-WARN-LLVM 223 224# PHENTSIZE-WARN-GNU: warning: '[[FILE]]': unable to read program headers to locate the PT_DYNAMIC segment: invalid e_phentsize: 1 225# PHENTSIZE-WARN-GNU: warning: '[[FILE]]': unable to read program headers to locate the PT_NOTE segment: invalid e_phentsize: 1 226 227# PHENTSIZE-WARN-LLVM: Notes [ 228# PHENTSIZE-WARN-LLVM-NEXT: warning: '[[FILE]]': unable to read program headers to locate the PT_NOTE segment: invalid e_phentsize: 1 229# PHENTSIZE-WARN-LLVM-NEXT: ] 230