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: not llvm-readelf --notes %t2.so 2>&1 | FileCheck -DFILE=%t2.so %s --check-prefix=ERR1 117# RUN: not llvm-readobj --notes %t2.so 2>&1 | FileCheck -DFILE=%t2.so %s --check-prefix=ERR1 118 119# ERR1: error: '[[FILE]]': SHT_NOTE section [index 1] has invalid offset (0xffff0000) or size (0x0) 120 121--- !ELF 122FileHeader: 123 Class: ELFCLASS64 124 Data: ELFDATA2LSB 125 Type: ET_EXEC 126Sections: 127 - Name: .note 128 Type: SHT_NOTE 129 Notes: [] 130 ShOffset: [[SHOFFSET=<none>]] 131 ShSize: [[SHSIZE=<none>]] 132 133## Test tools report an error if a note section has invalid size 134## that goes past the end of file. 135 136# RUN: yaml2obj --docnum=2 -DSHSIZE=0xffff0000 %s -o %t3.so 137# RUN: not llvm-readelf --notes %t3.so 2>&1 | FileCheck -DFILE=%t3.so %s --check-prefix=ERR2 138# RUN: not llvm-readobj --notes %t3.so 2>&1 | FileCheck -DFILE=%t3.so %s --check-prefix=ERR2 139 140# ERR2: error: '[[FILE]]': SHT_NOTE section [index 1] has invalid offset (0x40) or size (0xffff0000) 141 142## Test tools report an error if a note program header has an invalid offset that 143## goes past the end of file. 144 145# RUN: yaml2obj --docnum=3 -DPHOFFSET=0xffff0000 %s -o %t4.so 146# RUN: not llvm-readelf --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3 147# RUN: not llvm-readobj --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3 148 149# ERR3: error: '[[FILE]]': PT_NOTE header has invalid offset (0xffff0000) or size (0x0) 150 151--- !ELF 152FileHeader: 153 Class: ELFCLASS64 154 Data: ELFDATA2LSB 155 Type: ET_CORE 156ProgramHeaders: 157 - Type: PT_NOTE 158 Offset: [[PHOFFSET=<none>]] 159 FileSize: [[PHFILESIZE=<none>]] 160 161## Test tools report an error if a note program header has an invalid size that 162## goes past the end of file. 163 164# RUN: yaml2obj --docnum=3 -DPHFILESIZE=0xffff0000 %s -o %t5.so 165# RUN: not llvm-readelf --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so %s --check-prefix=ERR4 166# RUN: not llvm-readobj --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so %s --check-prefix=ERR4 167 168# ERR4: error: '[[FILE]]': PT_NOTE header has invalid offset (0x0) or size (0xffff0000) 169 170## Check we report a warning when we are unable to locate the PT_NOTE 171## segment because of broken program headers. 172# RUN: yaml2obj --docnum=1 -DPHENTSIZE=1 -DSHNUM=0 %s -o %t6.so 173# RUN: llvm-readelf --notes %t6.so 2>&1 | FileCheck %s -DFILE=%t6.so --check-prefix=PHENTSIZE-WARN-GNU 174# RUN: llvm-readobj --notes %t6.so 2>&1 | FileCheck %s -DFILE=%t6.so --check-prefix=PHENTSIZE-WARN-LLVM 175 176# PHENTSIZE-WARN-GNU: warning: '[[FILE]]': unable to read program headers to locate the PT_DYNAMIC segment: invalid e_phentsize: 1 177# PHENTSIZE-WARN-GNU: warning: '[[FILE]]': unable to read program headers to locate the PT_NOTE segment: invalid e_phentsize: 1 178 179# PHENTSIZE-WARN-LLVM: Notes [ 180# PHENTSIZE-WARN-LLVM-NEXT: warning: '[[FILE]]': unable to read program headers to locate the PT_NOTE segment: invalid e_phentsize: 1 181# PHENTSIZE-WARN-LLVM-NEXT: ] 182