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  Machine:    EM_X86_64
90  EPhEntSize: [[PHENTSIZE=56]]
91  EShNum:     [[SHNUM=6]]
92Sections:
93  - Name:         .note.ABI-tag
94    Type:         SHT_NOTE
95    AddressAlign: 0x0000000000000004
96    Content:      040000001000000001000000474E550000000000020000000600000020000000
97  - Name:         .note.gnu.build-id
98    Type:         SHT_NOTE
99    Flags:        [ SHF_ALLOC ]
100    Address:      0x0000000000400120
101    AddressAlign: 0x0000000000000004
102    Content:      040000001000000003000000474E55004FCB712AA6387724A9F465A32CD8C14B
103  - Name:         .note.gnu.gold-version
104    Type:         SHT_NOTE
105    AddressAlign: 0x0000000000000004
106    Content:      040000000900000004000000474E5500676F6C6420312E3131000000
107ProgramHeaders:
108  - Type: PT_NOTE
109    FileSize: 0x20
110    Sections:
111      - Section: .note.gnu.build-id
112
113## Test tools report an error if a note section has an invalid offset
114## that goes past the end of file.
115
116# RUN: yaml2obj --docnum=2 %s -o %t2.so
117# RUN: not llvm-readelf --notes %t2.so 2>&1 | FileCheck -DFILE=%t2.so %s --check-prefix=ERR1
118# RUN: not llvm-readobj --notes %t2.so 2>&1 | FileCheck -DFILE=%t2.so %s --check-prefix=ERR1
119
120# ERR1: error: '[[FILE]]': SHT_NOTE section [index 1] has invalid offset (0xffff0000) or size (0x0)
121
122--- !ELF
123FileHeader:
124  Class:   ELFCLASS64
125  Data:    ELFDATA2LSB
126  Type:    ET_EXEC
127  Machine: EM_X86_64
128Sections:
129  - Name:     .note
130    Type:     SHT_NOTE
131    Notes:    []
132    ShOffset: 0xffff0000
133
134## Test tools report an error if a note section has invalid size
135## that goes past the end of file.
136
137# RUN: yaml2obj --docnum=3 %s -o %t3.so
138# RUN: not llvm-readelf --notes %t3.so 2>&1 | FileCheck -DFILE=%t3.so %s --check-prefix=ERR2
139# RUN: not llvm-readobj --notes %t3.so 2>&1 | FileCheck -DFILE=%t3.so %s --check-prefix=ERR2
140
141# ERR2: error: '[[FILE]]': SHT_NOTE section [index 1] has invalid offset (0x40) or size (0xffff0000)
142
143--- !ELF
144FileHeader:
145  Class:   ELFCLASS64
146  Data:    ELFDATA2LSB
147  Type:    ET_EXEC
148  Machine: EM_X86_64
149Sections:
150  - Name:   .note
151    Type:   SHT_NOTE
152    ShSize: 0xffff0000
153    Notes:  []
154
155## Test tools report an error if a note program header has an invalid offset that
156## goes past the end of file.
157
158# RUN: yaml2obj --docnum=4 %s -o %t4.so
159# RUN: not llvm-readelf --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3
160# RUN: not llvm-readobj --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3
161
162# ERR3: error: '[[FILE]]': PT_NOTE header has invalid offset (0xffff0000) or size (0x0)
163
164--- !ELF
165FileHeader:
166  Class:   ELFCLASS64
167  Data:    ELFDATA2LSB
168  Type:    ET_CORE
169  Machine: EM_X86_64
170ProgramHeaders:
171  - Type:   PT_NOTE
172    Offset: 0xffff0000
173
174## Test tools report an error if a note program header has an invalid size that
175## goes past the end of file.
176
177# RUN: yaml2obj --docnum=5 %s -o %t5.so
178# RUN: not llvm-readelf --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so  %s --check-prefix=ERR4
179# RUN: not llvm-readobj --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so %s --check-prefix=ERR4
180
181# ERR4: error: '[[FILE]]': PT_NOTE header has invalid offset (0x78) or size (0xffff0000)
182
183--- !ELF
184FileHeader:
185  Class:   ELFCLASS64
186  Data:    ELFDATA2LSB
187  Type:    ET_CORE
188  Machine: EM_X86_64
189Sections:
190  - Name:  .note
191    Type:  SHT_NOTE
192    Notes: []
193ProgramHeaders:
194  - Type: PT_NOTE
195    FileSize: 0xffff0000
196    Sections:
197      - Section: .note
198
199## Check we report a warning when we are unable to locate the PT_NOTE
200## segment because of broken program headers.
201# RUN: yaml2obj --docnum=1 -DPHENTSIZE=1 -DSHNUM=0 %s -o %t6.so
202# RUN: llvm-readelf --notes %t6.so 2>&1 | FileCheck %s -DFILE=%t6.so --check-prefix=PHENTSIZE-WARN-GNU
203# RUN: llvm-readobj --notes %t6.so 2>&1 | FileCheck %s -DFILE=%t6.so --check-prefix=PHENTSIZE-WARN-LLVM
204
205# PHENTSIZE-WARN-GNU: warning: '[[FILE]]': unable to read program headers to locate the PT_DYNAMIC segment: invalid e_phentsize: 1
206# PHENTSIZE-WARN-GNU: warning: '[[FILE]]': unable to read program headers to locate the PT_NOTE segment: invalid e_phentsize: 1
207
208# PHENTSIZE-WARN-LLVM:      Notes [
209# PHENTSIZE-WARN-LLVM-NEXT: warning: '[[FILE]]': unable to read program headers to locate the PT_NOTE segment: invalid e_phentsize: 1
210# PHENTSIZE-WARN-LLVM-NEXT: ]
211