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