1 ## Check how llvm-readelf prints section details with --section-details.
3 ## Check the output for the 64-bit case.
4 # RUN: yaml2obj %s -DBITS=64 -DCHDR=0000000008000000000000000400000000000000 -o %t64.o
5 # RUN: llvm-readelf %t64.o --section-details 2>&1 | \
6 # RUN: FileCheck %s -DFILE=%t64.o --strict-whitespace --match-full-lines --check-prefix=GNU64
8 # GNU64:There are 22 section headers, starting at offset 0x198:
10 # GNU64-NEXT:Section Headers:
11 # GNU64-NEXT: [Nr] Name
12 # GNU64-NEXT: Type Address Off Size ES Lk Inf Al
14 # GNU64-NEXT: [ 0] {{$}}
15 # GNU64-NEXT: NULL 0000000000000000 000000 000000 00 0 0 0
16 # GNU64-NEXT: [0000000000000000]: {{$}}
17 # GNU64-NEXT: [ 1] allflags_and_long_fields
18 # GNU64-NEXT: PROGBITS 1111111111111111 2222222222222222 4444444444444444 5555555555555555 858993459 1717986918 8608480567731124087
19 # GNU64-NEXT: [ffffffffffffffff]: WRITE, ALLOC, EXEC, MERGE, STRINGS, INFO LINK, LINK ORDER, OS NONCONF, GROUP, TLS, COMPRESSED, EXCLUDE, OS (000000000ff00000), PROC (0000000070000000), UNKNOWN (ffffffff000ff008)
20 # GNU64-NEXT:{{.*}}: warning: '[[FILE]]': SHF_COMPRESSED section 'allflags_and_long_fields' does not have an Elf_Chdr header
21 # GNU64-NEXT: [<corrupt>]
22 # GNU64-NEXT: [ 2] noflags
23 # GNU64-NEXT: PROGBITS 0000000000000000 000040 000000 00 0 0 0
24 # GNU64-NEXT: [0000000000000000]: {{$}}
25 # GNU64-NEXT: [ 3] write
26 # GNU64-NEXT: PROGBITS 0000000000000000 000040 000000 00 0 0 0
27 # GNU64-NEXT: [0000000000000001]: WRITE
28 # GNU64-NEXT: [ 4] alloc
29 # GNU64-NEXT: PROGBITS 0000000000000000 000040 000000 00 0 0 0
30 # GNU64-NEXT: [0000000000000002]: ALLOC
31 # GNU64-NEXT: [ 5] exec
32 # GNU64-NEXT: PROGBITS 0000000000000000 000040 000000 00 0 0 0
33 # GNU64-NEXT: [0000000000000004]: EXEC
34 # GNU64-NEXT: [ 6] merge
35 # GNU64-NEXT: PROGBITS 0000000000000000 000040 000000 00 0 0 0
36 # GNU64-NEXT: [0000000000000010]: MERGE
37 # GNU64-NEXT: [ 7] strings
38 # GNU64-NEXT: PROGBITS 0000000000000000 000040 000000 00 0 0 0
39 # GNU64-NEXT: [0000000000000020]: STRINGS
40 # GNU64-NEXT: [ 8] infolink
41 # GNU64-NEXT: PROGBITS 0000000000000000 000040 000000 00 0 0 0
42 # GNU64-NEXT: [0000000000000040]: INFO LINK
43 # GNU64-NEXT: [ 9] linkorder
44 # GNU64-NEXT: PROGBITS 0000000000000000 000040 000000 00 0 0 0
45 # GNU64-NEXT: [0000000000000080]: LINK ORDER
46 # GNU64-NEXT: [10] nonconforming
47 # GNU64-NEXT: PROGBITS 0000000000000000 000040 000000 00 0 0 0
48 # GNU64-NEXT: [0000000000000100]: OS NONCONF
49 # GNU64-NEXT: [11] group
50 # GNU64-NEXT: PROGBITS 0000000000000000 000040 000000 00 0 0 0
51 # GNU64-NEXT: [0000000000000200]: GROUP
52 # GNU64-NEXT: [12] tls
53 # GNU64-NEXT: PROGBITS 0000000000000000 000040 000000 00 0 0 0
54 # GNU64-NEXT: [0000000000000400]: TLS
55 # GNU64-NEXT: [13] exclude
56 # GNU64-NEXT: PROGBITS 0000000000000000 000040 000000 00 0 0 0
57 # GNU64-NEXT: [0000000080000000]: EXCLUDE
58 # GNU64-NEXT: [14] known_and_unknown
59 # GNU64-NEXT: PROGBITS 0000000000000000 000040 000000 00 0 0 0
60 # GNU64-NEXT: [00000000000f0003]: WRITE, ALLOC, UNKNOWN (00000000000f0000)
61 # GNU64-NEXT: [15] only_unknown
62 # GNU64-NEXT: PROGBITS 0000000000000000 000040 000000 00 0 0 0
63 # GNU64-NEXT: [00000000000f0000]: UNKNOWN (00000000000f0000)
64 # GNU64-NEXT: [16] compressed_corrupted
65 # GNU64-NEXT: PROGBITS 0000000000000000 000040 000000 00 0 0 0
66 # GNU64-NEXT: [0000000000000800]: COMPRESSED
67 # GNU64-NEXT:{{.*}}: warning: '[[FILE]]': SHF_COMPRESSED section 'compressed_corrupted' does not have an Elf_Chdr header
68 # GNU64-NEXT: [<corrupt>]
69 # GNU64-NEXT: [17] compressed_zlib
70 # GNU64-NEXT: PROGBITS 0000000000000000 000040 000023 00 0 0 0
71 # GNU64-NEXT: [0000000000000800]: COMPRESSED
72 # GNU64-NEXT: ZLIB, 0000000000000008, 4
73 # GNU64-NEXT: [18] compressed_zstd
74 # GNU64-NEXT: PROGBITS 0000000000000000 000063 000029 00 0 0 0
75 # GNU64-NEXT: [0000000000000800]: COMPRESSED
76 # GNU64-NEXT: ZSTD, 0000000000000008, 4
77 # GNU64-NEXT: [19] compressed_unknown
78 # GNU64-NEXT: PROGBITS 0000000000000000 00008c 000018 00 0 0 0
79 # GNU64-NEXT: [0000000000000800]: COMPRESSED
80 # GNU64-NEXT: [<unknown>: 0x3], 0000000000000008, 4
81 # GNU64-NEXT: [20] .strtab
82 # GNU64-NEXT: STRTAB 0000000000000000 0000a4 000001 00 0 0 1
83 # GNU64-NEXT: [0000000000000000]: {{$}}
84 # GNU64-NEXT: [21] .shstrtab
85 # GNU64-NEXT: STRTAB 0000000000000000 0000a5 0000ed 00 0 0 1
86 # GNU64-NEXT: [0000000000000000]: {{$}}
91 Class: ELFCLASS[[BITS]]
96 - Name: allflags_and_long_fields
98 ShFlags: 0xffffffffffffffff
99 Address: 0x1111111111111111
100 ShOffset: 0x2222222222222222
102 ShSize: 0x4444444444444444
103 EntSize: 0x5555555555555555
105 ShAddrAlign: 0x7777777777777777
117 Flags: [ SHF_EXECINSTR ]
123 Flags: [ SHF_STRINGS ]
126 Flags: [ SHF_INFO_LINK ]
129 Flags: [ SHF_LINK_ORDER ]
130 - Name: nonconforming
132 Flags: [ SHF_OS_NONCONFORMING ]
141 Flags: [ SHF_EXCLUDE ]
142 - Name: known_and_unknown
148 - Name: compressed_corrupted
150 Flags: [ SHF_COMPRESSED ]
151 - Name: compressed_zlib
153 Flags: [ SHF_COMPRESSED ]
154 Content: 01000000[[CHDR]]789c636080000000080001
155 - Name: compressed_zstd
157 Flags: [ SHF_COMPRESSED ]
158 Content: 02000000[[CHDR]]28b52ffd20084100000000000000000000
159 - Name: compressed_unknown
161 Flags: [ SHF_COMPRESSED ]
162 Content: 03000000[[CHDR]]
164 ## Check the output for the 32-bit case.
165 # RUN: yaml2obj %s -DBITS=32 -DCHDR=0400000002000000 -o %t32.o
166 # RUN: llvm-readelf %t32.o --section-details 2>&1 | \
167 # RUN: FileCheck %s -DFILE=%t32.o --strict-whitespace --match-full-lines --check-prefix=GNU32
169 # GNU32:There are 22 section headers, starting at offset 0x164:
171 # GNU32-NEXT:Section Headers:
172 # GNU32-NEXT: [Nr] Name
173 # GNU32-NEXT: Type Addr Off Size ES Lk Inf Al
175 # GNU32-NEXT: [ 0] {{$}}
176 # GNU32-NEXT: NULL 00000000 000000 000000 00 0 0 0
177 # GNU32-NEXT: [00000000]: {{$}}
178 # GNU32-NEXT: [ 1] allflags_and_long_fields
179 # GNU32-NEXT: PROGBITS 11111111 22222222 44444444 55555555 858993459 1717986918 2004318071
180 # GNU32-NEXT: [ffffffff]: WRITE, ALLOC, EXEC, MERGE, STRINGS, INFO LINK, LINK ORDER, OS NONCONF, GROUP, TLS, COMPRESSED, EXCLUDE, OS (0ff00000), PROC (70000000), UNKNOWN (000ff008)
181 # GNU32-NEXT:{{.*}}: warning: '[[FILE]]': SHF_COMPRESSED section 'allflags_and_long_fields' does not have an Elf_Chdr header
182 # GNU32-NEXT: [<corrupt>]
183 # GNU32-NEXT: [ 2] noflags
184 # GNU32-NEXT: PROGBITS 00000000 000034 000000 00 0 0 0
185 # GNU32-NEXT: [00000000]: {{$}}
186 # GNU32-NEXT: [ 3] write
187 # GNU32-NEXT: PROGBITS 00000000 000034 000000 00 0 0 0
188 # GNU32-NEXT: [00000001]: WRITE
189 # GNU32-NEXT: [ 4] alloc
190 # GNU32-NEXT: PROGBITS 00000000 000034 000000 00 0 0 0
191 # GNU32-NEXT: [00000002]: ALLOC
192 # GNU32-NEXT: [ 5] exec
193 # GNU32-NEXT: PROGBITS 00000000 000034 000000 00 0 0 0
194 # GNU32-NEXT: [00000004]: EXEC
195 # GNU32-NEXT: [ 6] merge
196 # GNU32-NEXT: PROGBITS 00000000 000034 000000 00 0 0 0
197 # GNU32-NEXT: [00000010]: MERGE
198 # GNU32-NEXT: [ 7] strings
199 # GNU32-NEXT: PROGBITS 00000000 000034 000000 00 0 0 0
200 # GNU32-NEXT: [00000020]: STRINGS
201 # GNU32-NEXT: [ 8] infolink
202 # GNU32-NEXT: PROGBITS 00000000 000034 000000 00 0 0 0
203 # GNU32-NEXT: [00000040]: INFO LINK
204 # GNU32-NEXT: [ 9] linkorder
205 # GNU32-NEXT: PROGBITS 00000000 000034 000000 00 0 0 0
206 # GNU32-NEXT: [00000080]: LINK ORDER
207 # GNU32-NEXT: [10] nonconforming
208 # GNU32-NEXT: PROGBITS 00000000 000034 000000 00 0 0 0
209 # GNU32-NEXT: [00000100]: OS NONCONF
210 # GNU32-NEXT: [11] group
211 # GNU32-NEXT: PROGBITS 00000000 000034 000000 00 0 0 0
212 # GNU32-NEXT: [00000200]: GROUP
213 # GNU32-NEXT: [12] tls
214 # GNU32-NEXT: PROGBITS 00000000 000034 000000 00 0 0 0
215 # GNU32-NEXT: [00000400]: TLS
216 # GNU32-NEXT: [13] exclude
217 # GNU32-NEXT: PROGBITS 00000000 000034 000000 00 0 0 0
218 # GNU32-NEXT: [80000000]: EXCLUDE
219 # GNU32-NEXT: [14] known_and_unknown
220 # GNU32-NEXT: PROGBITS 00000000 000034 000000 00 0 0 0
221 # GNU32-NEXT: [000f0003]: WRITE, ALLOC, UNKNOWN (000f0000)
222 # GNU32-NEXT: [15] only_unknown
223 # GNU32-NEXT: PROGBITS 00000000 000034 000000 00 0 0 0
224 # GNU32-NEXT: [000f0000]: UNKNOWN (000f0000)
225 # GNU32-NEXT: [16] compressed_corrupted
226 # GNU32-NEXT: PROGBITS 00000000 000034 000000 00 0 0 0
227 # GNU32-NEXT: [00000800]: COMPRESSED
228 # GNU32-NEXT:{{.*}}: warning: '[[FILE]]': SHF_COMPRESSED section 'compressed_corrupted' does not have an Elf_Chdr header
229 # GNU32-NEXT: [<corrupt>]
230 # GNU32-NEXT: [17] compressed_zlib
231 # GNU32-NEXT: PROGBITS 00000000 000034 000017 00 0 0 0
232 # GNU32-NEXT: [00000800]: COMPRESSED
233 # GNU32-NEXT: ZLIB, 00000004, 2
234 # GNU32-NEXT: [18] compressed_zstd
235 # GNU32-NEXT: PROGBITS 00000000 00004b 00001d 00 0 0 0
236 # GNU32-NEXT: [00000800]: COMPRESSED
237 # GNU32-NEXT: ZSTD, 00000004, 2
238 # GNU32-NEXT: [19] compressed_unknown
239 # GNU32-NEXT: PROGBITS 00000000 000068 00000c 00 0 0 0
240 # GNU32-NEXT: [00000800]: COMPRESSED
241 # GNU32-NEXT: [<unknown>: 0x3], 00000004, 2
242 # GNU32-NEXT: [20] .strtab
243 # GNU32-NEXT: STRTAB 00000000 000074 000001 00 0 0 1
244 # GNU32-NEXT: [00000000]: {{$}}
245 # GNU32-NEXT: [21] .shstrtab
246 # GNU32-NEXT: STRTAB 00000000 000075 0000ed 00 0 0 1
247 # GNU32-NEXT: [00000000]: {{$}}
250 ## When --section-details and --sections are both specified, --sections is ignored.
251 # RUN: llvm-readelf %t64.o --section-details --sections 2>&1 | FileCheck %s -DFILE=%t64.o --check-prefix=GNU64
252 # RUN: llvm-readelf %t64.o --sections --section-details 2>&1 | FileCheck %s -DFILE=%t64.o --check-prefix=GNU64
254 ## Check that we produce the same output with -t (alias).
255 # RUN: llvm-readelf --section-details %t64.o > %t.readelf.full
256 # RUN: llvm-readelf -t %t64.o > %t.readelf.alias
257 # RUN: cmp %t.readelf.full %t.readelf.alias
259 ## Check how we dump sections when the section header string table can't be read.
261 # RUN: yaml2obj --docnum=2 %s -o %tshstrndx.o
262 # RUN: llvm-readelf %tshstrndx.o --section-details 2>&1 | \
263 # RUN: FileCheck %s -DFILE=%tshstrndx.o --check-prefix=SHSTRNDX
265 # SHSTRNDX: Section Headers:
266 # SHSTRNDX-NEXT: [Nr] Name
267 # SHSTRNDX-NEXT: Type Address Off Size ES Lk Inf Al
268 # SHSTRNDX-NEXT: Flags
269 # SHSTRNDX-NEXT: warning: '[[FILE]]': section header string table index 65279 does not exist
270 # SHSTRNDX-NEXT: [ 0]
271 # SHSTRNDX-NEXT: NULL 0000000000000000 000000 000000 00 0 0 0
272 # SHSTRNDX-NEXT: [0000000000000000]:
273 # SHSTRNDX-NEXT: warning: '[[FILE]]': a section [index 1] has an invalid sh_name (0x5) offset which goes past the end of the section name string table
274 # SHSTRNDX-NEXT: [ 1] <?>
275 # SHSTRNDX-NEXT: PROGBITS 0000000000000000 000040 000000 00 0 0 0
276 # SHSTRNDX-NEXT: [0000000000000000]:
277 # SHSTRNDX-NEXT: warning: '[[FILE]]': a section [index 2] has an invalid sh_name (0x1) offset which goes past the end of the section name string table
278 # SHSTRNDX-NEXT: [ 2] <?>
279 # SHSTRNDX-NEXT: PROGBITS 0000000000000000 000040 000000 00 0 0 0
280 # SHSTRNDX-NEXT: [0000000000000000]:
281 # SHSTRNDX-NEXT: warning: '[[FILE]]': a section [index 3] has an invalid sh_name (0x13) offset which goes past the end of the section name string table
282 # SHSTRNDX-NEXT: [ 3] <?>
283 # SHSTRNDX-NEXT: STRTAB 0000000000000000 000040 000001 00 0 0 1
284 # SHSTRNDX-NEXT: [0000000000000000]:
285 # SHSTRNDX-NEXT: warning: '[[FILE]]': a section [index 4] has an invalid sh_name (0x9) offset which goes past the end of the section name string table
286 # SHSTRNDX-NEXT: [ 4] <?>
287 # SHSTRNDX-NEXT: STRTAB 0000000000000000 000041 00001b 00 0 0 1
288 # SHSTRNDX-NEXT: [0000000000000000]: