DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Object files

Sections

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 in A``Special section indexes''. 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 specifies how many entries the section header table contains. e_shentsize specifies 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

Special section indexes


``SHN_UNDEF''
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.


NOTE: 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 described later in this section.


``SHN_LORESERVE''
This value specifies the lower bound of the range of reserved indexes.

``SHN_LOPROC'' through ``SHN_HIPROC''
Values in this inclusive range are reserved for processor-specific semantics.

``SHN_LOOS'' through ``SHN_HIOS''
Values in this inclusive range are reserved for operating system-specific semantics.

``SHN_ABS''
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.

``SHN_COMMON''
Symbols defined relative to this section are common symbols, such as FORTRAN COMMON or unallocated C external variables.

``SHN_HIRESERVE''
This value specifies the upper bound 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. 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.

A section header has the following structure.
   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_Word sh_flags; Elf64_Addr sh_addr; Elf64_Off sh_offset; Elf64_Word sh_size; Elf64_Word sh_link; Elf64_Word sh_info; Elf64_Word sh_addralign; Elf64_Word sh_entsize; } Elf64_Shdr;

Section header


sh_name
This member specifies the name of the section. Its value is an index into the section header string table section [See ``String table'' for more information], giving the location of a null-terminated string.

sh_type
This member categorizes the section's contents and semantics. Section types and their descriptions appear in ``Section types, sh_type''.

sh_flags
Sections support 1-bit flags that describe miscellaneous attributes. Flag definitions appear in ``Section types, sh_type''.

sh_addr
If the section will 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.

sh_offset
This member's value gives the byte offset from the beginning of the file to the first byte in the section. One section type, SHT_NOBITS described in ``Section types, sh_type'', occupies no space in the file, and its sh_offset member locates the conceptual placement in the file.

sh_size
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 may have a non-zero size, but it occupies no space in the file.

sh_link
This member holds a section header table index link, whose interpretation depends on the section type. ``Section types, sh_type'' describes the values.

sh_info
This member holds extra information, whose interpretation depends on the section type. ``Section types, sh_type'' describes the values.

sh_addralign
Some sections have address alignment constraints. For example, if a section holds a doubleword, the system must ensure doubleword alignment for the entire section. 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.

sh_entsize
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.

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_LOOS 0x60000000
SHT_HIOS 0x6fffffff
SHT_LOPROC 0x70000000
SHT_HIPROC 0x7fffffff
SHT_LOUSER 0x80000000
SHT_HIUSER 0xffffffff

Section types, sh_type


SHT_NULL
This value marks the section header as inactive; it does not have an associated section. Other members of the section header have undefined values.

SHT_PROGBITS
The section holds information defined by the program, whose format and meaning are determined solely by the program.

SHT_SYMTAB and SHT_DYNSYM
These sections hold a symbol table. Currently, an object file may have only one section of each type, but this restriction may be relaxed in the future. Typically, 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.


NOTE: See ``Symbol table'' for details.


SHT_STRTAB
The section holds a string table. An object file may have multiple string table sections.


NOTE: See ``String table'' for details.


SHT_RELA
The section holds relocation entries with explicit addends, such as type Elf32_Rela for the 32-bit or type Elf64_Rela for the 64-bit class of object files. An object file may have multiple relocation sections.


NOTE: See ``Relocation'' for details.


SHT_HASH
The section holds a symbol hash table. Currently, an object file may have only one hash table, but this restriction may be relaxed in the future. See ``Hash table'' for details.

SHT_DYNAMIC
The section holds information for dynamic linking. Currently, an object file may have only one dynamic section, but this restriction may be relaxed in the future. See ``Dynamic section'' for details.

SHT_NOTE
The section holds information that marks the file in some way. See ``Note section'' for details.

SHT_NOBITS
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.

SHT_REL
The section holds relocation entries without explicit addends, such as type Elf32_Rel for the 32-bit class of object files. An object file may have multiple relocation sections.


NOTE: See ``Relocation'' for details.


SHT_SHLIB
This section type is reserved but has unspecified semantics.

SHT_INIT_ARRAY
This section contains an array of pointers to initialization functions, as described in ``Initialization and termination functions''. Each pointer in the array is taken as a parameterless procedure with a void return.

SHT_FINI_ARRAY
This section contains an array of pointers to termination functions, as described in ``Initialization and termination functions''. Each pointer in the array is taken as a parameterless procedure with a void return.

SHT_PREINIT_ARRAY
This section contains an array of pointers to functions that are invoked before all other initialization functions, as described in ``Initialization and termination functions''. Each pointer in the array is taken as a parameterless procedure with a void return.

SHT_LOOS through SHT_HIOS
Values in this inclusive range are reserved for operating system-specific semantics.

SHT_LOPROC through SHT_HIPROC
Values in this inclusive range are reserved for processor-specific semantics.

SHT_LOUSER
This value specifies the lower bound of the range of indexes reserved for application programs.

SHT_HIUSER
This value specifies the upper bound of the range of indexes reserved for application programs. Section types between 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 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

Section header table entry: Index 0

A section header's sh_flags member holds 1-bit flags that describe the section's attributes. Defined values appear in the table shown below, other values are reserved.

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_MASKOS 0x0ff00000
SHF_MASKPROC 0xf0000000

Section attribute flags, sh_flags

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
The section contains data that should be writable during process execution.

SHF_ALLOC
The 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.

SHF_EXECINSTR
The section contains executable machine instructions.

SHF_MERGE
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.

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_STRINGS
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.

SHF_INFO_LINK
The sh_info field of this section header holds a section header table index.

SHF_LINK_ORDER
This flag adds special ordering requirements for link editors. 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 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.


NOTE: A typical use of this flag is to build a table that references text or data sections in address order.


SHF_OS_NONCONFORMING
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 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_MASKOS
All bits included in this mask are reserved for operating system-specific semantics.

SHF_MASKPROC
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.

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).

sh_link and sh_info interpretation


Next topic: Rules for linking unrecognized sections
Previous topic: Data encoding ELFDATA2MSB

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005