aboutsummaryrefslogtreecommitdiff
path: root/llvm/test/tools/llvm-readobj/ELF/section-details.test
blob: 1b906761d9f6c63960a38cce2c2325459fd55e69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
## Check how llvm-readelf prints section details with --section-details.

## Check the output for the 64-bit case.
# RUN: yaml2obj %s -DBITS=64 -DCHDR=0000000008000000000000000400000000000000 -o %t64.o
# RUN: llvm-readelf %t64.o --section-details 2>&1 | \
# RUN:   FileCheck %s -DFILE=%t64.o --strict-whitespace --match-full-lines --check-prefix=GNU64

#       GNU64:There are 22 section headers, starting at offset 0x198:
# GNU64-EMPTY:
#  GNU64-NEXT:Section Headers:
#  GNU64-NEXT:  [Nr] Name
#  GNU64-NEXT:       Type            Address          Off    Size   ES   Lk Inf Al
#  GNU64-NEXT:       Flags
#  GNU64-NEXT:  [ 0] {{$}}
#  GNU64-NEXT:       NULL            0000000000000000 000000 000000 00   0   0  0
#  GNU64-NEXT:       [0000000000000000]: {{$}}
#  GNU64-NEXT:  [ 1] allflags_and_long_fields
#  GNU64-NEXT:       PROGBITS        1111111111111111 2222222222222222 4444444444444444 5555555555555555 858993459 1717986918 8608480567731124087
#  GNU64-NEXT:       [ffffffffffffffff]: WRITE, ALLOC, EXEC, MERGE, STRINGS, INFO LINK, LINK ORDER, OS NONCONF, GROUP, TLS, COMPRESSED, EXCLUDE, OS (000000000ff00000), PROC (0000000070000000), UNKNOWN (ffffffff000ff008)
#  GNU64-NEXT:{{.*}}: warning: '[[FILE]]': SHF_COMPRESSED section 'allflags_and_long_fields' does not have an Elf_Chdr header
#  GNU64-NEXT:       [<corrupt>]
#  GNU64-NEXT:  [ 2] noflags
#  GNU64-NEXT:       PROGBITS        0000000000000000 000040 000000 00   0   0  0
#  GNU64-NEXT:       [0000000000000000]: {{$}}
#  GNU64-NEXT:  [ 3] write
#  GNU64-NEXT:       PROGBITS        0000000000000000 000040 000000 00   0   0  0
#  GNU64-NEXT:       [0000000000000001]: WRITE
#  GNU64-NEXT:  [ 4] alloc
#  GNU64-NEXT:       PROGBITS        0000000000000000 000040 000000 00   0   0  0
#  GNU64-NEXT:       [0000000000000002]: ALLOC
#  GNU64-NEXT:  [ 5] exec
#  GNU64-NEXT:       PROGBITS        0000000000000000 000040 000000 00   0   0  0
#  GNU64-NEXT:       [0000000000000004]: EXEC
#  GNU64-NEXT:  [ 6] merge
#  GNU64-NEXT:       PROGBITS        0000000000000000 000040 000000 00   0   0  0
#  GNU64-NEXT:       [0000000000000010]: MERGE
#  GNU64-NEXT:  [ 7] strings
#  GNU64-NEXT:       PROGBITS        0000000000000000 000040 000000 00   0   0  0
#  GNU64-NEXT:       [0000000000000020]: STRINGS
#  GNU64-NEXT:  [ 8] infolink
#  GNU64-NEXT:       PROGBITS        0000000000000000 000040 000000 00   0   0  0
#  GNU64-NEXT:       [0000000000000040]: INFO LINK
#  GNU64-NEXT:  [ 9] linkorder
#  GNU64-NEXT:       PROGBITS        0000000000000000 000040 000000 00   0   0  0
#  GNU64-NEXT:       [0000000000000080]: LINK ORDER
#  GNU64-NEXT:  [10] nonconforming
#  GNU64-NEXT:       PROGBITS        0000000000000000 000040 000000 00   0   0  0
#  GNU64-NEXT:       [0000000000000100]: OS NONCONF
#  GNU64-NEXT:  [11] group
#  GNU64-NEXT:       PROGBITS        0000000000000000 000040 000000 00   0   0  0
#  GNU64-NEXT:       [0000000000000200]: GROUP
#  GNU64-NEXT:  [12] tls
#  GNU64-NEXT:       PROGBITS        0000000000000000 000040 000000 00   0   0  0
#  GNU64-NEXT:       [0000000000000400]: TLS
#  GNU64-NEXT:  [13] exclude
#  GNU64-NEXT:       PROGBITS        0000000000000000 000040 000000 00   0   0  0
#  GNU64-NEXT:       [0000000080000000]: EXCLUDE
#  GNU64-NEXT:  [14] known_and_unknown
#  GNU64-NEXT:       PROGBITS        0000000000000000 000040 000000 00   0   0  0
#  GNU64-NEXT:       [00000000000f0003]: WRITE, ALLOC, UNKNOWN (00000000000f0000)
#  GNU64-NEXT:  [15] only_unknown
#  GNU64-NEXT:       PROGBITS        0000000000000000 000040 000000 00   0   0  0
#  GNU64-NEXT:       [00000000000f0000]: UNKNOWN (00000000000f0000)
#  GNU64-NEXT:  [16] compressed_corrupted
#  GNU64-NEXT:       PROGBITS        0000000000000000 000040 000000 00   0   0  0
#  GNU64-NEXT:       [0000000000000800]: COMPRESSED
#  GNU64-NEXT:{{.*}}: warning: '[[FILE]]': SHF_COMPRESSED section 'compressed_corrupted' does not have an Elf_Chdr header
#  GNU64-NEXT:       [<corrupt>]
#  GNU64-NEXT:  [17] compressed_zlib
#  GNU64-NEXT:       PROGBITS        0000000000000000 000040 000023 00   0   0  0
#  GNU64-NEXT:       [0000000000000800]: COMPRESSED
#  GNU64-NEXT:       ZLIB, 0000000000000008, 4
#  GNU64-NEXT:  [18] compressed_zstd
#  GNU64-NEXT:       PROGBITS        0000000000000000 000063 000029 00   0   0  0
#  GNU64-NEXT:       [0000000000000800]: COMPRESSED
#  GNU64-NEXT:       ZSTD, 0000000000000008, 4
#  GNU64-NEXT:  [19] compressed_unknown
#  GNU64-NEXT:       PROGBITS        0000000000000000 00008c 000018 00   0   0  0
#  GNU64-NEXT:       [0000000000000800]: COMPRESSED
#  GNU64-NEXT:       [<unknown>: 0x3], 0000000000000008, 4
#  GNU64-NEXT:  [20] .strtab
#  GNU64-NEXT:       STRTAB          0000000000000000 0000a4 000001 00   0   0  1
#  GNU64-NEXT:       [0000000000000000]: {{$}}
#  GNU64-NEXT:  [21] .shstrtab
#  GNU64-NEXT:       STRTAB          0000000000000000 0000a5 0000ed 00   0   0  1
#  GNU64-NEXT:       [0000000000000000]: {{$}}
#  GNU64-NOT:{{.}}

