Extended Section Header
There are limitations on the number of sections that can be represented by standard ELF data structures.
The e_shnum
and e_shstrndx
elements of the ELF header are both limited to being able to represent 65535
sections.
In addition, symbol table entries can reference their associated section using the st_shndx
element, which is limited to being able to represent 65279
sections. Although the size of this element could represent 65535
sections, a range of values is reserved for special symbol types, SHN_LORESERVE
(0xff00
) - SHN_HIRESERVE
(0xffff
).
To allow an ELF object to contain more than 65279
sections, a number of special definitions and a special section type are provided. The resultant ELF object is said to contain extended section header information.
In a standard ELF object, the first section header is zero filled. See ELF Symbol Table Entry: Index 0. When the number of sections exceed the ELF header data sizes, elements of section header 0
are used to define extended ELF header attributes. The following table shows the values.
Table 14-9
ELF Extended Section Header Table Entry: Index 0
Name | Value | Note |
---|---|---|
|
|
No name |
|
|
Inactive |
|
|
No flags |
|
|
No address |
|
|
No file offset |
|
|
The number of entries in the section header table |
|
|
The section header index of the entry that is associated with the section name string table |
|
|
The number of entries in the program header table |
|
|
No alignment |
|
|
No entries |
When this section header 0
information is used, the ELF header e_shnum
element is set to 0
, and the e_shstrndx
element is set to SHN_XINDEX
(0xffff
).
For a symbol table to be able to reference more than 65279
sections, an extended section header index table, identified as SHT_SYMTAB_SHNDX
, is created.
The SHT_SYMTAB_SHNDX
section is an array of Elf32_Word
values. Each value corresponds one to one with a symbol table entry and appears in the same order as the symbol table entries. The values represent the section header indexes against which the symbol table entries are defined. Only if the st_shndx
field of a symbol table entry contains the escape value SHN_XINDEX
(0xffff
), does the corresponding SHT_SYMTAB_SHNDX
entry hold the actual section header index. Otherwise, the SHT_SYMTAB_SHNDX
entry must be SHN_UNDEF
(0
).
Should an ELF file require more than 65534
program headers, the sh_info
element of section header 0
is used to define the number of program headers, and the e_phnum
element of the ELF header contains PN_XNUM
(0xffff
).
To aid in the processing of extended section header information, the libelf routines
elf_getphdrnum
(3ELF),
elf_getshdrnum
(3ELF), and
elf_getshdrstrndx
(3ELF) are provided.