As indicated, object files participate in both program linking and program execution. For convenience and efficiency, the object file format provides parallel views of a file's contents, reflecting the differing needs of these activities. Figure 7-1 shows an object file's organization.
An ELF header resides at the beginning of an object file and holds a road map describing the file's organization.
Sections represent the smallest indivisible units that can be processed within an ELF file. Segments are a collection of sections that represent the smallest individual units that can be mapped to a memory image by exec(2) or by the runtime linker.
Sections hold the bulk of object file information for the linking view: instructions, data, symbol table, relocation information, and so on. Descriptions of sections appear in the first part of this chapter. The second part of this chapter discusses segments and the program execution view of the file.
A program header table, if present, tells the system how to create a process image. Files used to build a process image (executables and shared objects) must have a program header table; relocatable objects do not need one.
A section header table contains information describing the file's sections. Every section has an entry in the table; each entry gives information such as the section name, the section size, and so forth. Files used in link-editing must have a section header table; other object files might or might not have one.
Although the figure shows the program header table immediately after the ELF header, and the section header table following the sections, actual files can differ. Moreover, sections and segments have no specified order. Only the ELF header has a fixed position in the file.
As described here, the object file format supports various processors with 8-bit bytes, 32-bit and 64-bit architectures. Nevertheless, it is intended to be extensible to larger (or smaller) architectures.
Object files therefore represent some control data with a machine-independent format, making it possible to identify object files and interpret their contents in a common way. Remaining data in an object file use the encoding of the target processor, regardless of the machine on which the file was created.
Table 7-1 32-Bit Data Types
Name |
Size |
Alignment |
Purpose |
---|---|---|---|
Elf32_Addr |
4 |
4 |
Unsigned program address |
Elf32_Half |
2 |
2 |
Unsigned medium integer |
Elf32_Off |
4 |
4 |
Unsigned file offset |
Elf32_Sword |
4 |
4 |
Signed integer |
Elf32_Word |
4 |
4 |
Unsigned integer |
unsigned char |
1 |
1 |
Unsigned small integer |
Table 7-2 64-Bit Data Types
Name |
Size |
Alignment |
Purpose |
---|---|---|---|
Elf64_Addr |
8 |
8 |
Unsigned program address |
Elf64_Half |
2 |
2 |
Unsigned medium integer |
Elf64_Off |
8 |
8 |
Unsigned file offset |
Elf64_Sword |
4 |
4 |
Signed integer |
Elf64_Word |
4 |
4 |
Unsigned integer |
Elf64_Xword |
8 |
8 |
Unsigned long integer |
Elf64_Sxword |
8 |
8 |
Signed long integer |
unsigned char |
1 |
1 |
Unsigned small integer |
All data structures that the object file format defines follow the natural size and alignment guidelines for the relevant class. If necessary, data structures contain explicit padding to ensure 4-byte alignment for 4-byte objects, to force structure sizes to a multiple of 4, and so forth. Data also have suitable alignment from the beginning of the file. Thus, for example, a structure containing an Elf32_Addr member will be aligned on a 4-byte boundary within the file, and a structure containing an Elf64_Addr member will be aligned on an 8-byte boundary.
For portability, ELF uses no bit-fields.
Some object file control structures can grow, because the ELF header contains their actual sizes. If the object file format changes, a program can encounter control structures that are larger or smaller than expected. Programs might therefore ignore extra information. The treatment of missing information depends on context and will be specified if and when extensions are defined.
The ELF header has the following structure (defined in sys/elf.h):
#define EI_NIDENT 16 typedef struct { unsigned char e_ident[EI_NIDENT]; Elf32_Half e_type; Elf32_Half e_machine; Elf32_Word e_version; Elf32_Addr e_entry; Elf32_Off e_phoff; Elf32_Off e_shoff; Elf32_Word e_flags; Elf32_Half e_ehsize; Elf32_Half e_phentsize; Elf32_Half e_phnum; Elf32_Half e_shentsize; Elf32_Half e_shnum; Elf32_Half e_shstrndx; } Elf32_Ehdr; typedef struct { unsigned char e_ident[EI_NIDENT]; Elf64_Half e_type; Elf64_Half e_machine; Elf64_Word e_version; Elf64_Addr e_entry; Elf64_Off e_phoff; Elf64_Off e_shoff; Elf64_Word e_flags; Elf64_Half e_ehsize; Elf64_Half e_phentsize; Elf64_Half e_phnum; Elf64_Half e_shentsize; Elf64_Half e_shnum; Elf64_Half e_shstrndx; } Elf64_Ehdr; |
The initial bytes mark the file as an object file and provide machine-independent data with which to decode and interpret the file's contents. Complete descriptions appear in "ELF Identification".
This member identifies the object file type.
Name |
Value |
Meaning |
---|---|---|
ET_NONE |
0 |
No file type |
ET_REL |
1 |
Relocatable file |
ET_EXEC |
2 |
Executable file |
ET_DYN |
3 |
Shared object file |
ET_CORE |
4 |
Core file |
ET_LOPROC |
0xff00 |
Processor-specific |
ET_HIPROC |
0xffff |
Processor-specific |
Although the core file contents are unspecified, type ET_CORE is reserved to mark the file. Values from ET_LOPROC through ET_HIPROC (inclusive) are reserved for processor-specific semantics. Other values are reserved and will be assigned to new object file types as necessary.
This member's value specifies the required architecture for an individual file.
Name |
Value |
Meaning |
---|---|---|
EM_NONE |
0 |
No machine |
EM_M32 |
1 |
AT&T WE 32100 |
EM_SPARC |
2 |
SPARC |
EM_386 |
3 |
Intel 80386 |
EM_68K |
4 |
Motorola 68000 |
EM_88K |
5 |
Motorola 88000 |
EM_486 |
6 |
Intel 80486 |
EM_860 |
7 |
Intel 80860 |
EM_MIPS |
8 |
MIPS RS3000 Big-Endian |
EM_MIPS_RS3_LE |
10 |
MIPS RS3000 Little-Endian |
EM_RS6000 |
11 |
RS6000 |
EM_PA_RISC |
15 |
PA-RISC |
EM_nCUBE |
16 |
nCUBE |
EM_VPP500 |
17 |
Fujitsu VPP500 |
EM_SPARC32PLUS |
18 |
Sun SPARC 32+ |
EM_PPC |
20 |
PowerPC |
EM_SPARCV9 |
43 |
SPARC V9 |
Other values are reserved and will be assigned to new machines as necessary. Processor-specific ELF names use the machine name to distinguish them. For example, the flags mentioned below use the prefix EF_; a flag named WIDGET for the EM_XYZ machine would be called EF_XYZ_WIDGET.
This member identifies the object file version.
Name |
Value |
Meaning |
---|---|---|
EV_NONE |
0 |
Invalid version |
EV_CURRENT |
>=1 |
Current version |
The value 1 signifies the original file format; extensions will create new versions with higher numbers. The value of EV_CURRENT changes as necessary to reflect the current version number.
This member gives the virtual address to which the system first transfers control, thus starting the process. If the file has no associated entry point, this member holds zero.
This member holds the program header table's file offset in bytes. If the file has no program header table, this member holds zero.
This member holds the section header table's file offset in bytes. If the file has no section header table, this member holds zero.
This member holds processor-specific flags associated with the file. Flag names take the form EF_machine_flag. This member is presently zero for SPARC and IA.
Table 7-6 64-bit SPARC: ELF Flags
Name |
Value |
Meaning |
---|---|---|
EF_SPARCV9_MM |
0x3 |
Mask for Memory Model |
EF_SPARCV9_TSO |
0x0 |
Total Store Ordering |
EF_SPARCV9_PSO |
0x1 |
Partial Store Ordering |
EF_SPARCV9_RMO |
0x2 |
Relaxed Memory Ordering |
EF_SPARC_EXT_MASK |
0xffff00 |
Vendor Extension mask |
EF_SPARC_SUN_US1 |
0x000200 |
Sun UltraSPARC 1 Extensions |
EF_SPARC_HAL_R1 |
0x000400 |
HAL R1 Extensions |
EF_SPARC_SUN_US3 |
0x000800 |
Sun UltraSPARC 3 Extensions |
This member holds the ELF header's size in bytes.
This member holds the size in bytes of one entry in the file's program header table; all entries are the same size.
This member holds the number of entries in the program header table. Thus the product of e_phentsize and e_phnum gives the table's size in bytes. If a file has no program header table, e_phnum holds the value zero.
This member holds a section header's size in bytes. A section header is one entry in the section header table; all entries are the same size.
This member holds the number of entries in the section header table. Thus the product of e_shentsize and e_shnum gives the section header table's size in bytes. If a file has no section header table, e_shnum holds the value zero.
This member holds the section header table index of the entry associated with the section name string table. If the file has no section name string table, this member holds the value SHN_UNDEF. See "Sections" and "String Table" for more information.
As mentioned above, ELF provides an object file framework to support multiple processors, multiple data encoding, and multiple classes of machines. To support this object file family, the initial bytes of the file specify how to interpret the file, independent of the processor on which the inquiry is made and independent of the file's remaining contents.
The initial bytes of an ELF header (and an object file) correspond to the e_ident member.
Table 7-7 e_ident[ ] Identification Index
Name |
Value |
Purpose |
---|---|---|
EI_MAG0 |
0 |
File identification |
EI_MAG1 |
1 |
File identification |
EI_MAG2 |
2 |
File identification |
EI_MAG3 |
3 |
File identification |
EI_CLASS |
4 |
File class |
EI_DATA |
5 |
Data encoding |
EI_VERSION |
6 |
File version |
EI_PAD |
7 |
Start of padding bytes |
EI_NIDENT |
16 |
Size of e_ident[] |
These indexes access bytes that hold the following values:
A file's first 4 bytes hold a magic number, identifying the file as an ELF object file.
Name |
Value |
Position |
---|---|---|
ELFMAG0 |
0x7f |
e_ident[EI_MAG0] |
ELFMAG1 |
'E' |
e_ident[EI_MAG1] |
ELFMAG2 |
'L' |
e_ident[EI_MAG2] |
ELFMAG3 |
'F' |
e_ident[EI_MAG3] |
The next byte, e_ident[EI_CLASS], identifies the file's class, or capacity.
Name |
Value |
Meaning |
---|---|---|
ELFCLASSNONE |
0 |
Invalid class |
ELFCLASS32 |
1 |
32-bit objects |
ELFCLASS64 |
2 |
64-bit objects |
The file format is designed to be portable among machines of various sizes, without imposing the sizes of the largest machine on the smallest. Class ELFCLASS32 supports machines with files and virtual address spaces up to 4 gigabytes; it uses the basic types defined above.
Class ELFCLASS64 is reserved for 64-bit architectures such as SPARC.
Byte e_ident[EI_DATA] specifies the data encoding of the processor-specific data in the object file. The following encodings are currently defined.
Name |
Value |
Meaning |
---|---|---|
ELFDATANONE |
0 |
Invalid data encoding |
ELFDATA2LSB |
1 |
See Figure 7-2. |
ELFDATA2MSB |
2 |
See Figure 7-3. |
More information on these encodings appears below. Other values are reserved and will be assigned to new encodings as necessary.
Byte e_ident[EI_VERSION] specifies the ELF header version number. Currently, this value must be EV_CURRENT, as explained in Table 7-5 for e_version.
This value marks the beginning of the unused bytes in e_ident. These bytes are reserved and set to zero; programs that read object files should ignore them. The value of EI_PAD will change in the future if currently unused bytes are given meanings.
A file's data encoding specifies how to interpret the basic objects in a file. As described above, class ELFCLASS32 files use objects that occupy 1, 2, and 4 bytes. Under the defined encodings, objects are represented as shown below. Byte numbers appear in the upper left corners.
Encoding ELFDATA2LSB specifies 2's complement values, with the least significant byte occupying the lowest address.
Encoding ELFDATA2MSB specifies 2's complement values, with the most significant byte occupying the lowest address.
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_ORDERED section flag (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-16.
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-15describes the values.
This member holds extra information, whose interpretation depends on the section type. Table 7-15describes 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:
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 "Move Section" 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. This entry holds the following:
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_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.
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-16 |
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_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 |
other |
SHN_UNDEF |
0 |
Various sections hold program and control information. Sections in the list below are used by the system and have the indicated types and attributes.
Table 7-16 Special Sections
Name |
Type |
Attribute |
---|---|---|
.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 |
.dynamic |
SHT_DYNAMIC |
SHF_ALLOC + SHF_WRITE |
.dynstr |
SHT_STRTAB |
SHF_ALLOC |
.dynsym |
SHT_DYNSYM |
SHF_ALLOC |
.fini |
SHT_PROGBITS |
SHF_ALLOC + SHF_EXECINSTR |
.got |
SHT_PROGBITS | |
.hash |
SHT_HASH |
SHF_ALLOC |
.init |
SHT_PROGBITS |
SHF_ALLOC + SHF_EXECINSTR |
.interp |
SHT_PROGBITS | |
.note |
SHT_NOTE |
None |
.plt |
SHT_PROGBITS | |
.rela |
SHT_RELA |
None |
.relname |
SHT_REL |
See "Relocation" |
.relaname |
SHT_RELA |
See "Relocation" |
.rodata |
SHT_PROGBITS |
SHF_ALLOC |
.rodata1 |
SHT_PROGBITS |
SHF_ALLOC |
.shstrtab |
SHT_STRTAB |
None |
.strtab |
SHT_STRTAB |
See description below |
.symtab |
SHT_SYMTAB |
See "Symbol Table" |
.text |
SHT_PROGBITS |
SHF_ALLOC + SHF_EXECINSTR |
.SUNW_bss |
SHT_NOBITS |
SHF_ALLOC + SHF_WRITE |
.SUNW_heap |
SHT_PROGBITS |
SHF_ALLOC + SHF_WRITE |
.SUNW_move |
SHT_SUNW_move |
SHF_ALLOC |
.SUNW_reloc |
SHT_rel SHT_rela |
SHF_ALLOC |
.SUNW_syminfo |
SHT_SUNW_syminfo |
SHF_ALLOC |
.SUNW_version |
SHT_SUNW_verdef SHT_SUNW_verneed SHT_SUNW_versym |
SHF_ALLOC |
This section holds uninitialized data that contribute to the program's memory image. By definition, the system initializes the data with zeros when the program begins to run. The section occupies no file space, as indicated by the section type, SHT_NOBITS.
This section holds comment information, typically contributed by the components of the compilation system. This section can be manipulated by mcs(1)).
These sections hold initialized data that contribute to the program's memory image.
This section holds dynamic linking information. See "Dynamic Section" for details.
This section holds strings needed for dynamic linking, most commonly the strings that represent the names associated with symbol table entries.
This section holds the dynamic linking symbol table. See "Symbol Table" for details.
This section holds executable instructions that contribute to the process termination code. That is, when a program exits normally, the system arranges to execute the code in this section. See "Initialization and Termination Routines" for details.
This section holds the global offset table. See "Global Offset Table (Processor-Specific)" for more information.
This section holds a symbol hash table. See "Hash Table" for more information.
This section holds executable instructions that contribute to the process initialization code. That is, when a program starts to run, the system arranges to execute the code in this section before calling the program entry point. See "Initialization and Termination Routines" for details.
This section holds the pathname of a program interpreter. See "Program Interpreter" for more information.
This section holds information in the format described in "Note Section".
This section holds the procedure linkage table. See "Procedure Linkage Table (Processor-Specific)" for more information.
This section holds relocations that do not apply to a particular section. One use of this is for register relocations, see "Register Symbols" for more details.
These sections hold relocation information, as "Relocation" describes. If the file has a loadable segment that includes relocation, the sections' attributes will include the SHF_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 will have the name .rel.text or .rela.text.
These sections hold read-only data that typically contribute to a non-writable segment in the process image. See "Program Header" for more information.
This section holds section names.
This section holds strings, most commonly the strings that represent the names associated with symbol table entries. If the file has a loadable segment that includes the symbol string table, the section's attributes will include the SHF_ALLOC bit; otherwise, that bit will be turned off.
This section holds a symbol table, as "Symbol Table" describes. If the file has a loadable segment that includes the symbol table, the section's attributes will include the SHF_ALLOC bit; otherwise, that bit will be turned off.
This section holds the text or executable instructions of a program.
This section holds partially initialized data for shared objects that contribute to the program's memory image. The data is initialized at runtime. The section occupies no file space, as indicated by the section type, SHT_NOBITS.
This section holds the heap of a dynamic executable created from dldump(3DL).
This section holds the additional information for partially initialized data. See "Move Section".
This section holds relocation information, as "Relocation" describes. This section is a concatenation of relocation sections that provides better locality of reference of the individual relocation records. Only the offset of the relocation record itself is meaningful, thus the section sh_info value is zero.
This section holds additional symbol table information. See "Syminfo Table" for more information.
Sections of this name hold versioning information. See "Versioning Information" for more information.
Section names with a dot (.) prefix are reserved for the system, although applications can use these sections if their existing meanings are satisfactory. Applications can use names without the prefix to avoid conflicts with system sections. The object file format lets one define sections not in the list above. An object file can 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 example, .Foo.psect is the psect section defined by the FOO architecture.
Existing extensions use their historical names.
Preexisting Extensions:
.conflict |
.liblist |
.lit8 |
.sdata |
.debug |
.line |
.reginfo |
.stab |
.gptab |
.lit4 |
.sbss |
.tdesc |
String table sections hold null-terminated character sequences, commonly called strings. The object file uses these strings to represent symbol and section names. One references a string as an index into the string table section.
The first byte, which is index zero, is defined to hold a null character. Likewise, a string table's last byte is defined to hold a null character, ensuring null termination for all strings. A string whose index is zero specifies either no name or a null name, depending on the context.
An empty string table section is permitted; its section header's sh_size member will contain zero. Nonzero indexes are invalid for an empty string table.
A section header's sh_name member holds an index into the section header string table section, as designated by the e_shstrndx member of the ELF header. The following figures show a string table with 25 bytes and the strings associated with various indexes.
The table below shows the strings of the string table above:
Table 7-17 String Table Indexes
Index |
String |
---|---|
0 |
none |
1 |
name |
7 |
Variable |
11 |
able |
16 |
able |
24 |
null string |
As the example shows, a string table index can refer to any byte in the section. A string can appear more than once; references to substrings can exist; and a single string can be referenced multiple times. Unreferenced strings also are allowed.
An object file's symbol table holds information needed to locate and relocate a program's symbolic definitions and references. A symbol table index is a subscript into this array. Index 0 both designates the first entry in the table and serves as the undefined symbol index. The contents of the initial entry are specified later in this section.
Table 7-18 Symbol Table Initial Entry
Name |
Value |
---|---|
STN_UNDEF |
0 |
A symbol table entry has the following format (defined in sys/elf.h):
typedef struct { Elf32_Word st_name; Elf32_Addr st_value; Elf32_Word st_size; unsigned char st_info; unsigned char st_other; Elf32_Half st_shndx; } Elf32_Sym; typedef struct { Elf64_Word st_name; unsigned char st_info; unsigned char st_other; Elf64_Half st_shndx; Elf64_Addr st_value; Elf64_Xword st_size; } Elf64_Sym; |
This member holds an index into the object file's symbol string table, which holds the character representations of the symbol names. If the value is nonzero, it represents a string table index that gives the symbol name. Otherwise, the symbol table entry has no name.
External C symbols have the same names in C and in object files' symbol tables.
This member gives the value of the associated symbol. Depending on the context, this can be an absolute value, an address, and so forth. See "Symbol Values".
Many symbols have associated sizes. For example, a data object's size is the number of bytes contained in the object. This member holds 0 if the symbol has no size or an unknown size.
This member specifies the symbol's type and binding attributes. A list of the values and meanings appears below. The following code shows how to manipulate the values (defined in sys/elf.h):
#define ELF32_ST_BIND(i) ((i) >> 4) #define ELF32_ST_TYPE(i) ((i) & 0xf) #define ELF32_ST_INFO(b, t) (((b)<<4)+((t)&0xf)) #define ELF64_ST_BIND(info) ((info) >> 4) #define ELF64_ST_TYPE(info) ((info) & 0xf) #define ELF64_ST_INFO(bind, type) (((bind)<<4)+((type)&0xf)) |
This member currently holds 0 and has no defined meaning.
Every symbol table entry is defined in relation to some section; this member holds the relevant section header table index. Some section indexes indicate special meanings. See Table 7-12.
A symbol's binding determines the linkage visibility and behavior.
Table 7-19 Symbol Binding, ELF32_ST_BIND & ELF64_ST_BIND
Name |
Value |
---|---|
STB_LOCAL |
0 |
STB_GLOBAL |
1 |
STB_WEAK |
2 |
STB_LOPROC |
13 |
STB_HIPROC |
15 |
Local symbols are not visible outside the object file containing their definition. Local symbols of the same name can exist in multiple files without interfering with each other.
Global symbols are visible to all object files being combined. One file's definition of a global symbol will satisfy another file's undefined reference to the same global symbol.
Weak symbols resemble global symbols, but their definitions have lower precedence.
Values in this inclusive range are reserved for processor-specific semantics.
Global and weak symbols differ in two major ways:
When the link-editor combines several relocatable object files, it does not allow multiple definitions of STB_GLOBAL symbols with the same name. On the other hand, if a defined global symbol exists, the appearance of a weak symbol with the same name will not cause an error. The link-editor honors the global definition and ignores the weak ones.
Similarly, if a common symbol exists (that is, a symbol with the st_index field holding SHN_COMMON), the appearance of a weak symbol with the same name does not cause an error. The link-editor uses the common definition and ignores the weak one. See "Symbol Resolution" for more information.
When the link-editor searches archive libraries (see "Archive Processing") , it extracts archive members that contain definitions of undefined or tentative global symbols. The member's definition can be either a global or a weak symbol.
The link-editor, by default, does not extract archive members to resolve undefined weak symbols. Unresolved weak symbols have a zero value. The use of -z weakextract overrides this default behavior, and allows weak references to cause the extraction of archive members.
In each symbol table, all symbols with STB_LOCAL binding precede the weak and global symbols. As "Sections" describes, a symbol table section's sh_info section header member holds the symbol table index for the first non-local symbol.
A symbol's type provides a general classification for the associated entity.
Table 7-20 Symbol Types, ELF32_ST_TYPE & ELF64_ST_TYPE
Name |
Value |
---|---|
STT_NOTYPE |
0 |
STT_OBJECT |
1 |
STT_FUNC |
2 |
STT_SECTION |
3 |
STT_FILE |
4 |
STT_LOPROC |
13 |
STT_SPARC_REGISTER |
13 |
STT_HIPROC |
15 |
The symbol type is not specified.
This symbol is associated with a data object, such as a variable, an array, and so forth.
This symbol is associated with a function or other executable code.
This symbol is associated with a section. Symbol table entries of this type exist primarily for relocation and normally have STB_LOCAL binding.
Conventionally, the symbol's name gives the name of the source file associated with the object file. A file symbol has STB_LOCAL binding, its section index is SHN_ABS, and it precedes the other STB_LOCAL symbols for the file, if it is present. Symbol index 1 of the SHT_SYMTAB is an STT_FILE symbol representing the file itself. Conventionally, this is followed by the files STT_SECTION symbols, and any global symbols that have been reduced to locals (see "Reducing Symbol Scope", and Chapter 5, Versioning for more details).
Values in this inclusive range are reserved for processor-specific semantics.
Function symbols (those with type STT_FUNC) in shared object files have special significance. When another object file references a function from a shared object, the link-editor automatically creates a procedure linkage table entry for the referenced symbol. Shared object symbols with types other than STT_FUNC will not be referenced automatically through the procedure linkage table.
If a symbol's value refers to a specific location within a section, its section index member, st_shndx, holds an index into the section header table. As the section moves during relocation, the symbol's value changes as well, and references to the symbol continue to point to the same location in the program. Some special section index values give other semantics:
This symbol has an absolute value that will not change because of relocation.
This symbol labels a common block that has not yet been allocated. The symbol's value gives alignment constraints, similar to a section's sh_addralign member. That is, the link-editor will allocate the storage for the symbol at an address that is a multiple of st_value. The symbol's size tells how many bytes are required.
This section table index means the symbol is undefined. When the link-editor combines this object file with another that defines the indicated symbol, this file's references to the symbol will be bound to the actual definition.
As mentioned above, the symbol table entry for index 0 (STN_UNDEF) is reserved; it holds the following:
Table 7-21 Symbol Table Entry: Index 0
Name |
Value |
Note |
---|---|---|
st_name |
0 |
No name |
st_value |
0 |
Zero value |
st_size |
0 |
No size |
st_info |
0 |
No type, local binding |
st_other |
0 |
|
st_shndx |
SHN_UNDEF |
No section |
Symbol table entries for different object file types have slightly different interpretations for the st_value member.
In relocatable files, st_value holds alignment constraints for a symbol whose section index is SHN_COMMON.
In relocatable files, st_value holds a section offset for a defined symbol. That is, st_value is an offset from the beginning of the section that st_shndx identifies.
In executable and shared object files, st_value holds a virtual address. To make these files' symbols more useful for the runtime linker, the section offset (file interpretation) gives way to a virtual address (memory interpretation) for which the section number is irrelevant.
Although the symbol table values have similar meanings for different object files, the data allow efficient access by the appropriate programs.
The SPARC architecture supports register symbols, that is, a symbol that initializes a global register. A symbol table entry for a register symbol contains the following:
Table 7-22 SPARC: Symbol Table Entry: Register Symbol
Field |
Meaning |
---|---|
st_name |
Index into string table of the name of the symbol, or 0 for a scratch register. |
st_value | Register number. See the ABI manual for integer register assignments. |
st_size |
Unused (0). |
st_info | Bind is typically STB_GLOBAL, type must be STT_SPARC_REGISTER. |
st_other |
Unused (0). |
st_shndx |
SHN_ABS if this object initializes this register symbol; SHN_UNDEF otherwise. |
Table 7-23 SPARC: Register Numbers
Name |
Value |
Meaning |
---|---|---|
STO_SPARC_REGISTER_G2 |
0x2 |
%g2 |
STO_SPARC_REGISTER_G3 |
0x3 |
%g3 |
Absence of an entry for a particular global register means that the particular global register is not used at all by the object.
This section contains multiple entries of the type Elf32_Syminfo or Elf64_Syminfo. There is one entry in the .SUNW_syminfo section for every entry in the associated symbol table (sh_link). If this section is present in an object, additional symbol information is to be found by taking the symbol index from the associated symbol table and using that to find the corresponding Elf32_Syminfo or Elf64_Syminfo entry in this section. The associated symbol table and the Syminfo table will always have the same number of entries. Index 0 will be used to store the current version of the Syminfo table, which will be SYMINFO_CURRENT. Since symbol table entry 0 is always reserved for the UNDEF symbol table entry, this does not pose any conflicts.
An Symfino entry has the following format:
typedef struct { Elf32_Half si_boundto; /* direct bindings - symbol bound to */ Elf32_Half si_flags; /* per symbol flags */ } Elf32_Syminfo; typedef struct { Elf64_Half si_boundto; /* direct bindings - symbol bound to */ Elf64_Half si_flags; /* per symbol flags */ } Elf64_Syminfo; |
This is a bit-field that can have the following flags set:
Table 7-24 Syminfo flags
Name |
Value |
Meaning |
---|---|---|
SYMINFO_FLG_DIRECT |
0x01 |
This symbol has a direct reference to an external object. |
SYMINFO_FLG_COPY |
0x02 |
This symbol is the result of a copy-relocation. |
Index to an entry in the .dynamic section identified by the sh_info field. This entry will identify a DT_* (DT_NEEDED) entry which will identify a dynamic object associated with the Syminfo entry. The following two entries are reserved values for si_boundto:
Table 7-25 si_boundto reserved values
Name |
Value |
Meaning |
---|---|---|
SYMINFO_BT_SELF |
0xffff |
Symbol bound to self |
SYMINFO_BT_PARENT |
0xfffe |
Symbol bound to parent. The parent is the first object to cause this dynamic object to be loaded. |
Relocation is the process of connecting symbolic references with symbolic definitions. For example, when a program calls a function, the associated call instruction must transfer control to the proper destination address at execution. In other words, relocatable files must have information that describes how to modify their section contents, thus allowing executable and shared object files to hold the right information for a process's program image. Relocation entries are these data.
Relocation entries can have the following structure (defined in sys/elf.h):
typedef struct { Elf32_Addr r_offset; Elf32_Word r_info; } Elf32_Rel; typedef struct { Elf32_Addr r_offset; Elf32_Word r_info; Elf32_Sword r_addend; } Elf32_Rela; typedef struct { Elf64_Addr r_offset; Elf64_Xword r_info; } Elf64_Rel; typedef struct { Elf64_Addr r_offset; Elf64_Xword r_info; Elf64_Sxword r_addend; } Elf32_Rela; |
This member gives the location at which to apply the relocation action. For a relocatable file, the value is the byte offset from the beginning of the section to the storage unit affected by the relocation. For an executable file or a shared object, the value is the virtual address of the storage unit affected by the relocation.
This member gives both the symbol table index, with respect to which the relocation must be made, and the type of relocation to apply. For example, a call instruction's relocation entry will hold the symbol table index of the function being called. If the index is STN_UNDEF, the undefined symbol index, the relocation uses 0 as the symbol value. Relocation types are processor-specific; descriptions of their behavior appear below. When the text below refers to a relocation entry's relocation type or symbol table index, it means the result of applying ELF32_R_TYPE or ELF32_R_SYM, respectively, to the entry's r_info member:
#define ELF32_R_SYM(i) ((i)>>8) #define ELF32_R_TYPE(i) ((unsigned char)(i)) #define ELF32_R_INFO(s, t) (((s)<<8)+(unsigned char)(t)) #define ELF64_R_SYM(info) ((info)>>32) #define ELF64_R_TYPE(info) ((Elf64_Word)(info)) #define ELF64_R_INFO(sym, type) (((Elf64_Xword)(sym)<<32)+ \ (Elf64_Xword)(type)) |
For Elf64_Rel and Elf64_Rela structures, the r_info field is further broken down into an 8-bit type identifier and a 24-bit type dependent data field:
#define ELF64_R_TYPE_DATA(info) (((Elf64_Xword)(info)<<32)>>40) #define ELF64_R_TYPE_ID(info) (((Elf64_Xword)(info)<<56)>>56) #define ELF64_R_TYPE_INFO(data, type) (((Elf64_Xword)(data)<<8)+ \ (Elf64_Xword)(type)) |
This member specifies a constant addend used to compute the value to be stored into the relocatable field.
As shown above, only Elf32_Rela entries contain an explicit addend. Entries of type Elf32_Rel store an implicit addend in the location to be modified. 32-bit SPARCuses Elf32_Rela entries, 64-bit SPARC uses Elf64_Rela entries and IA uses Elf32_Rel entries.
A relocation section references two other sections: a symbol table and a section to modify. The section header's sh_info and sh_link members, described in "Sections" earlier, specify these relationships. Relocation entries for different object files have slightly different interpretations for the r_offset member.
In relocatable files, r_offset holds a section offset. That is, the relocation section itself describes how to modify another section in the file; relocation offsets designate a storage unit within the second section.
In executable and shared object files, r_offset holds a virtual address. To make these files' relocation entries more useful for the runtime linker, the section offset (file interpretation) gives way to a virtual address (memory interpretation).
Although the interpretation of r_offset changes for different object files to allow efficient access by the relevant programs, the relocation types' meanings stay the same.
On SPARC, relocation entries describe how to alter the following instruction and data fields (bit numbers appear in the lower box corners):
On IA, relocation entries describe how to alter the following instruction and data fields (bit numbers appear in the lower box corners):
word32 specifies a 32-bit field occupying 4 bytes with an arbitrary byte alignment. These values use the same byte order as other word values in the IA architecture:
64-bit SPARC also includes a 64-bit word field:
Calculations below assume the actions are transforming a relocatable file into either an executable or a shared object file. Conceptually, the link-editor merges one or more relocatable files to form the output. It first decides how to combine and locate the input files, then updates the symbol values, and finally performs the relocation. Relocations applied to executable or shared object files are similar and accomplish the same result. Descriptions below use the following notation:
Means the addend used to compute the value of the relocatable field
Means the base address at which a shared object is loaded into memory during execution. Generally, a shared object file is built with a 0 base virtual address, but the execution address is different. See "Program Header" for more information about the base address
Means the offset into the global offset table at which the address of the relocation entry's symbol resides during execution. See "Global Offset Table (Processor-Specific)" for more information.
Means the address of the global offset table. See "Global Offset Table (Processor-Specific)" for more information.
Means the place (section offset or address) of the procedure linkage table entry for a symbol. A procedure linkage table entry redirects a function call to the proper destination. The link-editor builds the initial procedure linkage table, and the runtime linker modifies the entries during execution. See "Procedure Linkage Table (Processor-Specific)" for more information.
Means the place (section offset or address) of the storage unit being relocated (computed using r_offset).
Means the value of the symbol whose index resides in the relocation entry.
SPARC relocation entries apply to bytes (byte8), half-words (half16), or words (the others). IA relocation entries apply to words. In any case, the r_offset value designates the offset or virtual address of the first byte of the affected storage unit. The relocation type specifies which bits to change and how to calculate their values.
32-bit SPARC uses only Elf32_Rela relocation entries with explicit addends and 64-bit SPARC uses Elf64_Rela. Thus the r_addend member serves as the relocation addend. IA uses only Elf32_Rel relocation entries, the field to be relocated holds the addend. In all cases the addend and the computed result use the same byte order.
Field names in the following table tell whether the relocation type checks for overflow. A calculated relocation value can be larger than the intended field, and a relocation type can verify (V) the value fits or truncate (T) the result. As an example, V-simm13 means that the computed value can not have significant, nonzero bits outside the simm13 field.
Name |
Value |
Field |
Calculation |
---|---|---|---|
R_SPARC_NONE |
0 |
None |
None |
R_SPARC_8 |
1 |
V-byte8 |
S + A |
R_SPARC_16 |
2 |
V-half16 |
S + A |
R_SPARC_32 |
3 |
V-word32 |
S + A |
R_SPARC_DISP8 |
4 |
V-byte8 |
S + A - P |
R_SPARC_DISP16 |
5 |
V-half16 |
S + A - P |
R_SPARC_DISP32 |
6 |
V-disp32 |
S + A - P |
R_SPARC_WDISP30 |
7 |
V-disp30 |
(S + A - P) >> 2 |
R_SPARC_WDISP22 |
8 |
V-disp22 |
(S + A - P) >> 2 |
R_SPARC_HI22 |
9 |
T-imm22 |
(S + A) >> 10 |
R_SPARC_22 |
10 |
V-imm22 |
S + A |
R_SPARC_13 |
11 |
V-simm13 |
S + A |
R_SPARC_LO10 |
12 |
T-simm13 |
(S + A) & 0x3ff |
R_SPARC_GOT10 |
13 |
T-simm13 |
G & 0x3ff |
R_SPARC_GOT13 |
14 |
V-simm13 |
G |
R_SPARC_GOT22 |
15 |
T-simm22 |
G >> 10 |
R_SPARC_PC10 |
16 |
T-simm13 |
(S + A - P) & 0x3ff |
R_SPARC_PC22 |
17 |
V-disp22 |
(S + A - P) >> 10 |
R_SPARC_WPLT30 |
18 |
V-disp30 |
(L + A - P) >> 2 |
R_SPARC_COPY |
19 |
None |
None |
R_SPARC_GLOB_DAT |
20 |
V-word32 |
S + A |
R_SPARC_JMP_SLOT |
21 |
None |
See R_SPARC_JMP_SLOT, |
R_SPARC_RELATIVE |
22 |
V-word32 |
B + A |
R_SPARC_UA32 |
23 |
V-word32 |
S + A |
R_SPARC_PLT32 |
24 |
V-word32 |
L + A |
R_SPARC_HIPLT22 |
25 |
T-imm22 |
(L + A) >> 10 |
R_SPARC_LOPLT10 |
26 |
T-simm13 |
(L + A) & 0x3ff |
R_SPARC_PCPLT32 |
27 |
V-word32 |
L + A - P |
R_SPARC_PCPLT22 |
28 |
V-disp22 |
(L + A - P) >> 10 |
R_SPARC_PCPLT10 |
29 |
V-simm13 |
(L + A - P) & 0x3ff |
R_SPARC_10 |
30 |
V-simm10 |
S + A |
R_SPARC_11 |
31 |
V-simm11 |
S + A |
R_SPARC_WDISP16 |
40 |
V-d2/disp14 |
(S + A - P) >> 2 |
R_SPARC_WDISP19 |
41 |
V-disp19 |
(S + A - P) >> 2 |
R_SPARC_7 |
43 |
V-imm7 |
S + A |
R_SPARC_5 |
44 |
V-imm5 |
S + A |
R_SPARC_6 |
45 |
V-imm6 |
S + A |
Some relocation types have semantics beyond simple calculation:
This relocation type resembles R_SPARC_LO10, except that it refers to the address of the symbol's global offset table entry and additionally instructs the link-editor to build a global offset table.
This relocation type resembles R_SPARC_13, except that it refers to the address of the symbol's global offset table entry and additionally instructs the link-editor to build a global offset table.
This relocation type resembles R_SPARC_22, except that it refers to the address of the symbol's global offset table entry and additionally instructs the link-editor to build a global offset table.
This relocation type resembles R_SPARC_WDISP30, except that it refers to the address of the symbol's procedure linkage table entry and additionally instructs the link-editor to build a procedure linkage table.
The link-editor creates this relocation type for dynamic linking. Its offset member refers to a location in a writable segment. The symbol table index specifies a symbol that should exist both in the current object file and in a shared object. During execution, the runtime linker copies data associated with the shared object's symbol to the location specified by the offset. See "Copy Relocations" for more details.
This relocation type resembles R_SPARC_32, except that it sets a global offset table entry to the address of the specified symbol. The special relocation type allows you to determine the correspondence between symbols and global offset table entries.
The link-editor creates this relocation type for dynamic linking. Its offset member gives the location of a procedure linkage table entry. The runtime linker modifies the procedure linkage table entry to transfer control to the designated symbol address.
The link-editor creates this relocation type for dynamic linking. Its offset member gives the location within a shared object that contains a value representing a relative address. The runtime linker computes the corresponding virtual address by adding the virtual address at which the shared object is loaded to the relative address. Relocation entries for this type must specify 0 for the symbol table index.
This relocation type resembles R_SPARC_32, except that it refers to an unaligned word. That is, the word to be relocated must be treated as four separate bytes with arbitrary alignment, not as a word aligned according to the architecture requirements.
Field names in the following table tell whether the relocation type checks for overflow. A calculated relocation value can be larger than the intended field, and a relocation type can verify (V) the value fits or truncate (T) the result. As an example, V-simm13 means that the computed value can not have significant, nonzero bits outside the simm13 field.
Name |
Value |
Field |
Calculation |
---|---|---|---|
R_SPARC_NONE |
0 |
None |
None |
R_SPARC_8 |
1 |
V-byte8 |
S + A |
R_SPARC_16 |
2 |
V-half16 |
S + A |
R_SPARC_32 |
3 |
V-word32 |
S + A |
R_SPARC_DISP8 |
4 |
V-byte8 |
S + A - P |
R_SPARC_DISP16 |
5 |
V-half16 |
S + A - P |
R_SPARC_DISP32 |
6 |
V-disp32 |
S + A - P |
R_SPARC_WDISP30 |
7 |
V-disp30 |
(S + A - P) >> 2 |
R_SPARC_WDISP22 |
8 |
V-disp22 |
(S + A - P) >> 2 |
R_SPARC_HI22 |
9 |
V-imm22 |
(S + A) >> 10 |
R_SPARC_22 |
10 |
V-imm22 |
S + A |
R_SPARC_13 |
11 |
V-simm13 |
S + A |
R_SPARC_LO10 |
12 |
T-simm13 |
(S + A) & 0x3ff |
R_SPARC_GOT10 |
13 |
T-simm13 |
G & 0x3ff |
R_SPARC_GOT13 |
14 |
V-simm13 |
G |
R_SPARC_GOT22 |
15 |
T-simm22 |
G >> 10 |
R_SPARC_PC10 |
16 |
T-simm13 |
(S + A - P) & 0x3ff |
R_SPARC_PC22 |
17 |
V-disp22 |
(S + A - P) >> 10 |
R_SPARC_WPLT30 |
18 |
V-disp30 |
(L + A - P) >> 2 |
R_SPARC_COPY |
19 |
None |
None |
R_SPARC_GLOB_DAT |
20 |
V-xword64 |
S + A |
R_SPARC_JMP_SLOT |
21 |
None |
See R_SPARC_JMP_SLOT, |
R_SPARC_RELATIVE |
22 |
V-xword64 |
B + A |
R_SPARC_UA32 |
23 |
V-word32 |
S + A |
R_SPARC_PLT32 |
24 |
V-word32 |
L + A |
R_SPARC_HIPLT22 |
25 |
T-imm22 |
(L + A) >> 10 |
R_SPARC_LOPLT10 |
26 |
T-simm13 |
(L + A) & 0x3ff |
R_SPARC_PCPLT32 |
27 |
V-disp32 |
L + A - P |
R_SPARC_PCPLT22 |
28 |
V-disp22 |
(L + A - P) >> 10 |
R_SPARC_PCPLT10 |
29 |
V-simm13 |
(L + A - P) & 0x3ff |
R_SPARC_10 |
30 |
V-simm10 |
S + A |
R_SPARC_11 |
31 |
V-simm11 |
S + A |
R_SPARC_64 |
32 |
V-xword64 |
S + A |
R_SPARC_OLO10 |
33 |
V-simm13 |
((S + A) & 0x3ff) + O |
R_SPARC_HH22 |
34 |
V-imm22 |
(S + A) >> 42 |
R_SPARC_HM10 |
35 |
T-simm13 |
((S + A) >> 32) & 0x3ff |
R_SPARC_LM22 |
36 |
T-imm22 |
(S + A) >> 10 |
R_SPARC_PC_HH22 |
37 |
V-imm22 |
(S + A - P) >> 42 |
R_SPARC_PC_HM10 |
38 |
T-simm13 |
((S + A - P) >> 32) & 0x3ff |
R_SPARC_PC_LM22 |
39 |
T-imm22 |
(S + A - P) >> 10 |
R_SPARC_WDISP16 |
40 |
V-d2/disp14 |
(S + A - P) >> 2 |
R_SPARC_WDISP19 |
41 |
V-disp19 |
(S + A - P) >> 2 |
R_SPARC_7 |
43 |
V-imm7 |
(S + A) & 0x7f |
R_SPARC_5 |
44 |
V-imm5 |
(S + A) & 0x1f |
R_SPARC_6 |
45 |
V-imm6 |
(S + A) & 0x3f |
R_SPARC_DISP64 |
46 |
V-xword64 |
S + A - P |
R_SPARC_PLT64 |
47 |
V-xword64 |
L + A |
R_SPARC_HIX22 |
48 |
V-imm22 |
((S + A) ^ 0xffffffffffffffff) >> 10 |
R_SPARC_LOX10 |
49 |
T-simm13 |
((S + A) & 0x3ff) | 0x1c00 |
R_SPARC_H44 |
50 |
V-imm22 |
(S + A) >> 22 |
R_SPARC_M44 |
51 |
T-imm10 |
((S + A) >> 12) & 0x3ff |
R_SPARC_L44 |
52 |
T-imm13 |
(S + A) & 0xfff |
R_SPARC_REGISTER |
53 |
V-xword64 |
S + A |
R_SPARC_UA64 |
54 |
V-xword64 |
S + A |
R_SPARC_UA16 |
55 |
V-half16 |
S + A |
Some relocation types have semantics beyond simple calculation:
This relocation type resembles R_SPARC_LO10, except that it refers to the address of the symbol's global offset table entry and additionally instructs the link-editor to build a global offset table.
This relocation type resembles R_SPARC_13, except that it refers to the address of the symbol's global offset table entry and additionally instructs the link-editor to build a global offset table.
This relocation type resembles R_SPARC_22, except that it refers to the address of the symbol's global offset table entry and additionally instructs the link-editor to build a global offset table.
This relocation type resembles R_SPARC_WDISP30, except that it refers to the address of the symbol's procedure linkage table entry and additionally instructs the link-editor to build a procedure linkage table.
The link-editor creates this relocation type for dynamic linking. Its offset member refers to a location in a writable segment. The symbol table index specifies a symbol that should exist both in the current object file and in a shared object. During execution, the runtime linker copies data associated with the shared object's symbol to the location specified by the offset. See "Copy Relocations" for more details.
This relocation type resembles R_SPARC_64, except that it sets a global offset table entry to the address of the specified symbol. The special relocation type allows you to determine the correspondence between symbols and global offset table entries.
The link-editor creates this relocation type for dynamic linking. Its offset member gives the location of a procedure linkage table entry. The runtime linker modifies the procedure linkage table entry to transfer control to the designated symbol address.
The link-editor creates this relocation type for dynamic linking. Its offset member gives the location within a shared object that contains a value representing a relative address. The runtime linker computes the corresponding virtual address by adding the virtual address at which the shared object is loaded to the relative address. Relocation entries for this type must specify 0 for the symbol table index.
This relocation type resembles R_SPARC_32, except that it refers to an unaligned word. That is, the word to be relocated must be treated as four separate bytes with arbitrary alignment, not as a word aligned according to the architecture requirements.
This relocation type resembles R_SPARC_LO10, except that an extra offset is added to make full use of the 13-bit signed immediate field.
This relocation type is used by the assembler when it sees an instruction of the form "imm22-instruction ... %hh(absolute) ...".
This relocation type is generated by the assembler when it sees an instruction of the form "simm13-instruction ... %hm(absolute) ..."
This relocation type is used by the assembler when it sees an instruction of the form "imm22-instruction ... %lm(absolute) ...". This resembles R_SPARC_HI22, except it truncates rather than validates.
This relocation type is used by the assembler when it sees an instruction of the form "imm22-instruction ... %hh(pc-relative) ...".
This relocation type is generated by the assembler when it sees an instruction of the form "simm13-instruction ... %hm(pc-relative) ...".
This relocation type is used by the assembler when it sees an instruction of the form "imm22-instruction ... %lm(pc-relative) ...". This resembles R_SPARC_PC22, except that it truncates rather than validates.
This relocation type is used by the assembler for 7 bit software trap numbers.
This relocation type is used with R_SPARC_LOX10 for executables that will be confined to the uppermost 4GB of the 64-bit address space. Similar to R_SPARC_HI22, but supplies ones complement of linked value.
Used with R_SPARC_HIX22. Similar to R_SPARC_LO10, but always sets bits 10..12 of the linked value.
This relocation type is used by the assembler when it sees an instruction of the form "imm44-instruction ... %h44(absolute) ..".
This relocation type is generated by the assembler when it sees an instruction of the form "imm44-instruction ... %m44(absolute) ...".
This relocation type is used with the R_SPARC_H44 and R_SPARC_M44 relocation types to generate a 44-bit absolute addressing model. The assembler will generate this type when it sees an instruction of the form "imm44-instruction ... %l44(absolute) ...".
This relocation type is used to initialize a register symbol. Its offset member contains the register number to be initialized. There must be a corresponding register symbol for this register of type SHN_ABS.
Name |
Value |
Field |
Calculation |
---|---|---|---|
R_386_NONE |
0 |
none |
none |
R_386_32 |
1 |
word32 |
S + A |
R_386_PC32 |
2 |
word32 |
S + A - P |
R_386_GOT32 |
3 |
word32 |
G + A |
R_386_PLT32 |
4 |
word32 |
L + A - P |
R_386_COPY |
5 |
none |
none |
R_386_GLOB_DAT |
6 |
word32 |
S |
R_386_JMP_SLOT |
7 |
word32 |
S |
R_386_RELATIVE |
8 |
word32 |
B + A |
R_386_GOTOFF |
9 |
word32 |
S + A - GOT |
R_386_GOTPC |
10 |
word32 |
GOT + A - P |
R_386_32PLT |
11 |
word32 |
L + A |
Some relocation types have semantics beyond simple calculation:
This relocation type computes the distance from the base of the global offset table to the symbol's global offset table entry. It also instructs the link-editor to build a global offset table.
This relocation type computes the address of the symbol's procedure linkage table entry and instructs the link-editor to build a procedure linkage table.
The link-editor creates this relocation type for dynamic linking. Its offset member refers to a location in a writable segment. The symbol table index specifies a symbol that should exist both in the current object file and in a shared object. During execution, the runtime linker copies data associated with the shared object's symbol to the location specified by the offset. See "Copy Relocations".
This relocation type is used to set a global offset table entry to the address of the specified symbol. The special relocation type lets one determine the correspondence between symbols and global offset table entries.
The link-editor creates this relocation type for dynamic linking. Its offset member gives the location of a procedure linkage table entry. The runtime linker modifies the procedure linkage table entry to transfer control to the designated symbol address.
The link-editor creates this relocation type for dynamic linking. Its offset member gives the location within a shared object that contains a value representing a relative address. The runtime linker computes the corresponding virtual address by adding the virtual address at which the shared object is loaded to the relative address. Relocation entries for this type must specify 0 for the symbol table index.
This relocation type computes the difference between a symbol's value and the address of the global offset table. It also instructs the link-editor to build the global offset table.
This relocation type resembles R_386_PC32, except it uses the address of the global offset table in its calculation. The symbol referenced in this relocation normally is _GLOBAL_OFFSET_TABLE_, which also instructs the link-editor to build the global offset table.
Sections of this type will be uniquely identified by their section name (sh_name). If the link-editor encounters multiple sections of type SHT_SUNW_COMDAT with the same section name, the first one will be retained and all others will be discarded. Also any relocations applied to a discarded SHT_SUNW_COMDAT section will be ignored and any symbols defined in a discarded section will not be kept.
Additionally the link-editor also supports the section naming convention used for section reordering (see "Segment Declarations") when the compiler is invoked with the -xF option. That is, if the sections are placed in a section of the name .<funcname>%<sectname> the final SHT_SUNW_COMDAT sections which have been retained will be coalesced into a section identified by the .<sectname>. Using this method, the SHT_SUNW_COMDAT sections can be placed into the .text, .data, or any other section as their final destination.
Objects created by the link-editor can contain two types of versioning information:
Version definitions provide associations of global symbols and are implemented using sections of type SHT_SUNW_verdef and SHT_SUNW_versym.
Version dependencies indicate the version definition requirements from other object dependencies and are implemented using sections of type SHT_SUNW_verneed.
The structures that form these sections are defined in sys/link.h. Sections that contain versioning information are named .SUNW_version.
This section is defined by the type SHT_SUNW_verdef. If this section exists, a SHT_SUNW_versym section must also exist. Using these two structures, an association of symbols-to-version definitions is maintained within the file (see "Creating a Version Definition" for more details). Elements of this section have the following structure:
typedef struct { Elf32_Half vd_version; Elf32_Half vd_flags; Elf32_Half vd_ndx; Elf32_Half vd_cnt; Elf32_Word vd_hash; Elf32_Word vd_aux; Elf32_Word vd_next; } Elf32_Verdef; typedef struct { Elf32_Word vda_name; Elf32_Word vda_next; } Elf32_Verdaux; typedef struct { Elf64_Half vd_version; Elf64_Half vd_flags; Elf64_Half vd_ndx; Elf64_Half vd_cnt; Elf64_Word vd_hash; Elf64_Word vd_aux; Elf64_Word vd_next; } Elf64_Verdef; typedef struct { Elf64_Word vda_name; Elf64_Word vda_next; } Elf64_Verdaux; |
This member identifies the version of the structure itself.
Name |
Value |
Meaning |
---|---|---|
VER_DEF_NONE |
0 |
Invalid version |
VER_DEF_CURRENT |
>=1 |
Current version |
The value 1 signifies the original section format; extensions will create new versions with higher numbers. The value of VER_DEF_CURRENT changes as necessary to reflect the current version number.
This member holds version definition-specific information.
Name |
Value |
Meaning |
---|---|---|
VER_FLG_BASE |
0x1 |
Version definition of the file itself |
VER_FLG_WEAK |
0x2 |
Weak version identifier |
The base version definition is always present when version definitions, or symbol auto-reduction, has been applied to the file. The base version provides a default version for the files reserved symbols (see "Generating the Output Image"). A weak version definition has no symbols associated with it (see "Creating a Weak Version Definition" for more details).
This member holds the version index. Each version definition has a unique index that is used to associate SHT_SUNW_versym entries to the appropriate version definition.
This member indicates the number of elements in the Elf32_Verdaux array.
This member holds the hash value of the version definition name (this value is generated using the same hashing function described in "Hash Table").
This member holds the byte offset, from the start of this Elf32_Verdef entry, to the Elf32_Verdaux array of version definition names. The first element of the array must exist and points to the version definition string this structure defines. Additional elements can be present, the number being indicated by the vd_cnt value. These elements represent the dependencies of this version definition. Each of these dependencies will have its own version definition structure.
This member holds the byte offset, from the start of this Elf32_Verdef structure, to the next Elf32_Verdef entry.
This member holds a string table offset to a null-terminated string, giving the name of the version definition.
This member holds the byte offset, from the start of this Elf32_Verdaux entry, to the next Elf32_Verdaux entry.
This section is defined by the type SHT_SUNW_versym, and consists of an array of elements having the following structure:
typedef Elf32_Half Elf32_Versym; typedef Elf64_Half Elf64_Versym; |
The number of elements of the array must equal the number of symbol table entries contained in the associated symbol table (determined by the sections sh_link value). Each element of the array contains a single index that can have the following values:
Table 7-31 Version Dependency Indexes
Name |
Value |
Meaning |
---|---|---|
VER_NDX_LOCAL |
0 |
Symbol has local scope |
VER_NDX_GLOBAL |
1 |
Symbol has global scope (assigned to base version definition) |
|
>1 |
Symbol has global scope (assigned to user-defined version definition) |
Any index values greater than VER_NDX_GLOBAL must correspond to the vd_ndx value of an entry in the SHT_SUNW_verdef section. If no index values greater than VER_NDX_GLOBAL exist, then no SHT_SUNW_verdef section need be present.
This section is defined by the type SHT_SUNW_verneed. This section compliments the dynamic dependency requirements of the file by indicating the version definitions required from these dependencies. Only if a dependency contains version definitions will a recording be made in this section. Elements of this section have the following structure:
typedef struct { Elf32_Half vn_version; Elf32_Half vn_cnt; Elf32_Word vn_file; Elf32_Word vn_aux; Elf32_Word vn_next; } Elf32_Verneed; typedef struct { Elf32_Word vna_hash; Elf32_Half vna_flags; Elf32_Half vna_other; Elf32_Word vna_name; Elf32_Word vna_next; } Elf32_Vernaux; typedef struct { Elf64_Half vn_version; Elf64_Half vn_cnt; Elf64_Word vn_file; Elf64_Word vn_aux; Elf64_Word vn_next; } Elf64_Verneed; typedef struct { Elf64_Word vna_hash; Elf64_Half vna_flags; Elf64_Half vna_other; Elf64_Word vna_name; Elf64_Word vna_next; } Elf64_Vernaux; |
This member identifies the version of the structure itself.
Name |
Value |
Meaning |
---|---|---|
VER_NEED_NONE |
0 |
Invalid version |
VER_NEED_CURRENT |
>=1 |
Current version |
The value 1 signifies the original section format; extensions will create new versions with higher numbers. The value of VER_NEED_CURRENT changes as necessary to reflect the current version number.
This member indicates the number of elements in the Elf32_Vernaux array.
This member holds a string table offset to a null-terminated string, giving the filename having a version dependency. This name will match one of the .dynamic dependencies (refer to "Dynamic Section") found in the file.
This member holds the byte offset, from the start of this Elf32_Verneed entry, to the Elf32_Vernaux array of version definitions required from the associated file dependency. There must exist at least one version dependency. Additional version dependencies can be present, the number being indicated by the vn_cnt value.
This member holds the byte offset, from the start of this Elf32_Verneed entry, to the next Elf32_Verneed entry.
This member holds the hash value of the version dependency name (this value is generated using the same hashing function described in "Hash Table").
This member holds version dependency specific information.
Name |
Value |
Meaning |
---|---|---|
VER_FLG_WEAK |
0x2 |
Weak version identifier |
A weak version dependency indicates an original binding to a weak version definition. See "Creating a Version Definition" for more details.
This member is presently unused.
This member holds a string table offset to a null-terminated string, giving the name of the version dependency.
This member holds the byte offset, from the start of this Elf32_Vernaux entry, to the next Elf32_Vernaux entry.
Sometimes a vendor or system builder needs to mark an object file with special information that other programs will check for conformance, compatibility, and so forth. Sections of type SHT_NOTE and program header elements of type PT_NOTE can be used for this purpose.
The note information in sections and program header elements holds any number of entries, each of which is an array of 4-byte words in the format of the target processor. Labels are shown on Figure 7-5 to help explain note information organization, but they are not part of the specification.
The first namesz bytes in name contain a null-terminated character representation of the entry's owner or originator. There is no formal mechanism for avoiding name conflicts. By convention, vendors use their own name, such as "XYZ Computer Company," as the identifier. If no name is present, namesz contains 0. Padding is present, if necessary, to ensure 4-byte alignment for the descriptor. Such padding is not included in namesz.
The first descsz bytes in desc hold the note descriptor. If no descriptor is present, descsz contains 0. Padding is present, if necessary, to ensure 4-byte alignment for the next note entry. Such padding is not included in descsz.
This word gives the interpretation of the descriptor. Each originator controls its own types; multiple interpretations of a single type value can exist. Thus, a program must recognize both the name and the type to understand a descriptor. Types currently must be nonnegative.
To illustrate, the following note segment holds two entries.
The system reserves note information with no name (namesz == 0) and with a zero-length name (name[0] == '\0') but currently defines no types. All other names must have at least one non-null character.
If an element of a huge array is initialized, data for the entire array is written to the object file. The size of relocatable object files or executable files could be huge. The section SHT_SUNW_move has been introduced to help compress these files.
Objects created by the compilers or by the link-editors can contain move section for partially initialized symbols. This section is defined by the type SHT_SUNW_move. This section contains the multiple entries of the type ELF32_Move or Elf64_Move, which are defined as follows:
typedef struct { Elf32_Lword m_value; Elf32_Word m_info; Elf32_Word m_poffset; Elf32_Half m_repeat; Elf32_Half m_stride; } Elf32_Move; #define ELF32_M_SYM(info) ((info)>>8) #define ELF32_M_SIZE(info) ((unsigned char)(info)) #define ELF32_M_INFO(sym, size) (((sym)<<8)+(unsigned char)(size)) typedef struct { Elf64_Lword m_value; Elf64_Xword m_info; Elf64_Xword m_poffset; Elf64_Half m_repeat; Elf64_Half m_stride; } Elf64_Move; #define ELF64_M_SYM(info) ((info)>>8) #define ELF64_M_SIZE(info) ((unsigned char)(info)) #define ELF64_M_INFO(sym, size) (((sym)<<8)+(unsigned char)(size)) |
This is a offset relative to the symbol.
This member gives both the symbol table index, with respect to which the move must be made, and the size of the object to be moved in bytes. The lower 8 bits of the member holds the size and the upper bytes hold the symbol index. The size can be 1, 2, 4 or 8.
This member gives the repetition count.
This member gives the stride unit value. This member gives how many units should be skipped to perform the initialization. If the value is 0, it means that the initialization will be performed contiguously for m_repeat units.
This member gives the initialization value.