--- !ELF
FileHeader:
  Class: ELFCLASS[[BITS]]
  Data:  ELFDATA2LSB
  Type:  ET_REL
  Flags: []
Sections:
  - Name:        allflags_and_long_fields
    Type:        SHT_PROGBITS
    ShFlags:     0xffffffffffffffff
    Address:     0x1111111111111111
    ShOffset:    0x2222222222222222
    Link:        0x33333333
    ShSize:      0x4444444444444444
    EntSize:     0x5555555555555555
    Info:        0x66666666
    ShAddrAlign: 0x7777777777777777
  - Name:  noflags
    Type:  SHT_PROGBITS
    Flags: [ ]
  - Name:  write
    Type:  SHT_PROGBITS
    Flags: [ SHF_WRITE ]
  - Name:  alloc
    Type:  SHT_PROGBITS
    Flags: [ SHF_ALLOC ]
  - Name:  exec
    Type:  SHT_PROGBITS
    Flags: [ SHF_EXECINSTR ]
  - Name:  merge
    Type:  SHT_PROGBITS
    Flags: [ SHF_MERGE ]
  - Name:  strings
    Type:  SHT_PROGBITS
    Flags: [ SHF_STRINGS ]
  - Name:  infolink
    Type:  SHT_PROGBITS
    Flags: [ SHF_INFO_LINK ]
  - Name:  linkorder
    Type:  SHT_PROGBITS
    Flags: [ SHF_LINK_ORDER ]
  - Name:  nonconforming
    Type:  SHT_PROGBITS
    Flags: [ SHF_OS_NONCONFORMING ]
  - Name:  group
    Type:  SHT_PROGBITS
    Flags: [ SHF_GROUP ]
  - Name:  tls
    Type:  SHT_PROGBITS
    Flags: [ SHF_TLS ]
  - Name:  exclude
    Type:  SHT_PROGBITS
    Flags: [ SHF_EXCLUDE ]
  - Name:  known_and_unknown
    Type:  SHT_PROGBITS
    ShFlags: 0x000f0003
  - Name:  only_unknown
    Type:  SHT_PROGBITS
    ShFlags: 0x000f0000
  - Name:  compressed_corrupted
    Type:  SHT_PROGBITS
    Flags: [ SHF_COMPRESSED ]
  - Name:  compressed_zlib
    Type:  SHT_PROGBITS
    Flags: [ SHF_COMPRESSED ]
    Content: 01000000[[CHDR]]789c636080000000080001
  - Name:  compressed_zstd
    Type:  SHT_PROGBITS
    Flags: [ SHF_COMPRESSED ]
    Content: 02000000[[CHDR]]28b52ffd20084100000000000000000000
  - Name:  compressed_unknown
    Type:  SHT_PROGBITS
    Flags: [ SHF_COMPRESSED ]
    Content: 03000000[[CHDR]]

