xref: /llvm-project/llvm/test/tools/llvm-readobj/ELF/sections-ext.test (revision 7749e2de20d82a6bb8b8beaa74b2a8dbd8232067)
1## This is a test case for --section-symbols, --section-relocations and
2## --section-data command line flags and their aliases.
3
4# RUN: yaml2obj %s -o %t
5
6## Test --section-symbols (--st) displays symbols for each section.
7# RUN: llvm-readobj --sections --st %t > %t.readobj-st
8# RUN: llvm-readobj --sections --section-symbols %t > %t.readobj-st-no-alias
9# RUN: diff %t.readobj-st %t.readobj-st-no-alias
10# RUN: FileCheck %s --input-file=%t.readobj-st --check-prefixes=ALL,ST
11
12## Test --section-relocations (--sr) displays relocations for each section.
13# RUN: llvm-readobj --sections --sr %t > %t.readobj-sr
14# RUN: llvm-readobj --sections --section-relocations %t > %t.readobj-sr-no-alias
15# RUN: diff %t.readobj-sr %t.readobj-sr-no-alias
16# RUN: FileCheck %s --input-file=%t.readobj-sr --check-prefixes=ALL,SR
17
18## Test --section-data (--sd) displays section data for each section except SHT_NOBITS sections.
19# RUN: llvm-readobj --sections --sd %t > %t.readobj-sd
20# RUN: llvm-readobj --sections --section-data %t > %t.readobj-sd-no-alias
21# RUN: diff %t.readobj-sd %t.readobj-sd-no-alias
22# RUN: FileCheck %s --input-file=%t.readobj-sd --check-prefixes=ALL,SD
23
24## Test all options together.
25# RUN: llvm-readobj --sections --section-symbols --section-relocations --section-data %t | \
26# RUN:   FileCheck %s --check-prefixes=ALL,ST,SR,SD
27
28# ALL:      Sections [
29# ALL-NEXT:   Section {
30# ALL-NEXT:     Index: 0
31# ALL-NEXT:     Name:  (0)
32# ALL-NEXT:     Type: SHT_NULL (0x0)
33# ALL-NEXT:     Flags [ (0x0)
34# ALL-NEXT:     ]
35# ALL-NEXT:     Address: 0x0
36# ALL-NEXT:     Offset: 0x0
37# ALL-NEXT:     Size: 0
38# ALL-NEXT:     Link: 0
39# ALL-NEXT:     Info: 0
40# ALL-NEXT:     AddressAlignment: 0
41# ALL-NEXT:     EntrySize: 0
42# SR-NEXT:      Relocations [
43# SR-NEXT:      ]
44# ST-NEXT:      Symbols [
45# ST-NEXT:      ]
46# SD-NEXT:      SectionData (
47# SD-NEXT:      )
48# ALL-NEXT:   }
49# ALL-NEXT:   Section {
50# ALL-NEXT:     Index: 1
51# ALL-NEXT:     Name: .text (6)
52# ALL-NEXT:     Type: SHT_PROGBITS (0x1)
53# ALL-NEXT:     Flags [ (0x0)
54# ALL-NEXT:     ]
55# ALL-NEXT:     Address: 0x0
56# ALL-NEXT:     Offset: 0x40
57# ALL-NEXT:     Size: 0
58# ALL-NEXT:     Link: 0
59# ALL-NEXT:     Info: 0
60# ALL-NEXT:     AddressAlignment: 0
61# ALL-NEXT:     EntrySize: 0
62# SR-NEXT:      Relocations [
63# SR-NEXT:      ]
64# ST-NEXT:      Symbols [
65# ST-NEXT:        Symbol {
66# ST-NEXT:          Name: foo (1)
67# ST-NEXT:          Value: 0x0
68# ST-NEXT:          Size: 0
69# ST-NEXT:          Binding: Local (0x0)
70# ST-NEXT:          Type: None (0x0)
71# ST-NEXT:          Other: 0
72# ST-NEXT:          Section: .text (0x1)
73# ST-NEXT:        }
74# ST-NEXT:      ]
75# SD-NEXT:      SectionData (
76# SD-NEXT:      )
77# ALL-NEXT:   }
78# ALL-NEXT:   Section {
79# ALL-NEXT:     Index: 2
80# ALL-NEXT:     Name: .rela.text (1)
81# ALL-NEXT:     Type: SHT_RELA (0x4)
82# ALL-NEXT:     Flags [ (0x0)
83# ALL-NEXT:     ]
84# ALL-NEXT:     Address: 0x0
85# ALL-NEXT:     Offset: 0x40
86# ALL-NEXT:     Size: 24
87# ALL-NEXT:     Link: 4
88# ALL-NEXT:     Info: 1
89# ALL-NEXT:     AddressAlignment: 0
90# ALL-NEXT:     EntrySize: 24
91# SR-NEXT:      Relocations [
92# SR-NEXT:        0x0 R_X86_64_NONE - 0x0
93# SR-NEXT:      ]
94# ST-NEXT:      Symbols [
95# ST-NEXT:      ]
96# SD-NEXT:      SectionData (
97# SD-NEXT:        0000: 00000000 00000000 00000000 00000000  |................|
98# SD-NEXT:        0010: 00000000 00000000                    |........|
99# SD-NEXT:      )
100# ALL-NEXT:   }
101# ALL-NEXT:   Section {
102# ALL-NEXT:     Index: 3
103# ALL-NEXT:     Name: .bss (12)
104# ALL-NEXT:     Type: SHT_NOBITS (0x8)
105# ALL-NEXT:     Flags [ (0x0)
106# ALL-NEXT:     ]
107# ALL-NEXT:     Address: 0x0
108# ALL-NEXT:     Offset: 0x58
109# ALL-NEXT:     Size: 4096
110# ALL-NEXT:     Link: 0
111# ALL-NEXT:     Info: 0
112# ALL-NEXT:     AddressAlignment: 0
113# ALL-NEXT:     EntrySize: 0
114# SR-NEXT:      Relocations [
115# SR-NEXT:      ]
116# ST-NEXT:      Symbols [
117# ST-NEXT:      ]
118# ALL-NEXT:   }
119# ALL-NEXT:   Section {
120# ALL-NEXT:     Index: 4
121# ALL-NEXT:     Name: .symtab (35)
122# ALL-NEXT:     Type: SHT_SYMTAB (0x2)
123# ALL-NEXT:     Flags [ (0x0)
124# ALL-NEXT:     ]
125# ALL-NEXT:     Address: 0x0
126# ALL-NEXT:     Offset: 0x58
127# ALL-NEXT:     Size: 48
128# ALL-NEXT:     Link: 5
129# ALL-NEXT:     Info: 2
130# ALL-NEXT:     AddressAlignment: 8
131# ALL-NEXT:     EntrySize: 24
132# SR-NEXT:      Relocations [
133# SR-NEXT:      ]
134# ST-NEXT:      Symbols [
135# ST-NEXT:      ]
136# SD-NEXT:      SectionData (
137# SD-NEXT:        0000: 00000000 00000000 00000000 00000000  |................|
138# SD-NEXT:        0010: 00000000 00000000 01000000 00000100  |................|
139# SD-NEXT:        0020: 00000000 00000000 00000000 00000000  |................|
140# SD-NEXT:      )
141# ALL-NEXT:   }
142# ALL-NEXT:   Section {
143# ALL-NEXT:     Index: 5
144# ALL-NEXT:     Name: .strtab (27)
145# ALL-NEXT:     Type: SHT_STRTAB (0x3)
146# ALL-NEXT:     Flags [ (0x0)
147# ALL-NEXT:     ]
148# ALL-NEXT:     Address: 0x0
149# ALL-NEXT:     Offset: 0x88
150# ALL-NEXT:     Size: 5
151# ALL-NEXT:     Link: 0
152# ALL-NEXT:     Info: 0
153# ALL-NEXT:     AddressAlignment: 1
154# ALL-NEXT:     EntrySize: 0
155# SR-NEXT:      Relocations [
156# SR-NEXT:      ]
157# ST-NEXT:      Symbols [
158# ST-NEXT:      ]
159# SD-NEXT:      SectionData (
160# SD-NEXT:        0000: 00666F6F 00 |.foo.|
161# SD-NEXT:      )
162# ALL-NEXT:   }
163# ALL-NEXT:   Section {
164# ALL-NEXT:     Index: 6
165# ALL-NEXT:     Name: .shstrtab (17)
166# ALL-NEXT:     Type: SHT_STRTAB (0x3)
167# ALL-NEXT:     Flags [ (0x0)
168# ALL-NEXT:     ]
169# ALL-NEXT:     Address: 0x0
170# ALL-NEXT:     Offset: 0x8D
171# ALL-NEXT:     Size: 43
172# ALL-NEXT:     Link: 0
173# ALL-NEXT:     Info: 0
174# ALL-NEXT:     AddressAlignment: 1
175# ALL-NEXT:     EntrySize: 0
176# SR-NEXT:      Relocations [
177# SR-NEXT:      ]
178# ST-NEXT:      Symbols [
179# ST-NEXT:      ]
180# SD-NEXT:      SectionData (
181# SD-NEXT:        0000: 002E7265 6C612E74 65787400 2E627373 |..rela.text..bss|
182# SD-NEXT:        0010: 002E7368 73747274 6162002E 73747274 |..shstrtab..strt|
183# SD-NEXT:        0020: 6162002E 73796D74 616200            |ab..symtab.|
184# SD-NEXT:      )
185# ALL-NEXT:   }
186# ALL-NEXT: ]
187
188## Check that --section-symbols, --section-relocations and --section-data
189## options produce no output without --sections.
190# RUN: llvm-readobj --section-symbols --section-relocations --section-data %t | \
191# RUN:   FileCheck %s -DFILE=%t --check-prefix=NO-SECTIONS
192
193# NO-SECTIONS:      File: [[FILE]]
194# NO-SECTIONS-NEXT: Format: elf64-x86-64
195# NO-SECTIONS-NEXT: Arch: x86_64
196# NO-SECTIONS-NEXT: AddressSize: 64bit
197# NO-SECTIONS-NEXT: LoadName: <Not found>
198# NO-SECTIONS-NOT:  {{.}}
199
200--- !ELF
201FileHeader:
202  Class:   ELFCLASS64
203  Data:    ELFDATA2LSB
204  Type:    ET_REL
205  Machine: EM_X86_64
206Sections:
207  - Name: .text
208    Type: SHT_PROGBITS
209  - Name: .rela.text
210    Type: SHT_RELA
211    Info: .text
212    Relocations:
213      - Type: R_X86_64_NONE
214  - Name: .bss
215    Type: SHT_NOBITS
216    Size: 0x1000
217Symbols:
218  - Name:    foo
219    Section: .text
220
221## Check the output for an arbitrary section when --section-symbols is requested,
222## but there is no symbol table in the object.
223# RUN: yaml2obj --docnum=2 %s -o %t2
224# RUN: llvm-readobj -S --section-symbols %t2 2>&1 | \
225# RUN:   FileCheck %s --implicit-check-not=warning: --check-prefix=NOSYMTAB
226
227# NOSYMTAB:      Section {
228# NOSYMTAB:        Index: 1
229# NOSYMTAB-NEXT:   Name: .foo
230# NOSYMTAB:        Symbols [
231# NOSYMTAB-NEXT:   ]
232# NOSYMTAB-NEXT: }
233# NOSYMTAB-NEXT: Section {
234# NOSYMTAB-NEXT:   Index: 2
235
236--- !ELF
237FileHeader:
238  Class:   ELFCLASS64
239  Data:    ELFDATA2LSB
240  Type:    ET_REL
241  Machine: EM_X86_64
242Sections:
243  - Name: .foo
244    Type: SHT_PROGBITS
245