An object file's section header table helps you locate all 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 does not have sections for these special indexes.
Table 7-11 Special Section Indexes
Name |
Value |
---|---|
SHN_UNDEF |
0 |
SHN_LORESERVE |
0xff00 |
SHN_LOPROC |
0xff00 |
SHN_BEFORE |
0xff00 |
SHN_AFTER |
0xff01 |
SHN_HIPROC |
0xff1f |
SHN_ABS |
0xfff1 |
SHN_COMMON |
0xfff2 |
SHN_HIRESERVE |
0xffff |
This value marks an undefined, missing, irrelevant, or otherwise meaningless section reference. For example, a symbol defined relative to section number SHN_UNDEF is an undefined symbol.
Although index 0 is reserved as the undefined value, the section header table contains an entry for index 0. That is, 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.
This value specifies the lower boundary of the range of reserved indexes.
Values in this inclusive range are reserved for processor-specific semantics.
These values provide for initial and final section ordering in conjunction with the SHF_LINK_ORDER and SHF_ORDERED section flags (see Table 7-14).
This value specifies absolute values for the corresponding reference. For example, symbols defined relative to section number SHN_ABS have absolute values and are not affected by relocation.
Symbols defined relative to this section are common symbols, such as FORTRAN COMMON or unallocated C external variables. These symbols are sometimes referred to as tentative.
This value specifies the upper boundary of the range of reserved indexes. The system reserves indexes between SHN_LORESERVE and SHN_HIRESERVE, inclusive; the values do not reference the section header table. That is, 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:
Every section in an object file has exactly one section header describing it. Section headers can exist that do not have a section.
Each section occupies one contiguous (possibly empty) sequence of bytes within a file.
Sections in a file can not overlap. No byte in a file resides in more than one section.
An object file can have inactive space. The various headers and the sections might not cover every byte in an object file. The contents of the inactive data are unspecified.
A section header has the following structure (defined in sys/elf.h):
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; |
This member specifies the name of the section. Its value is an index into the section header string table section (see "String Table") giving the location of a null-terminated string. Section names and their descriptions are in Table 7-17.
This member categorizes the section's contents and semantics. Section types and their descriptions are in Table 7-12.
Sections support 1-bit flags that describe miscellaneous attributes. Flag definitions are in Table 7-14.
If the section is to appear in the memory image of a process, this member gives the address at which the section's first byte should reside. Otherwise, the member contains 0.
This member gives the byte offset from the beginning of the file to the first byte in the section. Section type SHT_NOBITS, described below, occupies no space in the file, and its sh_offset member locates the conceptual placement in the file.
This member gives the section's size in bytes. Unless the section type is SHT_NOBITS, the section occupies sh_size bytes in the file. A section of type SHT_NOBITS can have a nonzero size, but it occupies no space in the file.
This member holds a section header table index link, whose interpretation depends on the section type. Table 7-15 describes the values.
This member holds extra information, whose interpretation depends on the section type. Table 7-15 describes the values.
Some sections have address alignment constraints. For example, if a section holds a double-word, the system must ensure double-word alignment for the entire section. That is, the value of 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.
Some sections hold a table of fixed-size entries, such as a symbol table. For such a section, this member gives the size in bytes of each entry. The member contains 0 if the section does not hold a table of fixed-size entries.
A section header's sh_type member specifies the section's semantics, as shown in the following table.
Table 7-12 Section Types, 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_SUNW_move |
0x6ffffffa |
SHT_SUNW_COMDAT |
0x6ffffffb |
SHT_SUNW_syminfo |
0x6ffffffc |
SHT_SUNW_verdef |
0x6ffffffd |
SHT_SUNW_verneed |
0x6ffffffe |
SHT_SUNW_versym |
0x6fffffff |
SHT_LOPROC |
0x70000000 |
SHT_HIPROC |
0x7fffffff |
SHT_LOUSER |
0x80000000 |
SHT_HIUSER |
0xffffffff |
This value marks the section header as inactive; it does not have an associated section. Other members of the section header have undefined values.
This section holds information defined by the program, whose format and meaning are determined solely by the program.
These sections hold a symbol table. Typically a SHT_SYMTAB section provides symbols for link-editing. As a complete symbol table, it can contain many symbols unnecessary for dynamic linking. Consequently, an object file can also contain a SHT_DYNSYM section, which holds a minimal set of dynamic linking symbols, to save space. See "Symbol Table" for details.
These sections hold a string table. An object file can have multiple string table sections. See "String Table" for details.
This section holds relocation entries with explicit addends, such as type Elf32_Rela for the 32-bit class of object files. An object file can have multiple relocation sections. See "Relocation" for details.
This section holds a symbol hash table. All dynamically linked object files must contain a symbol hash table. Currently, an object file can have only one hash table, but this restriction might be relaxed in the future. See "Hash Table" for details.
This section holds information for dynamic linking. Currently, an object file can have only one dynamic section, but this restriction might be relaxed in the future. See "Dynamic Section" for details.
This section holds information that marks the file in some way. See "Note Section" for details.
A section of this type occupies no space in the file but otherwise resembles SHT_PROGBITS. Although this section contains no bytes, the sh_offset member contains the conceptual file offset.
This section holds relocation entries without explicit addends, such as type Elf32_Rel for the 32-bit class of object files. An object file can have multiple relocation sections. See "Relocation" for details.
This section type is reserved but has unspecified semantics. Programs that contain a section of this type do not conform to the ABI.
This section contains data to handle partially initialized symbols. See "Comdat Section" for details.
This section contains data to handle partially initialized symbols. See "Move Section" for details.
This section contains a table which contains additional symbol information.See "Syminfo Table" for details.
The section contains definitions of fine-grained versions defined by this file. See "Version Definition Section" for details.
This section contains descriptions of fine-grained dependencies required for the execution of an image. See "Version Dependency Section" for details.
This section contains a table describing the relationship of symbols to the version definitions offered by the file. See "Version Symbol Section" for details.
Values in this inclusive range are reserved for processor-specific semantics.
This value specifies the lower boundary of the range of indexes reserved for application programs.
This value specifies the upper boundary of the range of indexes reserved for application programs. Section types between SHT_LOUSER and SHT_HIUSER can 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. The following table shows the values.
Table 7-13 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 |
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:
Table 7-14 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_ORDERED |
0x40000000 |
SHF_EXCLUDE |
0x80000000 |
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 reserved and set to zero.
This section contains data that should be writable during process execution.
This section occupies memory during process execution. Some control sections do not reside in the memory image of an object file; this attribute is off for those sections.
This section contains executable machine instructions.
The data in the section may be merged to eliminate duplication. Unless the SHF_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.
The data elements in the section consist of null-terminated character strings. The size of each character is specified in the section header's sh_entsize field.
The sh_info field of this section header holds a section header table index.
This flag adds special ordering requirements to the link-editor. The requirements apply if the sh_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 will 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.
The special sh_info values SHN_BEFORE and SHN_AFTER (see Table 7-11) imply that the sorted section is to precede or follow, respectively, all other sections in the set being ordered. Input file link-line order is preserved if multiple sections in an ordered set have one of these special values.
A typical use of this flag is to build a table that references text or data sections in address order.
This section requires special OS-specific processing (beyond the standard linking rules) to avoid incorrect behavior. If this section has either an sh_type value or contains sh_flags bits in the OS-specific ranges for those fields, and the link-editor does not recognize these values, then the link-editor will reject the object file containing this section with an error.
This section is a member (perhaps the only one) of a section group. The section must be referenced by a section of type SHT_GROUP. The SHF_GROUP flag can be set only for sections contained in relocatable objects (objects with the ELF header e_type member set to ET_REL). See "Section Groups" for further details.
All bits included in this mask are reserved for operating system-specific semantics.
This section requires ordering in relation to other sections of the same type. Ordered sections are combined within the section pointed to by the sh_link entry. The sh_link entry of an ordered section can point to itself.
If the sh_info entry of the ordered section is a valid section within the same input file, the ordered section will be sorted based on the relative ordering within the output file of the section pointed to by the sh_info entry.
The special sh_info values SHN_BEFORE and SHN_AFTER (see Table 7-11) imply that the sorted section is to precede or follow, respectively, all other sections in the set being ordered. Input file link-line order is preserved if multiple sections in an ordered set have one of these special values.
In the absence of the sh_info ordering information, sections from a single input file combined within one section of the output file will be contiguous and have the same relative ordering as they did in the input file. The contributions from multiple input files will appear in link-line order.
This section is excluded from input to the link-edit of an executable or shared object. This flag is ignored if the SHF_ALLOC flag is also set, or if relocations exist against the section.
All bits included in this mask are reserved for processor-specific semantics.
Two members in the section header, sh_link and sh_info, hold special information, depending on section type.
Table 7-15 sh_link and sh_info Interpretation
sh_type |
sh_link |
sh_info |
---|---|---|
SHT_DYNAMIC |
The section header index of the associated string table |
0 |
SHT_HASH |
The section header index of the associated symbol table |
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. See also Table 7-17 |
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) |
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_SUNW_move |
The section header index of the associated symbol table |
0 |
SHT_SUNW_COMDAT |
0 |
0 |
SHT_SUNW_syminfo |
The section header index of the associated symbol table |
The section header index of the associated .dynamic section |
SHT_SUNW_verdef |
The section header index of the associated string table |
The number of version definitions within the section |
SHT_SUNW_verneed |
The section header index of the associated string table |
The number of version dependencies within the section |
SHT_SUNW_versym |
The section header index of the associated symbol table |
0 |