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 normally tells how many entries the section header table contains.
e_shentsize gives the size in bytes of each entry.
If the number of sections is greater than or equal to
SHN_LORESERVE (0xff00), e_shnum
has the value SHN_UNDEF (0) and the
actual number of section header table
entries is contained in the sh_size field of
the section header at index 0
(otherwise, the sh_size member of the initial entry
contains 0).
Some section header table indexes are reserved in contexts
where index size is restricted, for example, the st_shndx
member of a symbol table entry and the e_shnum and
e_shstrndx members of the ELF header.
In such contexts, the reserved values do not represent actual
sections in the object file. Also in such contexts, an escape
value indicates that the actual section
index is to be found elsewhere, in a larger field.
| 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_XINDEX |
0xffff |
SHN_HIRESERVE |
0xffff |
SHN_UNDEFSHN_UNDEF is an undefined symbol.
Although index 0 is reserved as the undefined value,
the section header table contains an entry for index 0.
If the 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_LORESERVESHN_LOPROC through SHN_HIPROCSHN_LOOS through SHN_HIOSSHN_ABSSHN_ABS
have absolute values and are not affected by relocation.
SHN_COMMONCOMMON
or unallocated C external variables.
SHN_XINDEXSHN_HIRESERVESHN_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_namesh_type
sh_flags
sh_addrsh_offsetSHT_NOBITS
described
below,
occupies no space in the file, and its
sh_offset member locates the conceptual placement in the file.
sh_sizeSHT_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_linksh_infosh_flags field for this
section header includes the attribute SHF_INFO_LINK, then this member represents a section header table index.
sh_addralignsh_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_INIT_ARRAY |
14 |
SHT_FINI_ARRAY |
15 |
SHT_PREINIT_ARRAY |
16 |
SHT_GROUP |
17 |
SHT_SYMTAB_SHNDX |
18 |
SHT_LOOS |
0x60000000 |
SHT_HIOS |
0x6fffffff |
SHT_LOPROC |
0x70000000 |
SHT_HIPROC |
0x7fffffff |
SHT_LOUSER |
0x80000000 |
SHT_HIUSER |
0xffffffff |
SHT_NULLSHT_PROGBITSSHT_SYMTAB and SHT_DYNSYMSHT_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_STRTABSHT_RELAElf32_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_HASHSHT_DYNAMICSHT_NOTESHT_NOBITSSHT_PROGBITS.
Although this section contains no bytes, the sh_offset
member contains the conceptual file offset.
SHT_RELElf32_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_SHLIBSHT_INIT_ARRAYSHT_FINI_ARRAYSHT_PREINIT_ARRAYSHT_GROUPSHT_GROUP may appear only
in relocatable objects (objects with the ELF header e_type
member set to ET_REL). The section header table entry
for a group section must appear in the section header table
before the entries for any of the sections that are members of
the group.
SHT_SYMTAB_SHNDXSHT_SYMTAB
and is required if any of the section header indexes referenced
by that symbol table contain the escape value SHN_XINDEX.
The section is an array of Elf32_Word values.
Each value corresponds one to one with a symbol table entry
and appear in the same order as those entries. The values represent
the section header indexes against which the symbol table entries
are defined. All of the values in this section must be valid
section header indexes whether or not the st_shndx
field in the corresponding symbol table entry contains the special
escape code SHN_XINDEX.
SHT_LOOS through SHT_HIOSSHT_LOPROC through SHT_HIPROCSHT_LOUSERSHT_HIUSERSHT_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 |
Unspecified | If non-zero, the actual number of section header entries |
sh_link |
Unspecified | If non-zero, the index of the section header string table section |
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.
Figure 4-11: Section Attribute Flags
| Name | Value |
|---|---|
SHF_WRITE |
0x1 |
SHF_ALLOC |
0x2 |
SHF_EXECINSTR |
0x4 |
SHF_MERGE |
0x10 |
SHF_STRINGS |
0x20 |
SHF_INFO_LINK |
0x40 |
SHF_LINK_ORDER |
0x80 |
SHF_OS_NONCONFORMING |
0x100 |
SHF_GROUP |
0x200 |
SHF_MASKOS |
0x0ff00000 |
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_WRITESHF_ALLOCSHF_EXECINSTRSHF_MERGESHF_STRINGS flag is also set,
the data elements in the section are of a uniform size.
The size of each element is specified in the section
header's sh_entsize field.
If the SHF_STRINGS flag is also set,
the data elements consist of null-terminated character strings.
The size of each character is specified in the section
header's sh_entsize field.
Each element in the section is compared against other elements in sections with the same name, type and flags. Elements that would have identical values at program run-time may be merged. Relocations referencing elements of such sections must be resolved to the merged locations of the referenced values. Note that any relocatable values, including values that would result in run-time relocations, must be analyzed to determine whether the run-time values would actually be identical. An ABI-conforming object file may not depend on specific elements being merged, and an ABI-conforming link editor may choose not to merge specific elements.
SHF_STRINGSsh_entsize field.
SHF_INFO_LINKsh_info field of this section header holds a section
header table index.
SHF_LINK_ORDERsh_link field of this section's header references
another section (the linked-to section).
If this section is combined with other
sections in the output file, it must appear in the same
relative order with respect to those sections, as the linked-to section
appears with respect to sections the linked-to section is combined with.
A typical use of this flag is to build a table that references text or
data sections in address order.
SHF_OS_NONCONFORMINGsh_type value
or contains sh_flags bits in the OS-specific ranges for
those fields, and a link editor processing this section does not
recognize those values, then the link editor should reject
the object file containing this section with an error.
SHF_GROUPSHT_GROUP.
The SHF_GROUP flag may be set only for sections contained
in relocatable objects (objects with the ELF header e_type
member set to ET_REL).
See below for further details.
SHF_MASKOSSHF_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_RELSHT_RELA |
The section header index of the associated symbol table. | The section header index of the section to which the relocation applies. |
SHT_SYMTABSHT_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). |
SHT_GROUP |
The section header index of the associated symbol table. | The symbol table index of an entry in the associated symbol table. The name of the specified symbol table entry provides a signature for the section group. | SHT_SYMTAB_SHNDX |
The section header index of the associated symbol table section. | 0 |
sh_type
or sh_flags fields, the link editor should combine those
sections as described below.
If the section's sh_flags bits include the attribute
SHF_OS_NONCONFORMING, then the section requires
special knowledge to be correctly processed, and the link editor should
reject the object containing the section with an error.
Unrecognized sections that do not have the
SHF_OS_NONCONFORMING attribute, are combined in a two-phase
process. As the link editor combines sections using this process,
it must honor the alignment constraints of the
input sections (asserted by the sh_addralign field),
padding between sections with zero bytes, if necessary, and producing
a combination with the maximum alignment constraint of its
component input sections.
SHF_MERGE
and SHF_LINK_ORDER). When not otherwise constrained,
sections should be emitted in input order.
Non OS-specific processing (e.g. relocation) should be applied to unrecognized section types. An output section header table, if present, should contain entries for unknown sections. Any unrecognized section attribute flags should be removed.
It is recommended that link editors follow the same two-phase
ordering approach described above when linking sections of
known types. Padding between such sections may have values
different from zero, where appropriate.
A section of type SHT_GROUP defines such a grouping
of sections. The name of a symbol from one of the containing
object's symbol tables provides a signature for the section group.
The section header of the SHT_GROUP section specifies
the identifying symbol entry, as described above:
the sh_link member contains the section header index
of the symbol table section that contains the entry.
The sh_info member contains the symbol table index of
the identifying entry. The sh_flags
member of the section header contains 0.
The name of the section (sh_name) is not specified.
The section data of a SHT_GROUP section is an array
of Elf32_Word entries. The first entry is a flag word.
The remaining entries are a sequence of section header indices.
The following flags are currently defined:
| Name | Value |
|---|---|
GRP_COMDAT |
0x1 |
GRP_COMDAT
The section header indices in the SHT_GROUP section
identify the sections that make up the group. Each such section
must have the SHF_GROUP flag set in its sh_flags
section header member. If the linker decides to remove the section
group, it must remove all members of the group.
This requirement is not intended to imply that special case behavior
like removing debugging information requires removing the sections
to which that information refers, even if they are part of the same
group.
To facilitate removing a group without leaving dangling references and with only minimal processing of the symbol table, the following rules must be followed:
STB_GLOBAL or STB_WEAK
binding and section index SHN_UNDEF.
If there is a definition of the same
symbol in the object containing the references, it must
have a separate symbol table entry from the references.
Sections outside of the group may not reference symbols
with STB_LOCAL binding for addresses contained
in the group's sections, including symbols with type STT_SECTION.
sh_link or
sh_info member.
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 |
.fini_array |
SHT_FINI_ARRAY |
SHF_ALLOC+SHF_WRITE |
.got |
SHT_PROGBITS |
see below |
.hash |
SHT_HASH |
SHF_ALLOC |
.init |
SHT_PROGBITS |
SHF_ALLOC+SHF_EXECINSTR |
.init_array |
SHT_INIT_ARRAY |
SHF_ALLOC+SHF_WRITE |
.interp |
SHT_PROGBITS |
see below |
.line |
SHT_PROGBITS |
none |
.note |
SHT_NOTE |
none |
.plt |
SHT_PROGBITS |
see below |
.preinit_array |
SHT_PREINIT_ARRAY |
SHF_ALLOC+SHF_WRITE |
.relname |
SHT_REL |
see below |
.relaname |
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 |
.symtab_shndx |
SHT_SYMTAB_SHNDX |
see below |
.text |
SHT_PROGBITS |
SHF_ALLOC+SHF_EXECINSTR |
.bssSHT_NOBITS.
.comment.data and .data1.debug.debug are reserved for future use in the
ABI.
.dynamicSHF_ALLOC bit.
Whether the SHF_WRITE bit is set is processor specific.
See Chapter 5 for more information.
.dynstr.dynsym.fini.fini_array.got.hash.initmain for C programs).
.init_array.interpSHF_ALLOC bit; otherwise, that bit will be off.
See Chapter 5 for more information.
.line.note.plt.preinit_array.relname and .relanameSHF_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.strtabSHF_ALLOC
bit; otherwise, that bit will be off.
.symtabSHF_ALLOC bit; otherwise, that bit will be off.
.symtab_shndxSHF_ALLOC bit if the associated symbol table
section does; 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 |
For information on processor-specific sections,
see the ABI supplement for the desired processor.