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
90Sections:
91  - Name:         .note.ABI-tag
92    Type:         SHT_NOTE
93    AddressAlign: 0x0000000000000004
94    Content:      040000001000000001000000474E550000000000020000000600000020000000
95  - Name:         .note.gnu.build-id
96    Type:         SHT_NOTE
97    Flags:        [ SHF_ALLOC ]
98    Address:      0x0000000000400120
99    AddressAlign: 0x0000000000000004
100    Content:      040000001000000003000000474E55004FCB712AA6387724A9F465A32CD8C14B
101  - Name:         .note.gnu.gold-version
102    Type:         SHT_NOTE
103    AddressAlign: 0x0000000000000004
104    Content:      040000000900000004000000474E5500676F6C6420312E3131000000
105ProgramHeaders:
106  - Type: PT_NOTE
107    FileSize: 0x20
108    Sections:
109      - Section: .note.gnu.build-id
110
111## Test tools report an error if a note section has an invalid offset
112## that goes past the end of file.
113
114# RUN: yaml2obj --docnum=2 %s -o %t2.so
115# RUN: not llvm-readelf --notes %t2.so 2>&1 | FileCheck -DFILE=%t2.so %s --check-prefix=ERR1
116# RUN: not llvm-readobj --notes %t2.so 2>&1 | FileCheck -DFILE=%t2.so %s --check-prefix=ERR1
117
118# ERR1: error: '[[FILE]]': SHT_NOTE section [index 1] has invalid offset (0xffff0000) or size (0x0)
119
120--- !ELF
121FileHeader:
122  Class:   ELFCLASS64
123  Data:    ELFDATA2LSB
124  Type:    ET_EXEC
125  Machine: EM_X86_64
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
146  Machine: EM_X86_64
147Sections:
148  - Name:   .note
149    Type:   SHT_NOTE
150    ShSize: 0xffff0000
151    Notes:  []
152
153## Test tools report an error if a note program header has an invalid offset that
154## goes past the end of file.
155
156# RUN: yaml2obj --docnum=4 %s -o %t4.so
157# RUN: not llvm-readelf --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3
158# RUN: not llvm-readobj --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3
159
160# ERR3: error: '[[FILE]]': PT_NOTE header has invalid offset (0xffff0000) or size (0x0)
161
162--- !ELF
163FileHeader:
164  Class:   ELFCLASS64
165  Data:    ELFDATA2LSB
166  Type:    ET_CORE
167  Machine: EM_X86_64
168ProgramHeaders:
169  - Type:   PT_NOTE
170    Offset: 0xffff0000
171
172## Test tools report an error if a note program header has an invalid size that
173## goes past the end of file.
174
175# RUN: yaml2obj --docnum=5 %s -o %t5.so
176# RUN: not llvm-readelf --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so  %s --check-prefix=ERR4
177# RUN: not llvm-readobj --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so %s --check-prefix=ERR4
178
179# ERR4: error: '[[FILE]]': PT_NOTE header has invalid offset (0x78) or size (0xffff0000)
180
181--- !ELF
182FileHeader:
183  Class:   ELFCLASS64
184  Data:    ELFDATA2LSB
185  Type:    ET_CORE
186  Machine: EM_X86_64
187Sections:
188  - Name:  .note
189    Type:  SHT_NOTE
190    Notes: []
191ProgramHeaders:
192  - Type: PT_NOTE
193    FileSize: 0xffff0000
194    Sections:
195      - Section: .note
196