## Check the output for the 32-bit case.
# RUN: yaml2obj %s -DBITS=32 -DCHDR=0400000002000000 -o %t32.o
# RUN: llvm-readelf %t32.o --section-details 2>&1 | \
# RUN:   FileCheck %s -DFILE=%t32.o --strict-whitespace --match-full-lines --check-prefix=GNU32

#       GNU32:There are 22 section headers, starting at offset 0x164:
# GNU32-EMPTY:
#  GNU32-NEXT:Section Headers:
#  GNU32-NEXT:  [Nr] Name
#  GNU32-NEXT:       Type            Addr     Off    Size   ES   Lk Inf Al
#  GNU32-NEXT:       Flags
#  GNU32-NEXT:  [ 0] {{$}}
#  GNU32-NEXT:       NULL            00000000 000000 000000 00   0   0  0
#  GNU32-NEXT:       [00000000]: {{$}}
#  GNU32-NEXT:  [ 1] allflags_and_long_fields
#  GNU32-NEXT:       PROGBITS        11111111 22222222 44444444 55555555 858993459 1717986918 2004318071
#  GNU32-NEXT:       [ffffffff]: WRITE, ALLOC, EXEC, MERGE, STRINGS, INFO LINK, LINK ORDER, OS NONCONF, GROUP, TLS, COMPRESSED, EXCLUDE, OS (0ff00000), PROC (70000000), UNKNOWN (000ff008)
#  GNU32-NEXT:{{.*}}: warning: '[[FILE]]': SHF_COMPRESSED section 'allflags_and_long_fields' does not have an Elf_Chdr header
#  GNU32-NEXT:       [<corrupt>]
#  GNU32-NEXT:  [ 2] noflags
#  GNU32-NEXT:       PROGBITS        00000000 000034 000000 00   0   0  0
#  GNU32-NEXT:       [00000000]: {{$}}
#  GNU32-NEXT:  [ 3] write
#  GNU32-NEXT:       PROGBITS        00000000 000034 000000 00   0   0  0
#  GNU32-NEXT:       [00000001]: WRITE
#  GNU32-NEXT:  [ 4] alloc
#  GNU32-NEXT:       PROGBITS        00000000 000034 000000 00   0   0  0
#  GNU32-NEXT:       [00000002]: ALLOC
#  GNU32-NEXT:  [ 5] exec
#  GNU32-NEXT:       PROGBITS        00000000 000034 000000 00   0   0  0
#  GNU32-NEXT:       [00000004]: EXEC
#  GNU32-NEXT:  [ 6] merge
#  GNU32-NEXT:       PROGBITS        00000000 000034 000000 00   0   0  0
#  GNU32-NEXT:       [00000010]: MERGE
#  GNU32-NEXT:  [ 7] strings
#  GNU32-NEXT:       PROGBITS        00000000 000034 000000 00   0   0  0
#  GNU32-NEXT:       [00000020]: STRINGS
#  GNU32-NEXT:  [ 8] infolink
#  GNU32-NEXT:       PROGBITS        00000000 000034 000000 00   0   0  0
#  GNU32-NEXT:       [00000040]: INFO LINK
#  GNU32-NEXT:  [ 9] linkorder
#  GNU32-NEXT:       PROGBITS        00000000 000034 000000 00   0   0  0
#  GNU32-NEXT:       [00000080]: LINK ORDER
#  GNU32-NEXT:  [10] nonconforming
#  GNU32-NEXT:       PROGBITS        00000000 000034 000000 00   0   0  0
#  GNU32-NEXT:       [00000100]: OS NONCONF
#  GNU32-NEXT:  [11] group
#  GNU32-NEXT:       PROGBITS        00000000 000034 000000 00   0   0  0
#  GNU32-NEXT:       [00000200]: GROUP
#  GNU32-NEXT:  [12] tls
#  GNU32-NEXT:       PROGBITS        00000000 000034 000000 00   0   0  0
#  GNU32-NEXT:       [00000400]: TLS
#  GNU32-NEXT:  [13] exclude
#  GNU32-NEXT:       PROGBITS        00000000 000034 000000 00   0   0  0
#  GNU32-NEXT:       [80000000]: EXCLUDE
#  GNU32-NEXT:  [14] known_and_unknown
#  GNU32-NEXT:       PROGBITS        00000000 000034 000000 00   0   0  0
#  GNU32-NEXT:       [000f0003]: WRITE, ALLOC, UNKNOWN (000f0000)
#  GNU32-NEXT:  [15] only_unknown
#  GNU32-NEXT:       PROGBITS        00000000 000034 000000 00   0   0  0
#  GNU32-NEXT:       [000f0000]: UNKNOWN (000f0000)
#  GNU32-NEXT:  [16] compressed_corrupted
#  GNU32-NEXT:       PROGBITS        00000000 000034 000000 00   0   0  0
#  GNU32-NEXT:       [00000800]: COMPRESSED
#  GNU32-NEXT:{{.*}}: warning: '[[FILE]]': SHF_COMPRESSED section 'compressed_corrupted' does not have an Elf_Chdr header
#  GNU32-NEXT:       [<corrupt>]
#  GNU32-NEXT:  [17] compressed_zlib
#  GNU32-NEXT:       PROGBITS        00000000 000034 000017 00   0   0  0
#  GNU32-NEXT:       [00000800]: COMPRESSED
#  GNU32-NEXT:       ZLIB, 00000004, 2
#  GNU32-NEXT:  [18] compressed_zstd
#  GNU32-NEXT:       PROGBITS        00000000 00004b 00001d 00   0   0  0
#  GNU32-NEXT:       [00000800]: COMPRESSED
#  GNU32-NEXT:       ZSTD, 00000004, 2
#  GNU32-NEXT:  [19] compressed_unknown
#  GNU32-NEXT:       PROGBITS        00000000 000068 00000c 00   0   0  0
#  GNU32-NEXT:       [00000800]: COMPRESSED
#  GNU32-NEXT:       [<unknown>: 0x3], 00000004, 2
#  GNU32-NEXT:  [20] .strtab
#  GNU32-NEXT:       STRTAB          00000000 000074 000001 00   0   0  1
#  GNU32-NEXT:       [00000000]: {{$}}
#  GNU32-NEXT:  [21] .shstrtab
#  GNU32-NEXT:       STRTAB          00000000 000075 0000ed 00   0   0  1
#  GNU32-NEXT:       [00000000]: {{$}}
#  GNU32-NOT:{{.}}

