An object file's section header table lets one
locate all the file's sections.
The section header table is an array of Elf32_Shdr
or Elf64_Shdr
structures
as described below.
A section header table index is a subscript into this array.
The ELF header's e_shoff
member gives the byte offset from the beginning of the
file to the section header table.
e_shnum
tells how many entries the section header table contains.
e_shentsize
gives the size in bytes of each entry.
Some section header table indexes are reserved; an object file will not have sections for these special indexes.
Name | Value |
---|---|
SHN_UNDEF |
0 |
SHN_LORESERVE |
0xff00 |
SHN_LOPROC |
0xff00 |
SHN_HIPROC |
0xff1f |
SHN_LOOS |
0xff20 |
SHN_HIOS |
0xff3f |
SHN_ABS |
0xfff1 |
SHN_COMMON |
0xfff2 |
SHN_HIRESERVE |
0xffff |
SHN_UNDEF
SHN_UNDEF
is an undefined symbol.
e_shnum
member of the ELF header says a file has 6 entries
in the section header table, they have the indexes 0 through 5.
The contents of the initial entry are specified later in this
section.
SHN_LORESERVE
SHN_LOPROC
through SHN_HIPROC
SHN_LOOS
through SHN_HIOS
SHN_ABS
SHN_ABS
have absolute values and are not affected by relocation.
SHN_COMMON
COMMON
or unallocated C external variables.
SHN_HIRESERVE
SHN_LORESERVE
and SHN_HIRESERVE
,
inclusive; the values do not reference the section header table.
The section header table does not
contain entries for the reserved indexes.
Sections contain all information in an object file except the ELF header, the program header table, and the section header table. Moreover, object files' sections satisfy several conditions.
Figure 4-8: Section Header
typedef struct { Elf32_Word sh_name; Elf32_Word sh_type; Elf32_Word sh_flags; Elf32_Addr sh_addr; Elf32_Off sh_offset; Elf32_Word sh_size; Elf32_Word sh_link; Elf32_Word sh_info; Elf32_Word sh_addralign; Elf32_Word sh_entsize; } Elf32_Shdr; typedef struct { Elf64_Word sh_name; Elf64_Word sh_type; Elf64_Xword sh_flags; Elf64_Addr sh_addr; Elf64_Off sh_offset; Elf64_Xword sh_size; Elf64_Word sh_link; Elf64_Word sh_info; Elf64_Xword sh_addralign; Elf64_Xword sh_entsize; } Elf64_Shdr;
sh_name
sh_type
sh_flags
sh_addr
sh_offset
SHT_NOBITS
described
below,
occupies no space in the file, and its
sh_offset
member locates the conceptual placement in the file.
sh_size
SHT_NOBITS
, the section occupies sh_size
bytes in the file.
A section of type SHT_NOBITS
may have a non-zero size, but it occupies no space in the file.
sh_link
sh_info
sh_addralign
sh_addr
must be congruent to 0, modulo the value of sh_addralign
.
Currently, only 0 and positive integral powers of two are allowed.
Values 0 and 1 mean the section has no alignment constraints.
sh_entsize
A section header's sh_type
member specifies the section's semantics.
sh_type
Name | Value |
---|---|
SHT_NULL |
0 |
SHT_PROGBITS |
1 |
SHT_SYMTAB |
2 |
SHT_STRTAB |
3 |
SHT_RELA |
4 |
SHT_HASH |
5 |
SHT_DYNAMIC |
6 |
SHT_NOTE |
7 |
SHT_NOBITS |
8 |
SHT_REL |
9 |
SHT_SHLIB |
10 |
SHT_DYNSYM |
11 |
SHT_LOOS |
0x60000000 |
SHT_HIOS |
0x6fffffff |
SHT_LOPROC |
0x70000000 |
SHT_HIPROC |
0x7fffffff |
SHT_LOUSER |
0x80000000 |
SHT_HIUSER |
0xffffffff |
SHT_NULL
SHT_PROGBITS
SHT_SYMTAB
and SHT_DYNSYM
SHT_SYMTAB
provides symbols for link editing, though it may also be
used for dynamic linking.
As a complete symbol table, it may contain many symbols unnecessary
for dynamic linking.
Consequently, an object file may also contain a SHT_DYNSYM
section, which holds a minimal set of dynamic linking symbols,
to save space.
See ``Symbol Table'' below
for details.
SHT_STRTAB
SHT_RELA
Elf32_Rela
for the 32-bit class of object files
or type Elf64_Rela
for the 64-bit class of object files.
An object file may have multiple relocation sections.
``Relocation''
below for details.
SHT_HASH
SHT_DYNAMIC
SHT_NOTE
SHT_NOBITS
SHT_PROGBITS
.
Although this section contains no bytes, the sh_offset
member contains the conceptual file offset.
SHT_REL
Elf32_Rel
for the 32-bit class of object files or
type Elf64_Rel
for the 64-bit class of object files.
An object file may have multiple relocation sections.
See ``Relocation''
below for details.
SHT_SHLIB
SHT_LOOS
through SHT_HIOS
SHT_LOPROC
through SHT_HIPROC
SHT_LOUSER
SHT_HIUSER
SHT_LOUSER
and
SHT_HIUSER
may be used by the application, without conflicting with
current or future system-defined section types.
Other section type values are reserved.
As mentioned before, the section header for index 0 (SHN_UNDEF
)
exists, even though the index marks undefined section references.
This entry holds the following.
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 offset |
sh_size |
0 |
No size |
sh_link |
SHN_UNDEF |
No link information |
sh_info |
0 |
No auxiliary information |
sh_addralign |
0 |
No alignment |
sh_entsize |
0 |
No entries |
A section header's sh_flags
member holds 1-bit flags that describe the section's attributes.
Defined values appear in the following table;
other values are reserved.
Name | Value |
---|---|
SHF_WRITE |
0x1 |
SHF_ALLOC |
0x2 |
SHF_EXECINSTR |
0x4 |
SHF_MASKOS |
0x0f000000 |
SHF_MASKPROC |
0xf0000000 |
If a flag bit is set in sh_flags
,
the attribute is ``on'' for the section.
Otherwise, the attribute is ``off'' or does not apply.
Undefined attributes are set to zero.
SHF_WRITE
SHF_ALLOC
SHF_EXECINSTR
SHF_MASKOS
SHF_MASKPROC
Two members in the section header,
sh_link
and sh_info
,
hold special information, depending on section type.
sh_link
and sh_info
Interpretation
sh_type |
sh_link |
sh_info |
---|---|---|
SHT_DYNAMIC |
The section header index of the string table used by entries in the section. | 0 |
SHT_HASH |
The section header index of the symbol table to which the hash table applies. | 0 |
SHT_REL SHT_RELA |
The section header index of the associated symbol table. | The section header index of the section to which the relocation applies. |
SHT_SYMTAB SHT_DYNSYM |
The section header index of the associated string table. | One greater than the symbol table index of the last local
symbol (binding STB_LOCAL ). |
The following table shows sections that are used by the system and have the indicated types and attributes.
Name | Type | Attributes |
---|---|---|
.bss |
SHT_NOBITS |
SHF_ALLOC+SHF_WRITE |
.comment |
SHT_PROGBITS |
none |
.data |
SHT_PROGBITS |
SHF_ALLOC+SHF_WRITE |
.data1 |
SHT_PROGBITS |
SHF_ALLOC+SHF_WRITE |
.debug |
SHT_PROGBITS |
none |
.dynamic |
SHT_DYNAMIC |
see below |
.dynstr |
SHT_STRTAB |
SHF_ALLOC |
.dynsym |
SHT_DYNSYM |
SHF_ALLOC |
.fini |
SHT_PROGBITS |
SHF_ALLOC+SHF_EXECINSTR |
.got |
SHT_PROGBITS |
see below |
.hash |
SHT_HASH |
SHF_ALLOC |
.init |
SHT_PROGBITS |
SHF_ALLOC+SHF_EXECINSTR |
.interp |
SHT_PROGBITS |
see below |
.line |
SHT_PROGBITS |
none |
.note |
SHT_NOTE |
none |
.plt |
SHT_PROGBITS |
see below |
.rel name |
SHT_REL |
see below |
.rela name |
SHT_RELA |
see below |
.rodata |
SHT_PROGBITS |
SHF_ALLOC |
.rodata1 |
SHT_PROGBITS |
SHF_ALLOC |
.shstrtab |
SHT_STRTAB |
none |
.strtab |
SHT_STRTAB |
see below |
.symtab |
SHT_SYMTAB |
see below |
.text |
SHT_PROGBITS |
SHF_ALLOC+SHF_EXECINSTR |
.bss
SHT_NOBITS
.
.comment
.data
and .data1
.debug
.debug
are reserved for future use in the
ABI.
.dynamic
SHF_ALLOC
bit.
Whether the SHF_WRITE
bit is set is processor specific.
See Chapter 5 for more information.
.dynstr
.dynsym
.fini
.got
.hash
.init
main
for C programs).
.interp
SHF_ALLOC
bit; otherwise, that bit will be off.
See Chapter 5 for more information.
.line
.note
.plt
.rel
name and .rela
nameSHF_ALLOC
bit; otherwise, that bit will be off.
Conventionally, name
is supplied by the section to which the relocations apply.
Thus a relocation section for .text
normally would have the name .rel.text
or .rela.text
.
.rodata
and .rodata1
.shstrtab
.strtab
SHF_ALLOC
bit; otherwise, that bit will be off.
.symtab
SHF_ALLOC
bit; otherwise, that bit will be off.
.text
Section names with a dot (.
) prefix
are reserved for the system,
although applications may use these sections
if their existing meanings are satisfactory.
Applications may use names without the prefix to
avoid conflicts with system sections.
The object file format lets one define sections not
shown in the previous list.
An object file may have more than one section
with the same name.
Section names reserved for a processor architecture
are formed by placing an abbreviation of the architecture
name ahead of the section name.
The name should be taken from the
architecture names used for e_machine
.
For instance .
FOO.psect
is the psect
section defined by the FOO architecture.
Existing extensions are called by their historical names.
.sdata |
.tdesc |
.sbss |
.lit4 |
.lit8 |
.reginfo |
.gptab |
.liblist |
.conflict |