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    Sections:
110      - Section: .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 %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: 0xffff0000
131
132## Test tools report an error if a note section has invalid size
133## that goes past the end of file.
134
135# RUN: yaml2obj --docnum=3 %s -o %t3.so
136# RUN: not llvm-readelf --notes %t3.so 2>&1 | FileCheck -DFILE=%t3.so %s --check-prefix=ERR2
137# RUN: not llvm-readobj --notes %t3.so 2>&1 | FileCheck -DFILE=%t3.so %s --check-prefix=ERR2
138
139# ERR2: error: '[[FILE]]': SHT_NOTE section [index 1] has invalid offset (0x40) or size (0xffff0000)
140
141--- !ELF
142FileHeader:
143  Class: ELFCLASS64
144  Data:  ELFDATA2LSB
145  Type:  ET_EXEC
146Sections:
147  - Name:   .note
148    Type:   SHT_NOTE
149    ShSize: 0xffff0000
150    Notes:  []
151
152## Test tools report an error if a note program header has an invalid offset that
153## goes past the end of file.
154
155# RUN: yaml2obj --docnum=4 %s -o %t4.so
156# RUN: not llvm-readelf --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3
157# RUN: not llvm-readobj --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3
158
159# ERR3: error: '[[FILE]]': PT_NOTE header has invalid offset (0xffff0000) or size (0x0)
160
161--- !ELF
162FileHeader:
163  Class: ELFCLASS64
164  Data:  ELFDATA2LSB
165  Type:  ET_CORE
166ProgramHeaders:
167  - Type:   PT_NOTE
168    Offset: 0xffff0000
169
170## Test tools report an error if a note program header has an invalid size that
171## goes past the end of file.
172
173# RUN: yaml2obj --docnum=5 %s -o %t5.so
174# RUN: not llvm-readelf --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so  %s --check-prefix=ERR4
175# RUN: not llvm-readobj --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so %s --check-prefix=ERR4
176
177# ERR4: error: '[[FILE]]': PT_NOTE header has invalid offset (0x78) or size (0xffff0000)
178
179--- !ELF
180FileHeader:
181  Class: ELFCLASS64
182  Data:  ELFDATA2LSB
183  Type:  ET_CORE
184Sections:
185  - Name:  .note
186    Type:  SHT_NOTE
187    Notes: []
188ProgramHeaders:
189  - Type: PT_NOTE
190    FileSize: 0xffff0000
191    Sections:
192      - Section: .note
193
194## Check we report a warning when we are unable to locate the PT_NOTE
195## segment because of broken program headers.
196# RUN: yaml2obj --docnum=1 -DPHENTSIZE=1 -DSHNUM=0 %s -o %t6.so
197# RUN: llvm-readelf --notes %t6.so 2>&1 | FileCheck %s -DFILE=%t6.so --check-prefix=PHENTSIZE-WARN-GNU
198# RUN: llvm-readobj --notes %t6.so 2>&1 | FileCheck %s -DFILE=%t6.so --check-prefix=PHENTSIZE-WARN-LLVM
199
200# PHENTSIZE-WARN-GNU: warning: '[[FILE]]': unable to read program headers to locate the PT_DYNAMIC segment: invalid e_phentsize: 1
201# PHENTSIZE-WARN-GNU: warning: '[[FILE]]': unable to read program headers to locate the PT_NOTE segment: invalid e_phentsize: 1
202
203# PHENTSIZE-WARN-LLVM:      Notes [
204# PHENTSIZE-WARN-LLVM-NEXT: warning: '[[FILE]]': unable to read program headers to locate the PT_NOTE segment: invalid e_phentsize: 1
205# PHENTSIZE-WARN-LLVM-NEXT: ]
206