1 ## Test tools are able to dump different types of notes.
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
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
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
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
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
31 # LLVM: NoteSections [
32 # LLVM-NEXT: NoteSection {
33 # LLVM-NEXT: Name: .note.ABI-tag
34 # LLVM-NEXT: Offset: 0x78
35 # LLVM-NEXT: Size: 0x20
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
46 # LLVM-NEXT: NoteSection {
47 # LLVM-NEXT: Name: .note.gnu.build-id
48 # LLVM-NEXT: Offset: 0x98
49 # LLVM-NEXT: Size: 0x20
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
59 # LLVM-NEXT: NoteSection {
60 # LLVM-NEXT: Name: .note.gnu.gold-version
61 # LLVM-NEXT: Offset: 0xB8
62 # LLVM-NEXT: Size: 0x1C
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
72 # LLVM-NEXT: NoteSection {
73 # LLVM-NEXT: Name: .note.gnu.unknown
74 # LLVM-NEXT: Offset: 0xD4
75 # LLVM-NEXT: Size: 0x14
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|
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: ]
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
118 EPhEntSize: [[PHENTSIZE=<none>]]
119 EShNum: [[SHNUM=<none>]]
121 - Name: .note.ABI-tag
123 AddressAlign: 0x0000000000000004
124 Content: 040000001000000001000000474E550000000000020000000600000020000000
125 - Name: .note.gnu.build-id
128 Address: 0x0000000000400120
129 AddressAlign: 0x0000000000000004
130 Content: 040000001000000003000000474E55004FCB712AA6387724A9F465A32CD8C14B
131 - Name: .note.gnu.gold-version
133 AddressAlign: 0x0000000000000004
134 Content: 040000000900000004000000474E5500676F6C6420312E3131000000
135 - Name: .note.gnu.unknown
137 AddressAlign: 0x0000000000000004
138 Content: 0400000004000000cdab0000474E550061626364
142 FirstSec: .note.gnu.build-id
143 LastSec: .note.gnu.build-id
145 ## Test tools report an error if a note section has an invalid offset
146 ## that goes past the end of file.
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
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)
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)
177 ShOffset: [[SHOFFSET=<none>]]
178 ShSize: [[SHSIZE=<none>]]
180 ## Test tools report an error if a note section has invalid size
181 ## that goes past the end of file.
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
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)
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)
203 ## Test tools report an error if a note program header has an invalid offset that
204 ## goes past the end of file.
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
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: {{.}}
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)
233 Offset: [[PHOFFSET=<none>]]
234 FileSize: [[PHFILESIZE=<none>]]
236 ## Test tools report an error if a note program header has an invalid size that
237 ## goes past the end of file.
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
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)
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)
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
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
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: ]