## When --section-details and --sections are both specified, --sections is ignored.
# RUN: llvm-readelf %t64.o --section-details --sections 2>&1 | FileCheck %s -DFILE=%t64.o --check-prefix=GNU64
# RUN: llvm-readelf %t64.o --sections --section-details 2>&1 | FileCheck %s -DFILE=%t64.o --check-prefix=GNU64

## Check that we produce the same output with -t (alias).
# RUN: llvm-readelf --section-details %t64.o > %t.readelf.full
# RUN: llvm-readelf -t %t64.o > %t.readelf.alias
# RUN: cmp %t.readelf.full %t.readelf.alias

## Check how we dump sections when the section header string table can't be read.

# RUN: yaml2obj --docnum=2 %s -o %tshstrndx.o
# RUN: llvm-readelf %tshstrndx.o --section-details 2>&1 | \
# RUN:   FileCheck %s -DFILE=%tshstrndx.o --check-prefix=SHSTRNDX

# SHSTRNDX:      Section Headers:
# SHSTRNDX-NEXT:   [Nr] Name
# SHSTRNDX-NEXT:        Type            Address          Off    Size   ES   Lk Inf Al
# SHSTRNDX-NEXT:        Flags
# SHSTRNDX-NEXT: warning: '[[FILE]]': section header string table index 65279 does not exist
# SHSTRNDX-NEXT:   [ 0]
# SHSTRNDX-NEXT:        NULL            0000000000000000 000000 000000 00   0   0  0
# SHSTRNDX-NEXT:        [0000000000000000]:
# 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
# SHSTRNDX-NEXT:   [ 1] <?>
# SHSTRNDX-NEXT:        PROGBITS        0000000000000000 000040 000000 00   0   0  0
# SHSTRNDX-NEXT:        [0000000000000000]:
# 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
# SHSTRNDX-NEXT:   [ 2] <?>
# SHSTRNDX-NEXT:        PROGBITS        0000000000000000 000040 000000 00   0   0  0
# SHSTRNDX-NEXT:        [0000000000000000]:
# 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
# SHSTRNDX-NEXT:   [ 3] <?>
# SHSTRNDX-NEXT:        STRTAB          0000000000000000 000040 000001 00   0   0  1
# SHSTRNDX-NEXT:        [0000000000000000]:
# 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
# SHSTRNDX-NEXT:   [ 4] <?>
# SHSTRNDX-NEXT:        STRTAB          0000000000000000 000041 00001b 00   0   0  1
# SHSTRNDX-NEXT:        [0000000000000000]:

--- !ELF
FileHeader:
  Class:     ELFCLASS64
  Data:      ELFDATA2LSB
  Type:      ET_REL
  EShStrNdx: 0xfeff
Sections:
  - Name: foo
    Type: SHT_PROGBITS
  - Name: bar
    Type: SHT_PROGBITS