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

sh_name

0

No name

sh_type

SHT_NULL

Inactive

sh_flags

0

No flags

sh_addr

0

No address

sh_offset

0

No file offset

sh_size

e_shnum

The number of entries in the section header table

sh_link

e_shstrndx

The section header index of the entry that is associated with the section name string table

sh_info

e_phnum

The number of entries in the program header table

sh_addralign

0

No alignment

sh_entsize

0

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.