xref: /llvm-project/llvm/test/tools/llvm-objcopy/ELF/many-sections.test (revision 49c91a64fd375574970ed5d8c926f71425d18d76)
1## Show that llvm-objcopy can handle an input file with many sections.
2
3RUN: %python %p/../Inputs/ungzip.py %p/Inputs/many-sections.o.gz > %t
4RUN: llvm-objcopy %t %t2
5RUN: llvm-readobj --file-headers --sections --symbols %t2 | FileCheck %s
6RUN: llvm-readelf --symbols %t2 | FileCheck --check-prefix=SYMS %s
7
8## The ELF header should have e_shnum == 0 and e_shstrndx == SHN_XINDEX.
9# CHECK:        SectionHeaderCount: 0
10# CHECK-NEXT:   StringTableSectionIndex: 65535
11
12## The first section header should store the real section header count and
13## shstrndx in its fields.
14# CHECK:      Section {
15# CHECK-NEXT:   Index: 0
16# CHECK-NEXT:   Name:
17# CHECK-NEXT:   Type: SHT_NULL
18# CHECK-NEXT:   Flags [
19# CHECK-NEXT:   ]
20# CHECK-NEXT:   Address:
21# CHECK-NEXT:   Offset:
22# CHECK-NEXT:   Size: [[#SHNUM:]]
23# CHECK-NEXT:   Link: [[#SHNUM-1]]
24
25## Show that the .symtab_shndx section has the correct properties.
26## To avoid accidentally capturing the index of an unrelated section header for
27## checking the sh_link of the .symtab_shndx section, use the index of the
28## section immediately following the symbol table.
29# CHECK:        Name: .symtab
30# CHECK-NEXT:   Type: SHT_SYMTAB
31# CHECK:        Index: [[#AFTERSYMTAB:]]
32# CHECK:        Name: .symtab_shndx
33# CHECK-NEXT:   Type: SHT_SYMTAB_SHNDX
34# CHECK-NEXT:   Flags [ (0x0)
35# CHECK-NEXT:   ]
36# CHECK-NEXT:   Address: 0x0
37# CHECK-NEXT:   Offset:
38## There should be #syms * EntrySize bytes.
39# CHECK-NEXT:   Size: 262148
40# CHECK-NEXT:   Link: [[#AFTERSYMTAB-1]]
41# CHECK-NEXT:   Info: 0
42# CHECK-NEXT:   AddressAlignment: 4
43# CHECK-NEXT:   EntrySize: 4
44## Show that the sh_link of the first section header is the section header table
45## index. Also show that the last section is the .strtab.
46# CHECK:        Index: [[#SHNUM-1]]
47# CHECK-NEXT:   Name: .strtab
48
49## Show that the symbols with section indexes around the reserved range still
50## have the right section indexes afterwards.
51# CHECK:         Section: s65279 (0xFEFF)
52# CHECK-NEXT:  }
53## st_shndx == SHN_LORSERVE.
54# CHECK-NEXT:  Symbol {
55# CHECK-NEXT:    Name: sym65280 (
56# CHECK-NEXT:    Value: 0x0
57# CHECK-NEXT:    Size: 0
58# CHECK-NEXT:    Binding: Local (0x0)
59# CHECK-NEXT:    Type: None (0x0)
60# CHECK-NEXT:    Other: 0
61# CHECK-NEXT:    Section: s65280 (0xFF00)
62# CHECK-NEXT:  }
63## st_shndx == SHN_ABS.
64# CHECK:         Name: sym65521 (
65# CHECK-NEXT:    Value: 0x0
66# CHECK-NEXT:    Size: 0
67# CHECK-NEXT:    Binding: Local (0x0)
68# CHECK-NEXT:    Type: None (0x0)
69# CHECK-NEXT:    Other: 0
70# CHECK-NEXT:    Section: s65521 (0xFFF1)
71# CHECK-NEXT:  }
72## st_shndx == SHN_COMMON.
73# CHECK-NEXT:  Symbol {
74# CHECK-NEXT:    Name: sym65522 (
75# CHECK-NEXT:    Value: 0x0
76# CHECK-NEXT:    Size: 0
77# CHECK-NEXT:    Binding: Local (0x0)
78# CHECK-NEXT:    Type: None (0x0)
79# CHECK-NEXT:    Other: 0
80# CHECK-NEXT:    Section: s65522 (0xFFF2)
81# CHECK-NEXT:  }
82## st_shndx == SHN_XINDEX.
83# CHECK:         Name: sym65535 (
84# CHECK-NEXT:    Value: 0x0
85# CHECK-NEXT:    Size: 0
86# CHECK-NEXT:    Binding: Local (0x0)
87# CHECK-NEXT:    Type: None (0x0)
88# CHECK-NEXT:    Other: 0
89# CHECK-NEXT:    Section: s65535 (0xFFFF)
90# CHECK-NEXT:  }
91## st_shndx > SHN_XINDEX.
92# CHECK-NEXT:  Symbol {
93# CHECK-NEXT:    Name: sym65536 (
94# CHECK-NEXT:    Value: 0x0
95# CHECK-NEXT:    Size: 0
96# CHECK-NEXT:    Binding: Local (0x0)
97# CHECK-NEXT:    Type: None (0x0)
98# CHECK-NEXT:    Other: 0
99# CHECK-NEXT:    Section: s65536 (0x10000)
100# CHECK-NEXT:  }
101
102# SYMS: Symbol table '.symtab' contains 65537 entries
103