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