JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Linker and Libraries Guide
search filter icon
search icon

Document Information

Preface

1.  Introduction to the Oracle Solaris Link Editors

2.  Link-Editor

3.  Runtime Linker

4.  Shared Objects

5.  Application Binary Interfaces and Versioning

6.  Support Interfaces

7.  Object File Format

File Format

Data Representation

ELF Header

ELF Identification

Data Encoding

Sections

Section Merging

Special Sections

COMDAT Section

Group Section

Capabilities Section

Hash Table Section

Move Section

Note Section

Relocation Sections

Relocation Types (Processor-Specific)

SPARC: Relocation Types

64-bit SPARC: Relocation Types

32-bit x86: Relocation Types

x64: Relocation Types

String Table Section

Symbol Table Section

Symbol Values

Symbol Table Layout and Conventions

Symbol Sort Sections

Register Symbols

Syminfo Table Section

Versioning Sections

Version Definition Section

Version Dependency Section

Version Symbol Section

Dynamic Linking

Program Header

Base Address

Segment Permissions

Segment Contents

Program Loading (Processor-Specific)

Program Interpreter

Runtime Linker

Dynamic Section

Global Offset Table (Processor-Specific)

Procedure Linkage Table (Processor-Specific)

32-bit SPARC: Procedure Linkage Table

64-bit SPARC: Procedure Linkage Table

32-bit x86: Procedure Linkage Table

x64: Procedure Linkage Table

8.  Thread-Local Storage

9.  Mapfiles

A.  Link-Editor Quick Reference

B.  Versioning Quick Reference

C.  Establishing Dependencies with Dynamic String Tokens

D.  Direct Bindings

E.  System V Release 4 (Version 1) Mapfiles

F.  Linker and Libraries Updates and New Features

Index

File Format

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. The following figure shows an object file's organization.

Figure 7-1 Object File Format

Object file formats.

An ELF header resides at the beginning of an object file and holds a road map describing the file's organization.


Note - Only the ELF header has a fixed position in the file. The flexibility of the ELF format requires no specified order for header tables, sections or segments. However, this figure is typical of the layout used in the Oracle Solaris OS.


Sections represent the smallest indivisible units that can be processed within an ELF file. Segments are a collection of sections. Segments 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. This data includes instructions, data, symbol table, and relocation information. 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 generate a process image, executable files and shared objects, must have a program header table. Relocatable object files do not need a program header table.

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 and section size. Files that are used in link-editing must have a section header table.

Data Representation

The object file format supports various processors with 8-bit bytes, 32–bit architectures and 64–bit architectures. Nevertheless, the data representation is intended to be extensible to larger, or smaller, architectures. Table 7-1 and Table 7-2 list the 32–bit data types and 64–bit data types.

Object files represent some control data with a machine-independent format. This format provides for the common identification and interpretation of object files. The 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 ELF 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 ELF 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. Data structures can 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 is aligned on a 4-byte boundary within the file. Similarly, a structure containing an Elf64_Addr member is aligned on an 8–byte boundary.


Note - For portability, ELF uses no bit-fields.


ELF Header

Some control structures within object files can grow because the ELF header contains their actual sizes. If the object file format does change, 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 is specified if and when extensions are defined.

The ELF header has the following structure. See 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;
e_ident

The initial bytes mark the file as an object file. These bytes provide machine-independent data with which to decode and interpret the file's contents. Complete descriptions appear in ELF Identification.

e_type

Identifies the object file type, as listed in the following table.

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 for future use.

e_machine

Specifies the required architecture for an individual file. Relevant architectures are listed in the following table.

Name
Value
Meaning
EM_NONE
0
No machine
EM_SPARC
2
SPARC
EM_386
3
Intel 80386
EM_SPARC32PLUS
18
Sun SPARC 32+
EM_SPARCV9
43
SPARC V9
EM_AMD64
62
AMD 64

Other values are reserved for future use. Processor-specific ELF names are distinguished by using the machine name. For example, the flags defined for e_flags use the prefix EF_. A flag that is named WIDGET for the EM_XYZ machine would be called EF_XYZ_WIDGET.

e_version

Identifies the object file version, as listed in the following table.

Name
Value
Meaning
EV_NONE
0
Invalid version
EV_CURRENT
>=1
Current version

The value 1 signifies the original file format. The value of EV_CURRENT changes as necessary to reflect the current version number.

e_entry

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.

e_phoff

The program header table's file offset in bytes. If the file has no program header table, this member holds zero.

e_shoff

The section header table's file offset in bytes. If the file has no section header table, this member holds zero.

e_flags

Processor-specific flags associated with the file. Flag names take the form EF_machine_flag. This member is presently zero for x86. The SPARC flags are listed in the following table.

Name
Value
Meaning
EF_SPARC_EXT_MASK
0xffff00
Vendor Extension mask
EF_SPARC_32PLUS
0x000100
Generic V8+ features
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
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
e_ehsize

The ELF header's size in bytes.

e_phentsize

The size in bytes of one entry in the file's program header table. All entries are the same size.

e_phnum

The number of entries in the program header table. 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.

If the number of program headers is greater than or equal to PN_XNUM (0xffff), this member has the value PN_XNUM (0xffff). The actual number of program header table entries is contained in the sh_info field of the section header at index 0. Otherwise, the sh_info member of the initial section header entry contains the value zero. See Table 7-6 and Table 7-7.

e_shentsize

A section header's size in bytes. A section header is one entry in the section header table. All entries are the same size.

e_shnum

The number of entries in the section header table. 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.

If the number of sections is greater than or equal to SHN_LORESERVE (0xff00), e_shnum has the value zero. The actual number of section header table entries is contained in the sh_size field of the section header at index 0. Otherwise, the sh_size member of the initial section header entry contains the value zero. See Table 7-6 and Table 7-7.

e_shstrndx

The section header table index of the entry that is associated with the section name string table. If the file has no section name string table, this member holds the value SHN_UNDEF.

If the section name string table section index is greater than or equal to SHN_LORESERVE (0xff00), this member has the value SHN_XINDEX (0xffff) and the actual index of the section name string table section is contained in the sh_link field of the section header at index 0. Otherwise, the sh_link member of the initial section header entry contains the value zero. See Table 7-6 and Table 7-7.

ELF Identification

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. These bytes are 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-3 ELF 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_OSABI
7
Operating system/ABI identification
EI_ABIVERSION
8
ABI version
EI_PAD
9
Start of padding bytes
EI_NIDENT
16
Size of e_ident[]

These indexes access bytes that hold the following values.

EI_MAG0 - EI_MAG3

A 4–byte magic number, identifying the file as an ELF object file, as listed in the following table.

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]
EI_CLASS

Byte e_ident[EI_CLASS] identifies the file's class, or capacity, as listed in the following table.

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. The class of the file defines the basic types used by the data structures of the object file container. The data that is contained in object file sections can follow a different programming model.

Class ELFCLASS32 supports machines with files and virtual address spaces up to 4 gigabytes. This class uses the basic types that are defined in Table 7-1.

Class ELFCLASS64 is reserved for 64–bit architectures such as 64–bit SPARC and x64. This class uses the basic types that are defined in Table 7-2.

EI_DATA

Byte e_ident[EI_DATA] specifies the data encoding of the processor-specific data in the object file, as listed in the following table.

Name
Value
Meaning
ELFDATANONE
0
Invalid data encoding
ELFDATA2LSB
1
ELFDATA2MSB
2

More information on these encodings appears in the section Data Encoding. Other values are reserved for future use.

EI_VERSION

Byte e_ident[EI_VERSION] specifies the ELF header version number. Currently, this value must be EV_CURRENT.

EI_OSABI

Byte e_ident[EI_OSABI] identifies the operating system together with the ABI to which the object is targeted. Some fields in other ELF structures have flags and values that have operating system or ABI specific meanings. The interpretation of those fields is determined by the value of this byte.

EI_ABIVERSION

Byte e_ident[EI_ABIVERSION] identifies the version of the ABI to which the object is targeted. This field is used to distinguish among incompatible versions of an ABI. The interpretation of this version number is dependent on the ABI identified by the EI_OSABI field. If no values are specified for the EI_OSABI field for the processor, or no version values are specified for the ABI determined by a particular value of the EI_OSABI byte, the value zero is used to indicate unspecified.

EI_PAD

This value marks the beginning of the unused bytes in e_ident. These bytes are reserved and are set to zero. Programs that read object files should ignore these values.

Data Encoding

A file's data encoding specifies how to interpret the integer types in a file. Class ELFCLASS32 files and class ELFCLASS64 files use integers that occupy 1, 2, 4, and 8 bytes to represent offsets, addresses and other information. Under the defined encodings, objects are represented as described by the figures that follow. Byte numbers appear in the upper left corners.

ELFDATA2LSB encoding specifies 2's complement values, with the least significant byte occupying the lowest address. This encoding if often referred to informally as little endian.

Figure 7-2 Data Encoding ELFDATA2LSB

ELFDATA2LSB data encoding.

ELFDATA2MSB encoding specifies 2's complement values, with the most significant byte occupying the lowest address. This encoding if often referred to informally as big endian.

Figure 7-3 Data Encoding ELFDATA2MSB

ELFDATA2MSB data encoding.

Sections

An object file's section header table allows you to locate all of the sections of the file. The section header table is an array of Elf32_Shdr or Elf64_Shdr structures. A section header table index is a subscript into this array. The ELF header's e_shoff member indicates the byte offset from the beginning of the file to the section header table. The e_shnum member indicates how many entries that the section header table contains. The e_shentsize member indicates the size in bytes of each entry.

If the number of sections is greater than or equal to SHN_LORESERVE (0xff00), e_shnum has the value SHN_UNDEF (0). The actual number of section header table entries is contained in the sh_size field of the section header at index 0. Otherwise, the sh_size member of the initial entry contains the value zero.

Some section header table indexes are reserved in contexts where index size is restricted. For example, the st_shndx member of a symbol table entry and the e_shnum and e_shstrndx members of the ELF header. In such contexts, the reserved values do not represent actual sections in the object file. Also in such contexts, an escape value indicates that the actual section index is to be found elsewhere, in a larger field.

Table 7-4 ELF Special Section Indexes

Name
Value
SHN_UNDEF
0
SHN_LORESERVE
0xff00
SHN_LOPROC
0xff00
SHN_BEFORE
0xff00
SHN_AFTER
0xff01
SHN_AMD64_LCOMMON
0xff02
SHN_HIPROC
0xff1f
SHN_LOOS
0xff20
SHN_LOSUNW
0xff3f
SHN_SUNW_IGNORE
0xff3f
SHN_HISUNW
0xff3f
SHN_HIOS
0xff3f
SHN_ABS
0xfff1
SHN_COMMON
0xfff2
SHN_XINDEX
0xffff
SHN_HIRESERVE
0xffff

Note - 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 indicates a file has 6 entries in the section header table, the sections have the indexes 0 through 5. The contents of the initial entry are specified later in this section.


SHN_UNDEF

An undefined, missing, irrelevant, or otherwise meaningless section reference. For example, a symbol defined relative to section number SHN_UNDEF is an undefined symbol.

SHN_LORESERVE

The lower boundary of the range of reserved indexes.

SHN_LOPROC - SHN_HIPROC

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

SHN_LOOS - SHN_HIOS

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

SHN_LOSUNW - SHN_HISUNW

Values in this inclusive range are reserved for Sun-specific semantics.

SHN_SUNW_IGNORE

This section index provides a temporary symbol definition within relocatable objects. Reserved for internal use by dtrace(1M).

SHN_BEFORE, SHN_AFTER

Provide for initial and final section ordering in conjunction with the SHF_LINK_ORDER and SHF_ORDERED section flags. See Table 7-8.

SHN_AMD64_LCOMMON

x64 specific common block label. This label is similar to SHN_COMMON, but provides for identifying a large common block.

SHN_ABS

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. These symbols are sometimes referred to as tentative.

SHN_XINDEX

An escape value indicating that the actual section header index is too large to fit in the containing field. The header section index is found in another location specific to the structure where the section index appears.

SHN_HIRESERVE

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. 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, the sections in object files satisfy several conditions.

A section header has the following structure. See 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;
sh_name

The name of the section. This members value is an index into the section header string table section giving the location of a null-terminated string. Section names and their descriptions are listed in Table 7-10.

sh_type

Categorizes the section's contents and semantics. Section types and their descriptions are listed in Table 7-5.

sh_flags

Sections support 1-bit flags that describe miscellaneous attributes. Flag definitions are listed in Table 7-8.

sh_addr

If the section appears 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 the value zero.

sh_offset

The byte offset from the beginning of the file to the first byte in the section. For a SHT_NOBITS section, this member indicates the conceptual offset in the file, as the section occupies no space in the file.

sh_size

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 the section occupies no space in the file.

sh_link

A section header table index link, whose interpretation depends on the section type. Table 7-9 describes the values.

sh_info

Extra information, whose interpretation depends on the section type. Table 7-9 describes the values. If the sh_flags field for this section header includes the attribute SHF_INFO_LINK, then this member represents a section header table index.

sh_addralign

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. In this case, 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 the value zero 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-5 ELF 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_INIT_ARRAY
14
SHT_FINI_ARRAY
15
SHT_PREINIT_ARRAY
16
SHT_GROUP
17
SHT_SYMTAB_SHNDX
18
SHT_LOOS
0x60000000
SHT_LOSUNW
0x6fffffef
SHT_SUNW_capchain
0x6fffffef
SHT_SUNW_capinfo
0x6ffffff0
SHT_SUNW_symsort
0x6ffffff1
SHT_SUNW_tlssort
0x6ffffff2
SHT_SUNW_LDYNSYM
0x6ffffff3
SHT_SUNW_dof
0x6ffffff4
SHT_SUNW_cap
0x6ffffff5
SHT_SUNW_SIGNATURE
0x6ffffff6
SHT_SUNW_ANNOTATE
0x6ffffff7
SHT_SUNW_DEBUGSTR
0x6ffffff8
SHT_SUNW_DEBUG
0x6ffffff9
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_HISUNW
0x6fffffff
SHT_HIOS
0x6fffffff
SHT_LOPROC
0x70000000
SHT_SPARC_GOTDATA
0x70000000
SHT_AMD64_UNWIND
0x70000001
SHT_HIPROC
0x7fffffff
SHT_LOUSER
0x80000000
SHT_HIUSER
0xffffffff
SHT_NULL

Identifies the section header as inactive. This section header does not have an associated section. Other members of the section header have undefined values.

SHT_PROGBITS

Identifies information defined by the program, whose format and meaning are determined solely by the program.

SHT_SYMTAB, SHT_DYNSYM, SHT_SUNW_LDYNSYM

Identifies a symbol table. Typically, a SHT_SYMTAB section provides symbols for link-editing. As a complete symbol table, the table can contain many symbols that are 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.

SHT_DYNSYM can also be augmented with a SHT_SUNW_LDYNSYM section. This additional section provides local function symbols to the runtime environment, but is not required for dynamic linking. This section allows debuggers to produce accurate stack traces in runtime contexts when the non-allocable SHT_SYMTAB is not available, or has been stripped from the file. This section also provides the runtime environment with additional symbolic information for use with dladdr(3C).

When both a SHT_SUNW_LDYNSYM section and a SHT_DYNSYM section exist, the link-editor places their data regions immediately adjacent to each other. The SHT_SUNW_LDYNSYM section precedes the SHT_DYNSYM section. This placement allows the two tables to be viewed as a single larger contiguous symbol table, containing a reduced set of symbols from SHT_SYMTAB.

See Symbol Table Section for details.

SHT_STRTAB, SHT_DYNSTR

Identifies a string table. An object file can have multiple string table sections. See String Table Section for details.

SHT_RELA

Identifies 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 Sections for details.

SHT_HASH

Identifies a symbol hash table. A dynamically linked object file 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 Section for details.

SHT_DYNAMIC

Identifies information for dynamic linking. Currently, an object file can have only one dynamic section. See Dynamic Section for details.

SHT_NOTE

Identifies information that marks the file in some way. See Note Section for details.

SHT_NOBITS

Identifies a section that 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

Identifies 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 Sections for details.

SHT_SHLIB

Identifies a reserved section which has unspecified semantics. Programs that contain a section of this type do not conform to the ABI.

SHT_INIT_ARRAY

Identifies a section containing an array of pointers to initialization functions. Each pointer in the array is taken as a parameterless procedure with a void return. See Initialization and Termination Sections for details.

SHT_FINI_ARRAY

Identifies a section containing an array of pointers to termination functions. Each pointer in the array is taken as a parameterless procedure with a void return. See Initialization and Termination Sections for details.

SHT_PREINIT_ARRAY

Identifies a section containing an array of pointers to functions that are invoked before all other initialization functions. Each pointer in the array is taken as a parameterless procedure with a void return. See Initialization and Termination Sections for details.

SHT_GROUP

Identifies a section group. A section group identifies a set of related sections that must be treated as a unit by the link-editor. Sections of type SHT_GROUP can appear only in relocatable objects. See Group Section for details.

SHT_SYMTAB_SHNDX

Identifies a section containing extended section indexes, that are associated with a symbol table. If any section header indexes referenced by a symbol table, contain the escape value SHN_XINDEX, an associated SHT_SYMTAB_SHNDX is required.

The SHT_SYMTAB_SHNDX section is an array of Elf32_Word values. This array contains one entry for every entry in the associated symbol table entry. The values represent the section header indexes against which the symbol table entries are defined. Only if corresponding symbol table entry's st_shndx field contains the escape value SHN_XINDEX will the matching Elf32_Word hold the actual section header index. Otherwise, the entry must be SHN_UNDEF (0).

SHT_LOOSSHT_HIOS

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

SHT_LOSUNWSHT_HISUNW

Values in this inclusive range are reserved for Oracle Solaris OS semantics.

SHT_SUNW_capchain

An array of indices that collect capability family members. The first element of the array is the chain version number. Following this element are a chain of 0 terminated capability symbol indices. Each 0 terminated group of indices represents a capabilities family. The first element of each family is the capabilities lead symbol. The following elements point to family members. See Capabilities Section for details.

SHT_SUNW_capinfo

An array of indices that associate symbol table entries to capabilities requirements, and their lead capabilities symbol. An object that defines symbol capabilities contains a SHT_SUNW_cap section. The SHT_SUNW_cap section header information points to the associated SHT_SUNW_capinfo section. The SHT_SUNW_capinfo section header information points to the associated symbol table section. See Capabilities Section for details.

SHT_SUNW_symsort

An array of indices into the dynamic symbol table that is formed by the adjacent SHT_SUNW_LDYNSYM section and SHT_DYNSYM section. These indices are relative to the start of the SHT_SUNW_LDYNSYM section. The indices reference those symbols that contain memory addresses. The indices are sorted such that the indices reference the symbols by increasing address.

SHT_SUNW_tlssort

An array of indices into the dynamic symbol table that is formed by the adjacent SHT_SUNW_LDYNSYM section and SHT_DYNSYM section. These indices are relative to the start of the SHT_SUNW_LDYNSYM section. The indices reference thread-local storage symbols. See Chapter 8, Thread-Local Storage. The indices are sorted such that the indices reference the symbols by increasing offset.

SHT_SUNW_LDYNSYM

Dynamic symbol table for non-global symbols. See previous SHT_SYMTAB, SHT_DYNSYM, SHT_SUNW_LDYNSYM description.

SHT_SUNW_dof

Reserved for internal use by dtrace(1M).

SHT_SUNW_cap

Specifies capability requirements. See Capabilities Section for details.

SHT_SUNW_SIGNATURE

Identifies module verification signature.

SHT_SUNW_ANNOTATE

The processing of an annotate section follows all of the default rules for processing a section. The only exception occurs if the annotate section is in non-allocatable memory. If the section header flag SHF_ALLOC is not set, the link-editor silently ignores any unsatisfied relocations against this section.

SHT_SUNW_DEBUGSTR, SHT_SUNW_DEBUG

Identifies debugging information. Sections of this type are stripped from the object using the link-editor's -s option, or after the link-edit using strip(1).

SHT_SUNW_move

Identifies data to handle partially initialized symbols. See Move Section for details.

SHT_SUNW_COMDAT

Identifies a section that allows multiple copies of the same data to be reduced to a single copy. See COMDAT Section for details.

SHT_SUNW_syminfo

Identifies additional symbol information. See Syminfo Table Section for details.

SHT_SUNW_verdef

Identifies fine-grained versions defined by this file. See Version Definition Section for details.

SHT_SUNW_verneed

Identifies fine-grained dependencies required by this file. See Version Dependency Section for details.

SHT_SUNW_versym

Identifies a table describing the relationship of symbols to the version definitions offered by the file. See Version Symbol Section for details.

SHT_LOPROC - SHT_HIPROC

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

SHT_SPARC_GOTDATA

Identifies SPARC specific data, referenced using GOT-relative addressing. That is, offsets relative to the address assigned to the symbol _GLOBAL_OFFSET_TABLE_. For 64–bit SPARC, data in this section must be bound at link-edit time to locations within {+-} 2^32 bytes of the GOT address.

SHT_AMD64_UNWIND

Identifies x64 specific data, containing unwind function table entries for stack unwinding.

SHT_LOUSER

Specifies the lower boundary of the range of indexes that are reserved for application programs.

SHT_HIUSER

Specifies the upper boundary of the range of indexes that are 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-6 ELF 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

Should the number of sections or program headers exceed the ELF header data sizes, elements of section header 0 are used to define extended ELF header attributes. The following table shows the values.

Table 7-7 ELF Extended 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
e_shnum
The number of entries in the section header table
sh_link
e_shstrndx
The section header index of the entry that is associated with the section name string table
sh_info
e_phnum
The number of entries in the program header table
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-8 ELF 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_TLS
0x400
SHF_MASKOS
0x0ff00000
SHF_AMD64_LARGE
0x10000000
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 are set to zero.

SHF_WRITE

Identifies a section that should be writable during process execution.

SHF_ALLOC

Identifies a section that 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

Identifies a section that contains executable machine instructions.

SHF_MERGE

Identifies a section containing data that can 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.

SHF_STRINGS

Identifies a section that consists of null-terminated character strings. The size of each character is specified in the section header's sh_entsize field.

SHF_INFO_LINK

This section headers sh_info field holds a section header table index.

SHF_LINK_ORDER

This section 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, the section appears in the same relative order with respect to those sections. Similarly the linked-to section appears with respect to sections the linked-to section is combined with. The linked-to section must be unordered, and cannot in turn specify SHF_LINK_ORDER or SHF_ORDERED.

The special sh_link values SHN_BEFORE and SHN_AFTER (see Table 7-4) 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.

In the absence of the sh_link ordering information, sections from a single input file combined within one section of the output file are contiguous. These section have the same relative ordering as the sections did in the input file. The contributions from multiple input files appear in link-line 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 the link-editor does not recognize these values, then the object file containing this section is rejected with an error.

SHF_GROUP

This section is a member, perhaps the only member, 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 that are contained in relocatable objects. See Group Section for details.

SHF_TLS

This section holds thread-local storage. Each thread within a process has a distinct instance of this data. See Chapter 8, Thread-Local Storage for details.

SHF_MASKOS

All bits that are included in this mask are reserved for operating system-specific semantics.

SHF_AMD64_LARGE

The default compilation model for x64 only provides for 32–bit displacements. This displacement limits the size of sections, and eventually segments, to 2 Gbytes. This attribute flag identifies a section that can hold more than 2 Gbyte. This flag allows the linking of object files that use different code models.

An x64 object file section that does not contain the SHF_AMD64_LARGE attribute flag can be freely referenced by objects using small code models. A section that contains this flag can only be referenced by objects that use larger code models. For example, an x64 medium code model object can refer to data in sections that contain the attribute flag and sections that do not contain the attribute flag. However, an x64 small code model object can only refer to data in a section that does not contain this flag.

SHF_ORDERED

SHF_ORDERED is an older version of the functionality provided by SHF_LINK_ORDER, and has been superseded by SHF_LINK_ORDER. SHF_ORDERED offers two distinct and separate abilities. First, an output section can be specified, and second, special ordering requirements are required from the link-editor.

The sh_link field of an SHF_ORDERED section forms a linked list of sections. This list is terminated by a final section with a sh_link that points at itself. All sections in this list are assigned to the output section with the name of the final section in the list.

If the sh_info entry of the ordered section is a valid section within the same input file, the ordered section is sorted based on the relative ordering within the output file of the section pointed to by the sh_info entry. The section pointed at by the sh_info entry must be unordered, and cannot in turn specify SHF_LINK_ORDER or SHF_ORDERED.

The special sh_info values SHN_BEFORE and SHN_AFTER (see Table 7-4) 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 are contiguous. These sections have the same relative ordering as the sections appear in the input file. The contributions from multiple input files appear in link-line order.

SHF_EXCLUDE

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.

SHF_MASKPROC

All bits that are 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-9 ELF 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.
If the sh_flags member contains the SHF_INFO_LINK flag, the section header index of the section to which the relocation applies, otherwise 0. See also Table 7-10 and Relocation Sections.
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, STB_LOCAL.
SHT_GROUP
The section header index of the associated symbol table.
The symbol table index of an entry in the associated symbol table. The name of the specified symbol table entry provides a signature for the section group.
SHT_SYMTAB_SHNDX
The section header index of the associated symbol table.
0
SHT_SUNW_cap
If symbol capabilities exist, the section header index of the associated SHT_SUNW_capinfo table, otherwise 0.
If any capabilities refer to named strings, the section header index of the associated string table, otherwise 0.
SHT_SUNW_capinfo
The section header index of the associated symbol table.
For a dynamic object, the section header index of the associated SHT_SUNW_capchain table, otherwise 0.
SHT_SUNW_symsort
The section header index of the associated symbol table.
0
SHT_SUNW_tlssort
The section header index of the associated symbol table.
0
SHT_SUNW_LDYNSYM
The section header index of the associated string table. This index is the same string table used by the SHT_DYNSYM section.
One greater than the symbol table index of the last local symbol, STB_LOCAL. Since SHT_SUNW_LDYNSYM only contains local symbols, sh_info is equivalent to the number of symbols in the table.
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

Section Merging

The SHF_MERGE section flag can be used to mark SHT_PROGBITS sections within relocatable objects. See Table 7-8. This flag indicates that the section can be merged with compatible sections from other objects. Such merging has the potential to reduce the size of any executable or shared object that is built from these relocatable objects. This size reduction can also have a positive effect on the runtime performance of the resulting object.

A SHF_MERGE flagged section indicates that the section adheres to the following characteristics.

SHF_MERGE is an optional flag indicating a possible optimization. The link-editor is allowed to perform the optimization, or to ignore the optimization. The link-editor creates a valid output object in either case. The link-editor presently implements section merging only for sections containing string data marked with the SHF_STRINGS flag.

When the SHF_STRINGS section flag is set in conjunction with the SHF_MERGE flag, the strings in the section are available to be merged with strings from other compatible sections. The link-editor merges such sections using the same string compression algorithm as used to compress the SHT_STRTAB string tables, .strtab and .dynstr.

The link-editor currently implements string merging only for strings that consist of byte sized characters that do not have special alignment constraints. Specifically, the following section characteristics are required.


Note - Any string table compression can be suppressed with the link-editors -z nocompstrtab option.


Special Sections

Various sections hold program and control information. Sections in the following table are used by the system and have the indicated types and attributes.

Table 7-10 ELF Special Sections

Name
Type
Attribute
.bss
SHT_NOBITS
SHF_ALLOC + SHF_WRITE
.comment
SHT_PROGBITS
None
.data, .data1
SHT_PROGBITS
SHF_ALLOC + SHF_WRITE
.dynamic
SHT_DYNAMIC
SHF_ALLOC + SHF_WRITE
.dynstr
SHT_STRTAB
SHF_ALLOC
.dynsym
SHT_DYNSYM
SHF_ALLOC
.eh_frame_hdr
SHT_AMD64_UNWIND
SHF_ALLOC
.eh_frame
SHT_AMD64_UNWIND
SHF_ALLOC + SHF_WRITE
.fini
SHT_PROGBITS
SHF_ALLOC + SHF_EXECINSTR
.fini_array
SHT_FINI_ARRAY
SHF_ALLOC + SHF_WRITE
.got
SHT_PROGBITS
.hash
SHT_HASH
SHF_ALLOC
.init
SHT_PROGBITS
SHF_ALLOC + SHF_EXECINSTR
.init_array
SHT_INIT_ARRAY
SHF_ALLOC + SHF_WRITE
.interp
SHT_PROGBITS
.note
SHT_NOTE
None
.lbss
SHT_NOBITS
SHF_ALLOC + SHF_WRITE + SHF_AMD64_LARGE
.ldata, .ldata1
SHT_PROGBITS
SHF_ALLOC + SHF_WRITE + SHF_AMD64_LARGE
.lrodata, .lrodata1
SHT_PROGBITS
SHF_ALLOC + SHF_AMD64_LARGE
.plt
SHT_PROGBITS
.preinit_array
SHT_PREINIT_ARRAY
SHF_ALLOC + SHF_WRITE
.rela
SHT_RELA
None
.relname
SHT_REL
.relaname
SHT_RELA
.rodata, .rodata1
SHT_PROGBITS
SHF_ALLOC
.shstrtab
SHT_STRTAB
None
.strtab
SHT_STRTAB
Refer to the explanation following this table.
.symtab
SHT_SYMTAB
.symtab_shndx
SHT_SYMTAB_SHNDX
.tbss
SHT_NOBITS
SHF_ALLOC + SHF_WRITE + SHF_TLS
.tdata, .tdata1
SHT_PROGBITS
SHF_ALLOC + SHF_WRITE + SHF_TLS
.text
SHT_PROGBITS
SHF_ALLOC + SHF_EXECINSTR
.SUNW_bss
SHT_NOBITS
SHF_ALLOC + SHF_WRITE
.SUNW_cap
SHT_SUNW_cap
SHF_ALLOC
.SUNW_capchain
SHT_SUNW_capchain
SHF_ALLOC
.SUNW_capinfo
SHT_SUNW_capinfo
SHF_ALLOC
.SUNW_heap
SHT_PROGBITS
SHF_ALLOC + SHF_WRITE
.SUNW_ldynsym
SHT_SUNW_LDYNSYM
SHF_ALLOC
.SUNW_dynsymsort
SHT_SUNW_symsort
SHF_ALLOC
.SUNW_dymtlssort
SHT_SUNW_tlssort
SHF_ALLOC
.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
.bss

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.

.comment

Comment information, typically contributed by the components of the compilation system. This section can be manipulated by mcs(1).

.data, .data1

Initialized data that contribute to the program's memory image.

.dynamic

Dynamic linking information. See Dynamic Section for details.

.dynstr

Strings needed for dynamic linking, most commonly the strings that represent the names associated with symbol table entries.

.dynsym

Dynamic linking symbol table. See Symbol Table Section for details.

.eh_frame_hdr, .eh_frame

Call frame information used to unwind the stack.

.fini

Executable instructions that contribute to a single termination function for the executable or shared object containing the section. See Initialization and Termination Routines for details.

.fini_array

An array of function pointers that contribute to a single termination array for the executable or shared object containing the section. See Initialization and Termination Routines for details.

.got

The global offset table. See Global Offset Table (Processor-Specific) for details.

.hash

Symbol hash table. See Hash Table Section for details.

.init

Executable instructions that contribute to a single initialization function for the executable or shared object containing the section. See Initialization and Termination Routines for details.

.init_array

An array of function pointers that contributes to a single initialization array for the executable or shared object containing the section. See Initialization and Termination Routines for details.

.interp

The path name of a program interpreter. See Program Interpreter for details.

.lbss

x64 specific uninitialized data. This data is similar to .bss, but provides for a section that is larger than 2 Gbytes.

.ldata, .ldata1

x64 specific initialized data. This data is similar to .data, but provides for a section that is larger than 2 Gbytes.

.lrodata, .lrodata1

x64 specific read-only data. This data is similar to .rodata, but provides for a section that is larger than 2 Gbytes.

.note

Information in the format described in Note Section.

.plt

The procedure linkage table. See Procedure Linkage Table (Processor-Specific) for details.

.preinit_array

An array of function pointers that contribute to a single pre-initialization array for the executable or shared object containing the section. See Initialization and Termination Routines for details.

.rela

Relocations that do not apply to a particular section. One use of this section is for register relocations. See Register Symbols for details.

.relname, .relaname

Relocation information, as Relocation Sections describes. If the file has a loadable segment that includes relocation, the sections' attributes include the SHF_ALLOC bit. Otherwise, that bit is 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.

.rodata, .rodata1

Read-only data that typically contribute to a non-writable segment in the process image. See Program Header for details.

.shstrtab

Section names.

.strtab

Strings, most commonly the strings that represent the names that are associated with symbol table entries. If the file has a loadable segment that includes the symbol string table, the section's attributes include the SHF_ALLOC bit. Otherwise, that bit is turned off.

.symtab

Symbol table, as Symbol Table Section describes. If the file has a loadable segment that includes the symbol table, the section's attributes include the SHF_ALLOC bit. Otherwise, that bit is turned off.

.symtab_shndx

This section holds the special symbol table section index array, as described by .symtab. The section's attributes include the SHF_ALLOC bit if the associated symbol table section does. Otherwise, that bit is turned off.

.tbss

This section holds uninitialized thread-local data that contribute to the program's memory image. By definition, the system initializes the data with zeros when the data is instantiated for each new execution flow. The section occupies no file space, as indicated by the section type, SHT_NOBITS. See Chapter 8, Thread-Local Storage for details.

.tdata, .tdata1

These sections hold initialized thread-local data that contribute to the program's memory image. A copy of its contents is instantiated by the system for each new execution flow. See Chapter 8, Thread-Local Storage for details.

.text

The text or executable instructions of a program.

.SUNW_bss

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.

.SUNW_cap

Capability requirements. See Capabilities Section for details.

.SUNW_capchain

Capability chain table. See Capabilities Section for details.

.SUNW_capinfo

Capability symbol information. See Capabilities Section for details.

.SUNW_heap

The heap of a dynamic executable created from dldump(3C).

.SUNW_dynsymsort

An array of indices to symbols in the combined .SUNW_ldynsym.dynsym symbol table. The indices are sorted to reference symbols in order of increasing address. Symbols that do not represent variables or do not represent functions are not included. In the case of redundant global symbols and weak symbols, only the weak symbol is kept. See Symbol Sort Sections for details.

.SUNW_dyntlssort

An array of indices to thread-local storage symbols in the combined .SUNW_ldynsym.dynsym symbol table. The indices are sorted to reference symbols in order of increasing offset. Symbols that do not represent TLS variables are not included. In the case of redundant global symbols and weak symbols, only the weak symbol is kept. See Symbol Sort Sections for details.

.SUNW_ldynsym

Augments the .dynsym section. This section contains local function symbols, for use in contexts where the full .symtab section is not available. The link-editor always places the data for a .SUNW_ldynsym section immediately before, and adjacent to, the .dynsym section. Both sections always use the same .dynstr string table section. This placement and organization, allows both symbol tables to be treated as a single larger symbol table. See Symbol Table Section.

.SUNW_move

Additional information for partially initialized data. See Move Section for details.

.SUNW_reloc

Relocation information, as Relocation Sections 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 is meaningful, thus the section sh_info value is zero.

.SUNW_syminfo

Additional symbol table information. See Syminfo Table Section for details.

.SUNW_version

Versioning information. See Versioning Sections for details.

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 enables you to define sections that are not reserved. An object file can have more than one section with the same name.

Section names that are 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 that are used for e_machine. For example, .Foo.psect is the psect section defined by the FOO architecture.

Existing extensions use their historical names

COMDAT Section

COMDAT sections are 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 section is retained and the rest discarded. Any relocations that are applied to a discarded SHT_SUNW_COMDAT section are ignored. Any symbols that are defined in a discarded section are removed.

Additionally, the link-editor supports the section naming convention that is used for section reordering when the compiler is invoked with the -xF option. If a function is placed in a SHT_SUNW_COMDAT section that is named .sectname%funcname, the final SHT_SUNW_COMDAT sections that are retained are coalesced into the section that is named .sectname. This method can be used to place SHT_SUNW_COMDAT sections into the .text, .data, or any other section as their final destination.

Group Section

Some sections occur in interrelated groups. For example, an out-of-line definition of an inline function might require additional information besides the section containing executable instructions. This additional information can be a read-only data section containing literals referenced, one or more debugging information sections, or other informational sections.

There can be internal references among group sections. However, these references make no sense if one of the sections were removed, or one of the sections were replaced by a duplicate from another object. Therefore, these groups are included, or these groups are omitted, from the linked object as a unit.

A section of type SHT_GROUP defines such a grouping of sections. The name of a symbol from one of the containing object's symbol tables provides a signature for the section group. The section header of the SHT_GROUP section specifies the identifying symbol entry. The sh_link member contains the section header index of the symbol table section that contains the entry. The sh_info member contains the symbol table index of the identifying entry. The sh_flags member of the section header contains the value zero. The name of the section (sh_name) is not specified.

The section data of a SHT_GROUP section is an array of Elf32_Word entries. The first entry is a flag word. The remaining entries are a sequence of section header indices.

The following flag is currently defined.

Table 7-11 ELF Group Section Flag

Name
Value
GRP_COMDAT
0x1
GRP_COMDAT

GRP_COMDAT is a COMDAT group. This group can duplicate another COMDAT group in another object file, where duplication is defined as having the same group signature. In such cases, only one of the duplicate groups is retained by the link-editor. The members of the remaining groups are discarded.

The section header indices in the SHT_GROUP section, identify the sections that make up the group. These sections must have the SHF_GROUP flag set in their sh_flags section header member. If the link-editor decides to remove the section group, the link-editor removes all members of the group.

To facilitate removing a group without leaving dangling references and with only minimal processing of the symbol table, the following rules are followed.

Capabilities Section

A SHT_SUNW_cap section identifies the capability requirements of an object. These capabilities are referred to as object capabilities. This section can also identify the capability requirements of functions, or initialized data items, within an object. These capabilities are referred to as symbol capabilities. This section contains an array of the following structures. See sys/elf.h.

typedef struct {
        Elf32_Word      c_tag;
        union {
                Elf32_Word      c_val;
                Elf32_Addr      c_ptr;
        } c_un;
} Elf32_Cap;

typedef struct {
        Elf64_Xword     c_tag;
        union {
                Elf64_Xword     c_val;
                Elf64_Addr      c_ptr;
        } c_un;
} Elf64_Cap;

For each object with this type, c_tag controls the interpretation of c_un.

c_val

These objects represent integer values with various interpretations.

c_ptr

These objects represent program virtual addresses.

The following capabilities tags exist.

Table 7-12 ELF Capability Array Tags

Name
Value
c_un
CA_SUNW_NULL
0
Ignored
CA_SUNW_HW_1
1
c_val
CA_SUNW_SF_1
2
c_val
CA_SUNW_HW_2
3
c_val
CA_SUNW_PLAT
4
c_ptr
CA_SUNW_MACH
5
c_ptr
CA_SUNW_ID
6
c_ptr
CA_SUNW_NULL

Marks the end of a group of capabilities.

CA_SUNW_HW_1, CA_SUNW_HW_2

Indicates hardware capability values. The c_val element contains a value that represents the associated hardware capabilities. On SPARC platforms, hardware capabilities are defined in sys/auxv_SPARC.h. On x86 platforms, hardware capabilities are defined in sys/auxv_386.h.

CA_SUNW_SF_1

Indicates software capability values. The c_val element contains a value that represents the associated software capabilities that are defined in sys/elf.h.

CA_SUNW_PLAT

Specifies a platform name. The c_ptr element contains the string table offset of a null-terminated string, that defines a platform name.

CA_SUNW_MACH

Specifies a machine name. The c_ptr element contains the string table offset of a null-terminated string, that defines a machine hardware name.

CA_SUNW_ID

Specifies a capability identifier name. The c_ptr element contains the string table offset of a null-terminated string, that defines an identifier name. This element does not define a capability, but assigns a unique symbolic name to the capability group by which the group can be referenced. This identifier name is appended to any global symbol names that are transformed to local symbols as part of the link-editors -z symbolcap processing. See Converting Object Capabilities to Symbol Capabilities.

Relocatable objects can contain a capabilities section. The link-editor combines any capabilities sections from multiple input relocatable objects into a single capabilities section. The link-editor also allows capabilities to be defined at the time an object is built. See Identifying Capability Requirements.

Multiple CA_SUNW_NULL terminated groups of capabilities can exist within an object. The first group, starting at index 0, identifies the object capabilities. A dynamic object that defines object capabilities, has a PT_SUNWCAP program header associated to the section. This program header allows the runtime linker to validate the object against the system capabilities that are available to the process. Dynamic objects that use different object capabilities can provide a flexible runtime environment using filters. See Capability Specific Shared Objects.

Additional groups of capabilities identify symbol capabilities. Symbol capabilities allow multiple instances of the same symbol to exist within an object. Each instance is associated to a set of capabilities that must be available for the instance to be used. When symbol capabilities are present, the sh_link element of the SHT_SUNW_cap section points to the associated SHT_SUNW_capinfo table. Dynamic objects that use symbol capabilities can provide a flexible means of enabling optimized functions for specific systems. See Creating a Family of Symbol Capabilities Functions.

The SHT_SUNW_capinfo table parallels the associated symbol table. The sh_link element of the SHT_SUNW_capinfo section points to the associated symbol table. Functions that are associated with capabilities, have indexes within the SHT_SUNW_capinfo table that identify the capabilities group within the SHT_SUNW_cap section.

Within a dynamic object, the sh_info element of the SHT_SUNW_capinfo section points to a capabilities chain table, SHT_SUNW_capchain. This table is used by the runtime linker to locate members of a capabilities family.

A SHT_SUNW_capinfo table entry has the following format. See sys/elf.h.

typedef Elf32_Word    Elf32_Capinfo;
typedef Elf64_Xword   Elf64_Capinfo;

Elements within this table are interpreted using the following macros. See sys/elf.h.

#define ELF32_C_SYM(info)       ((info)>>8)
#define ELF32_C_GROUP(info)     ((unsigned char)(info))
#define ELF32_C_INFO(sym, grp)  (((sym)<<8)+(unsigned char)(grp))

#define ELF64_C_SYM(info)       ((info)>>32)
#define ELF64_C_GROUP(info)     ((Elf64_Word)(info))
#define ELF64_C_INFO(sym, grp)  (((Elf64_Xword)(sym)<<32)+(Elf64_Xword)(grp))

A SHT_SUNW_capinfo entry group element contains the index of the SHT_SUNW_cap table that this symbol is associated with. This element thus associates symbols to a capability group. A reserved group index, CAPINFO_SUNW_GLOB, identifies a lead symbol of a family of capabilities instances, that provides a default instance.

Name
Value
Meaning
CAPINFO_SUNW_GLOB
0xff
Identifies a default symbol. This symbol is not associated with any specific capabilities, but leads a symbol capabilities family.

A SHT_SUNW_capinfo entry symbol element contains the index of the lead symbol associated with this symbol. The group and symbol information allow the link-editor to process families of capabilities symbols from relocatable objects, and construct the necessary capabilities information in any output object. Within a dynamic object, the symbol element of a lead symbol, one tagged with the group CAPINFO_SUNW_GLOB, is an index into the SHT_SUNW_capchain table. This index allows the runtime linker to traverse the capabilities chain table, starting at this index, and inspects each following entry until a 0 entry is found. The chain entries contain symbol indices for each capabilities family member.

A dynamic object that defines symbol capabilities, has a DT_SUNW_CAP dynamic entry, and a DT_SUNW_CAPINFO dynamic entry. These entries identify the SHT_SUNW_cap section, and SHT_SUNW_capinfo section respectively. The object also contains DT_SUNW_CAPCHAIN, DT_SUNW_CAPCHAINENT and DT_SUNW_CAPCHAINSZ entries that identify the SHT_SUNW_capchain section, the sections entry size and total size. These entries allow the runtime linker to establish the best symbol to use, from a family of symbol capability instances.

An object can define only object capabilities, or can define only symbol capabilities, or can define both types of capabilities. An object capabilities group starts at index 0. Symbol capabilities groups start at any index other than 0. If an object defines symbol capabilities, but no object capabilities, then a single CA_SUNW_NULL entry must exist at index 0 to indicate the start of symbol capabilities.

Hash Table Section

A hash table consists of Elf32_Word or Elf64_Word objects that provide for symbol table access. The SHT_HASH section provides this hash table. The symbol table to which the hashing is associated is specified in the sh_link entry of the hash table's section header. Labels are used in the following figure to help explain the hash table organization, but these labels are not part of the specification.

Figure 7-4 Symbol Hash Table

ELF hash table information example.

The bucket array contains nbucket entries, and the chain array contains nchain entries. Indexes start at 0. Both bucket and chain hold symbol table indexes. Chain table entries parallel the symbol table. The number of symbol table entries should equal nchain, so symbol table indexes also select chain table entries.

A hashing function that accepts a symbol name, returns a value to compute a bucket index. Consequently, if the hashing function returns the value x for some name, bucket [x% nbucket] gives an index y. This index is an index into both the symbol table and the chain table. If the symbol table entry is not the name desired, chain[y] gives the next symbol table entry with the same hash value.

The chain links can be followed until the selected symbol table entry holds the desired name, or the chain entry contains the value STN_UNDEF.

The hash function is as follows.

unsigned long
elf_Hash(const unsigned char *name)
{
    unsigned long h = 0, g;
 
        while (*name)
        {
             h = (h << 4) + *name++;
             if (g = h & 0xf0000000)
                  h ^= g >> 24;
                   h &= ~g;
        }
        return h;
}

Move Section

Typically, within ELF files, initialized data variables are maintained within the object file. If a data variable is very large, and contains only a small number of initialized (nonzero) elements, the entire variable is still maintained in the object file.

Objects that contain large partially initialized data variables, such as FORTRAN COMMON blocks, can result in a significant disk space overhead. The SHT_SUNW_move section provides a mechanism of compressing these data variables. This compression reduces the disk size of the associated object.

The SHT_SUNW_move section contains multiple entries of the type ELF32_Move or Elf64_Move. These entries allow data variables to be defined as tentative items (.bss). These items occupy no space in the object file, but contribute to the object's memory image at runtime. The move records establish how the memory image is initialized with data to construct the complete data variable.

ELF32_Move and Elf64_Move entries 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))

The elements of these structures are as follows.

m_value

The initialization value, which is the value that is moved into the memory image.

m_info

The symbol table index, with respect to which the initialization is applied, together with the size, in bytes, of the offset being initialized. The lower 8 bits of the member define the size, which can be 1, 2, 4 or 8. The upper bytes define the symbol index.

m_poffset

The offset relative to the associated symbol to which the initialization is applied.

m_repeat

A repetition count.

m_stride

The stride count. This value indicates the number of units that should be skipped when performing a repetitive initialization. A unit is the size of an initialization object as defined by m_info. An m_stride value of zero indicates that the initialization be performed contiguously for units.

The following data definition would traditionally consume 0x8000 bytes within an object file.

typedef struct {
        int     one;
        char    two;
} Data;

Data move[0x1000] = {
        {0, 0},       {1, '1'},     {0, 0},
        {0xf, 'F'},   {0xf, 'F'},   {0, 0},
        {0xe, 'E'},   {0, 0},       {0xe, 'E'}
};

A SHT_SUNW_move section can be used to describe this data. The data item is defined within the .bss section. The non-zero elements of the data item are initialized with the appropriate move entries.

$ elfdump -s data | fgrep move
      [17]  0x00020868 0x00008000  OBJT GLOB 0   .bss       move
$ elfdump -m data

Move Section: .SUNW_move
    symndx offset   size repeat stride   value               with respect to
      [17]      8      4      1      1 0x000000000000000001  move
      [17]     12      4      1      1 0x000000000031000000  move
      [17]     24      4      2      1 0x00000000000000000f  move
      [17]     28      4      2      1 0x000000000046000000  move
      [17]     48      4      1      1 0x00000000000000000e  move
      [17]     52      4      1      1 0x000000000045000000  move
      [17]     64      4      1      1 0x00000000000000000e  move
      [17]     68      4      1      1 0x000000000045000000  move

Move sections that are supplied from relocatable objects are concatenated and output in the object being created by the link-editor. However, the following conditions cause the link-editor to process the move entries. This processing expands the move entry contents into a traditional data item.

Note Section

A vendor or system engineer might need to mark an object file with special information that other programs can check for conformance or compatibility. 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, as shown in the following figure. For 64–bit objects and 32–bit objects, each entry is an array of 4-byte words in the format of the target processor. Labels are shown in Figure 7-6 to help explain note information organization, but are not part of the specification.

Figure 7-5 Note Information

ELF note section information.
namesz and name

The first namesz bytes in name contain a null-terminated character representation of the entry's owner or originator. No formal mechanism exists 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 the value zero. Padding is present, if necessary, to ensure 4-byte alignment for the descriptor. Such padding is not included in namesz.

descsz and desc

The first descsz bytes in desc hold the note descriptor. If no descriptor is present, descsz contains the value zero. Padding is present, if necessary, to ensure 4-byte alignment for the next note entry. Such padding is not included in descsz.

type

Provides the interpretation of the descriptor. Each originator controls its own types. Multiple interpretations of a single type value can exist. A program must recognize both the name and the type to understand a descriptor. Types currently must be nonnegative.

The note segment that is shown in the following figure holds two entries.

Figure 7-6 Example Note Segment

ELF note section example.

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


Relocation Sections

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. Relocatable files must have information that describes how to modify their section contents. This information allows 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. See 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;
} Elf64_Rela;
r_offset

This member gives the location at which to apply the relocation action. Different object files have slightly different interpretations for this member.

For a relocatable file, the value indicates a section offset. The relocation section describes how to modify another section in the file. Relocation offsets designate a storage unit within the second section.

For an executable or shared object, the value indicates the virtual address of the storage unit affected by the relocation. This information makes the relocation entries more useful for the runtime linker.

Although the interpretation of the member changes for different object files to allow efficient access by the relevant programs, the meanings of the relocation types stay the same.

r_info

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 holds the symbol table index of the function being called. If the index is STN_UNDEF, the undefined symbol index, the relocation uses zero as the symbol value.

Relocation types are processor-specific. A relocation entry's relocation type or symbol table index is the result of applying ELF32_R_TYPE or ELF32_R_SYM, respectively, to the entry's r_info member.

#define ELF32_R_SYM(info)             ((info)>>8)
#define ELF32_R_TYPE(info)            ((unsigned char)(info))
#define ELF32_R_INFO(sym, type)       (((sym)<<8)+(unsigned char)(type))

#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 64–bit SPARC 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. For the existing relocation types, the data field is zero. New relocation types, however, might make use of the data bits.

#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))
r_addend

This member specifies a constant addend used to compute the value to be stored into the relocatable field.

Rela entries contain an explicit addend. Entries of type Rel store an implicit addend in the location to be modified. 32–bit SPARC use only Elf32_Rela relocation enteries. 64–bit SPARC and 64–bit x86 use only Elf64_Rela relocation entries. Thus, the r_addend member serves as the relocation addend. x86 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.

A relocation section can reference two other sections: a symbol table, identified by the sh_link section header entry, and a section to modify, identified by the sh_info section header entry. Sections specifies these relationships. A sh_info entry is required when a relocation section exists in a relocatable object, but is optional for executables and shared objects. The relocation offset is sufficient to perform the relocation.

Relocation Types (Processor-Specific)

Relocation entries describe how to alter instruction and data fields in the following figures. Bit numbers appear in the lower box corners.

On the SPARC platform, relocation entries apply to bytes (byte8), half-words (half16), or words.

32–bit relocation entries.

On 64–bit SPARC and x64, relocations also apply to extended-words (xword64).

64–bit relocation entries.

On x86, relocation entries apply to words (word32).

x86 relocation entry.

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 x86 architecture.

x86 relocation entry.

In all cases, 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.

Calculations for the following relocation types 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. The link-editor first decides how to combine and locate the input files. The link-editor then updates the symbol values and performs the relocation. Relocations applied to executable or shared object files are similar and accomplish the same result. Descriptions in the tables in this section use the following notation.

A

The addend used to compute the value of the relocatable field.

B

The base address at which a shared object is loaded into memory during execution. Generally, a shared object file is built with a base virtual address of 0. However, the execution address of the shared object is different. See Program Header.

G

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

GOT

The address of the global offset table. See Global Offset Table (Processor-Specific).

L

The section offset or address of the procedure linkage table entry for a symbol. See Procedure Linkage Table (Processor-Specific).

P

The section offset or address of the storage unit being relocated, computed using r_offset.

S

The value of the symbol whose index resides in the relocation entry.

Z

The size of the symbol whose index resides in the relocation entry.

SPARC: Relocation Types

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.

Table 7-13 SPARC: ELF Relocation Types

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
Refer to the explanation following this table.
R_SPARC_GLOB_DAT
20
V-word32
S + A
R_SPARC_JMP_SLOT
21
None
Refer to the explanation following this table.
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_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
R_SPARC_5
44
V-imm5
S + A
R_SPARC_6
45
V-imm6
S + 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-word32
S + A
R_SPARC_UA16
55
V-half16
S + A
R_SPARC_GOTDATA_HIX22
80
V-imm22
((S + A - GOT) >> 10) ^ ((S + A - GOT) >> 31)
R_SPARC_GOTDATA_LOX10
81
T-imm13
((S + A - GOT) & 0x3ff) | (((S + A - GOT) >> 31) & 0x1c00)
R_SPARC_GOTDATA_OP_HIX22
82
T-imm22
(G >> 10) ^ (G >> 31)
R_SPARC_GOTDATA_OP_LOX10
83
T-imm13
(G & 0x3ff) | ((G >> 31) & 0x1c00)
R_SPARC_GOTDATA_OP
84
Word32
Refer to the explanation following this table.
R_SPARC_SIZE32
86
V-word32
Z + A

Note - Additional relocations are available for thread-local storage references. These relocations are covered in Chapter 8, Thread-Local Storage.


Some relocation types have semantics beyond simple calculation.

R_SPARC_GOT10

Resembles R_SPARC_LO10, except that the relocation refers to the address of the symbol's GOT entry. Additionally, R_SPARC_GOT10 instructs the link-editor to create a global offset table.

R_SPARC_GOT13

Resembles R_SPARC_13, except that the relocation refers to the address of the symbol's GOT entry. Additionally, R_SPARC_GOT13 instructs the link-editor to create a global offset table.

R_SPARC_GOT22

Resembles R_SPARC_22, except that the relocation refers to the address of the symbol's GOT entry. Additionally, R_SPARC_GOT22 instructs the link-editor to create a global offset table.

R_SPARC_WPLT30

Resembles R_SPARC_WDISP30, except that the relocation refers to the address of the symbol's procedure linkage table entry. Additionally, R_SPARC_WPLT30 instructs the link-editor to create a procedure linkage table.

R_SPARC_COPY

Created by the link-editor for dynamic executables to preserve a read-only text segment. The relocation 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.

R_SPARC_GLOB_DAT

Resembles R_SPARC_32, except that the relocation sets a GOT entry to the address of the specified symbol. The special relocation type enables you to determine the correspondence between symbols and GOT entries.

R_SPARC_JMP_SLOT

Created by the link-editor for dynamic objects to provide lazy binding. The relocation 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.

R_SPARC_RELATIVE

Created by the link-editor for dynamic objects. The relocation 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 a value of zero for the symbol table index.

R_SPARC_UA32

Resembles R_SPARC_32, except that the relocation refers to an unaligned word. 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.

R_SPARC_LM22

Resembles R_SPARC_HI22, except that the relocation truncates rather than validates.

R_SPARC_PC_LM22

Resembles R_SPARC_PC22, except that the relocation truncates rather than validates.

R_SPARC_HIX22

Used with R_SPARC_LOX10 for executables that are confined to the uppermost 4 gigabytes of the 64–bit address space. Similar to R_SPARC_HI22, but supplies ones complement of linked value.

R_SPARC_LOX10

Used with R_SPARC_HIX22. Similar to R_SPARC_LO10, but always sets bits 10 through 12 of the linked value.

R_SPARC_L44

Used with the R_SPARC_H44 and R_SPARC_M44 relocation types to generate a 44-bit absolute addressing model.

R_SPARC_REGISTER

Used to initialize a register symbol. The relocation offset member contains the register number to be initialized. A corresponding register symbol must exist for this register. The symbol must be of type SHN_ABS.

R_SPARC_GOTDATA_OP_HIX22, R_SPARC_GOTDATA_OP_LOX10, and R_SPARC_GOTDATA_OP

These relocations provide for code transformations.

64-bit SPARC: Relocation Types

The following notation, used in relocation calculation, is unique to 64–bit SPARC.

O

The secondary addend used to compute the value of the relocation field. This addend is extracted from the r_info field by applying the ELF64_R_TYPE_DATA macro.

The relocations that are listed in the following table extend, or alter, the relocations defined for 32–bit SPARC. See SPARC: Relocation Types.

Table 7-14 64-bit SPARC: ELF Relocation Types

Name
Value
Field
Calculation
R_SPARC_HI22
9
V-imm22
(S + A) >> 10
R_SPARC_GLOB_DAT
20
V-xword64
S + A
R_SPARC_RELATIVE
22
V-xword64
B + A
R_SPARC_64
32
V-xword64
S + A
R_SPARC_OLO10
33
V-simm13
((S + A) & 0x3ff) + O
R_SPARC_DISP64
46
V-xword64
S + A - P
R_SPARC_PLT64
47
V-xword64
L + A
R_SPARC_REGISTER
53
V-xword64
S + A
R_SPARC_UA64
54
V-xword64
S + A
R_SPARC_H34
85
V-imm22
(S + A) >> 12
R_SPARC_SIZE64
87
V-xword64
Z + A

The following relocation type has semantics beyond simple calculation.

R_SPARC_OLO10

Resembles R_SPARC_LO10, except that an extra offset is added to make full use of the 13-bit signed immediate field.

32-bit x86: Relocation Types

The relocations that are listed in the following table are defined for 32–bit x86.

Table 7-15 32-bit x86: ELF Relocation Types

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
Refer to the explanation following this table.
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
R_386_16
20
word16
S + A
R_386_PC16
21
word16
S + A - P
R_386_8
22
word8
S + A
R_386_PC8
23
word8
S + A - P
R_386_SIZE32
38
word32
Z + A

Note - Additional relocations are available for thread-local storage references. These relocations are covered in Chapter 8, Thread-Local Storage.


Some relocation types have semantics beyond simple calculation.

R_386_GOT32

Computes the distance from the base of the GOT to the symbol's GOT entry. The relocation also instructs the link-editor to create a global offset table.

R_386_PLT32

Computes the address of the symbol's procedure linkage table entry and instructs the link-editor to create a procedure linkage table.

R_386_COPY

Created by the link-editor for dynamic executables to preserve a read-only text segment. The relocation 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.

R_386_GLOB_DAT

Used to set a GOT entry to the address of the specified symbol. The special relocation type enable you to determine the correspondence between symbols and GOT entries.

R_386_JMP_SLOT

Created by the link-editor for dynamic objects to provide lazy binding. The relocation 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.

R_386_RELATIVE

Created by the link-editor for dynamic objects. The relocation 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 a value of zero for the symbol table index.

R_386_GOTOFF

Computes the difference between a symbol's value and the address of the GOT. The relocation also instructs the link-editor to create the global offset table.

R_386_GOTPC

Resembles R_386_PC32, except that it uses the address of the GOT in its calculation. The symbol referenced in this relocation normally is _GLOBAL_OFFSET_TABLE_, which also instructs the link-editor to create the global offset table.

x64: Relocation Types

The relocations that are listed in the following table are defined for x64.

Table 7-16 x64: ELF Relocation Types

Name
Value
Field
Calculation
R_AMD64_NONE
0
None
None
R_AMD64_64
1
word64
S + A
R_AMD64_PC32
2
word32
S + A - P
R_AMD64_GOT32
3
word32
G + A
R_AMD64_PLT32
4
word32
L + A - P
R_AMD64_COPY
5
None
Refer to the explanation following this table.
R_AMD64_GLOB_DAT
6
word64
S
R_AMD64_JUMP_SLOT
7
word64
S
R_AMD64_RELATIVE
8
word64
B + A
R_AMD64_GOTPCREL
9
word32
G + GOT + A - P
R_AMD64_32
10
word32
S + A
R_AMD64_32S
11
word32
S + A
R_AMD64_16
12
word16
S + A
R_AMD64_PC16
13
word16
S + A - P
R_AMD64_8
14
word8
S + A
R_AMD64_PC8
15
word8
S + A - P
R_AMD64_PC64
24
word64
S + A - P
R_AMD64_GOTOFF64
25
word64
S + A - GOT
R_AMD64_GOTPC32
26
word32
GOT + A + P
R_AMD64_SIZE32
32
word32
Z + A
R_AMD64_SIZE64
33
word64
Z + A

Note - Additional relocations are available for thread-local storage references. These relocations are covered in Chapter 8, Thread-Local Storage.


The special semantics for most of these relocation types are identical to those used for x86. Some relocation types have semantics beyond simple calculation.

R_AMD64_GOTPCREL

This relocations has different semantics from the R_AMD64_GOT32 or equivalent R_386_GOTPC relocation. The x64 architecture provides an addressing mode that is relative to the instruction pointer. Therefore, an address can be loaded from the GOT using a single instruction.

The calculation for the R_AMD64_GOTPCREL relocation provides the difference between the location in the GOT where the symbol's address is given, and the location where the relocation is applied.

R_AMD64_32

The computed value is truncated to 32–bits. The link-editor verifies that the generated value for the relocation zero-extends to the original 64–bit value.

R_AMD64_32S

The computed value is truncated to 32–bits. The link-editor verifies that the generated value for the relocation sign-extends to the original 64–bit value.

R_AMD64_8, R_AMD64_16, R_AMD64_PC16, and R_AMD64_PC8

These relocations are not conformant to the x64 ABI, but are added here for documentation purposes. The R_AMD64_8 relocation truncates the computed value to 8-bits. The R_AMD64_16 relocation truncates the computed value to 16-bits.

String Table Section

String table sections hold null-terminated character sequences, commonly called strings. The object file uses these strings to represent symbol and section names. You reference a string as an index into the string table section.

The first byte, which is index zero, holds a null character. Likewise, a string table's last byte holds 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. The section header's sh_size member contains 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. The section header string table is designated by the e_shstrndx member of the ELF header. The following figure shows a string table with 25 bytes and the strings associated with various indexes.

Figure 7-7 ELF String Table

ELF string table example.

The following table shows the strings of the string table that are shown in the preceding figure.

Table 7-17 ELF 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. A single string can be referenced multiple times. Unreferenced strings also are allowed.

Symbol Table Section

An object file's symbol table holds information needed to locate and relocate a program's symbolic definitions and symbolic 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. See Table 7-21.

A symbol table entry has the following format. See 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;
st_name

An index into the object file's symbol string table, which holds the character representations of the symbol names. If the value is nonzero, the value represents a string table index that gives the symbol name. Otherwise, the symbol table entry has no name.

st_value

The value of the associated symbol. The value can be an absolute value or an address, depending on the context. See Symbol Values.

st_size

Many symbols have associated sizes. For example, a data object's size is the number of bytes that are contained in the object. This member holds the value zero if the symbol has no size or an unknown size.

st_info

The symbol's type and binding attributes. A list of the values and meanings appears in Table 7-18. The following code shows how to manipulate the values. See sys/elf.h.

#define ELF32_ST_BIND(info)          ((info) >> 4)
#define ELF32_ST_TYPE(info)          ((info) & 0xf)
#define ELF32_ST_INFO(bind, type)    (((bind)<<4)+((type)&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))
st_other

A symbol's visibility. A list of the values and meanings appears in Table 7-20. The following code shows how to manipulate the values for both 32–bit objects and 64–bit objects. Other bits are set to zero, and have no defined meaning.

#define ELF32_ST_VISIBILITY(o)       ((o)&0x3)
#define ELF64_ST_VISIBILITY(o)       ((o)&0x3)
st_shndx

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

If this member contains SHN_XINDEX, then the actual section header index is too large to fit in this field. The actual value is contained in the associated section of type SHT_SYMTAB_SHNDX.

A symbol's binding, determined from its st_info field, determines the linkage visibility and behavior.

Table 7-18 ELF Symbol Binding, ELF32_ST_BIND and ELF64_ST_BIND

Name
Value
STB_LOCAL
0
STB_GLOBAL
1
STB_WEAK
2
STB_LOOS
10
STB_HIOS
12
STB_LOPROC
13
STB_HIPROC
15
STB_LOCAL

Local symbol. These 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.

STB_GLOBAL

Global symbols. These symbols are visible to all object files being combined. One file's definition of a global symbol satisfies another file's undefined reference to the same global symbol.

STB_WEAK

Weak symbols. These symbols resemble global symbols, but their definitions have lower precedence.

STB_LOOS - STB_HIOS

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

STB_LOPROC - STB_HIPROC

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

Global symbols and weak symbols differ in two major ways.


Note - Weak symbols are intended primarily for use in system software. Their use in application programs is discouraged.


In each symbol table, all symbols with STB_LOCAL binding precede the weak symbols 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, as determined from its st_info field, provides a general classification for the associated entity.

Table 7-19 ELF Symbol Types, ELF32_ST_TYPE and ELF64_ST_TYPE

Name
Value
STT_NOTYPE
0
STT_OBJECT
1
STT_FUNC
2
STT_SECTION
3
STT_FILE
4
STT_COMMON
5
STT_TLS
6
STT_LOOS
10
STT_HIOS
12
STT_LOPROC
13
STT_SPARC_REGISTER
13
STT_HIPROC
15
STT_NOTYPE

The symbol type is not specified.

STT_OBJECT

This symbol is associated with a data object, such as a variable, an array, and so forth.

STT_FUNC

This symbol is associated with a function or other executable code.

STT_SECTION

This symbol is associated with a section. Symbol table entries of this type exist primarily for relocation and normally have STB_LOCAL binding.

STT_FILE

Conventionally, the symbol's name gives the name of the source file that is associated with the object file. A file symbol has STB_LOCAL binding and a section index of SHN_ABS. This symbol, if present, precedes the other STB_LOCAL symbols for the file.

Symbol index 1 of the SHT_SYMTAB is an STT_FILE symbol representing the object file. Conventionally, this symbol is followed by the files STT_SECTION symbols. These section symbols are then followed by any global symbols that have been reduced to locals.

STT_COMMON

This symbol labels an uninitialized common block. This symbol is treated exactly the same as STT_OBJECT.

STT_TLS

The symbol specifies a thread-local storage entity. When defined, this symbol gives the assigned offset for the symbol, not the actual address.

Thread-local storage relocations can only reference symbols with type STT_TLS. A reference to a symbol of type STT_TLS from an allocatable section, can only be achieved by using special thread-local storage relocations. See Chapter 8, Thread-Local Storage for details. A reference to a symbol of type STT_TLS from a non-allocatable section does not have this restriction.

STT_LOOS - STT_HIOS

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

STT_LOPROC - STT_HIPROC

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

A symbol's visibility is determined from its st_other field. This visibility can be specified in a relocatable object. This visibility defines how that symbol can be accessed once the symbol has become part of an executable or shared object.

Table 7-20 ELF Symbol Visibility

Name
Value
STV_DEFAULT
0
STV_INTERNAL
1
STV_HIDDEN
2
STV_PROTECTED
3
STV_EXPORTED
4
STV_SINGLETON
5
STV_ELIMINATE
6
STV_DEFAULT

The visibility of symbols with the STV_DEFAULT attribute is as specified by the symbol's binding type. Global symbols and weak symbols are visible outside of their defining component, the executable file or shared object. Local symbols are hidden. Global symbols and weak symbols can also be preempted. These symbols can by interposed by definitions of the same name in another component.

STV_PROTECTED

A symbol that is defined in the current component is protected if the symbol is visible in other components, but cannot be preempted. Any reference to such a symbol from within the defining component must be resolved to the definition in that component. This resolution must occur, even if a symbol definition exists in another component that would interpose by the default rules. A symbol with STB_LOCAL binding will not have STV_PROTECTED visibility.

STV_HIDDEN

A symbol that is defined in the current component is hidden if its name is not visible to other components. Such a symbol is necessarily protected. This attribute is used to control the external interface of a component. An object named by such a symbol can still be referenced from another component if its address is passed outside.

A hidden symbol contained in a relocatable object is either removed or converted to STB_LOCAL binding when the object is included in an executable file or shared object.

STV_INTERNAL

This visibility attribute is currently reserved.

STV_EXPORTED

This visibility attribute ensures that a symbol remains global. This visibility can not be demoted, or eliminated by any other symbol visibility technique. A symbol with STB_LOCAL binding will not have STV_EXPORTED visibility.

STV_SINGLETON

This visibility attribute ensures that a symbol remains global, and that a single instance of the symbol definition is bound to by all references within a process. This visibility can not be demoted, or eliminated by any other symbol visibility technique. A symbol with STB_LOCAL binding will not have STV_SINGLETON visibility. A STV_SINGLETON can not be directly bound to.

STV_ELIMINATE

This visibility attribute extends STV_HIDDEN. A symbol that is defined in the current component as eliminate is not visible to other components. The symbol is not written to any symbol table of a dynamic executable or shared object from which the component is used.

The STV_SINGLETON visibility attribute can affect the resolution of symbols within an executable or shared object during link-editing. Only one instance of a singleton can be bound to from any reference within a process.

A STV_SINGLETON can be combined with a STV_DEFAULT visibility attribute, with the STV_SINGLETON taking precedence. A STV_EXPORT can be combined with a STV_DEFAULT visibility attribute, with the STV_EXPORT taking precedence. A STV_SINGLETON or STV_EXPORT visibility can not be combined with any other visibility attribute. Such an event is deemed fatal to the link-edit.

Other visibility attributes do not affect the resolution of symbols within an executable or shared object during link-editing. Such resolution is controlled by the binding type. Once the link-editor has chosen its resolution, these attributes impose two requirements. Both requirements are based on the fact that references in the code being linked might have been optimized to take advantage of the attributes.

If a symbol's value refers to a specific location within a section, the symbols's 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. References to the symbol continue to point to the same location in the program. Some special section index values give other semantics.

SHN_ABS

This symbol has an absolute value that does not change because of relocation.

SHN_COMMON, and SHN_AMD64_LCOMMON

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. The link-editor allocates 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.

SHN_UNDEF

This section table index indicates that the symbol is undefined. When the link-editor combines this object file with another object that defines the indicated symbol, this file's references to the symbol is bound to the definition.

As mentioned previously, the symbol table entry for index 0 (STN_UNDEF) is reserved. This entry holds the values listed in the following table.

Table 7-21 ELF 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 Values

Symbol table entries for different object file types have slightly different interpretations for the st_value member.

Although the symbol table values have similar meanings for different object files, the data allow efficient access by the appropriate programs.

Symbol Table Layout and Conventions

The symbols in a symbol table are written in the following order.

Three symbol tables are of special interest in the Oracle Solaris OS.

.symtab (SHT_SYMTAB)

This symbol table contains every symbol that describes the associated ELF file. This symbol table is typically non-allocable, and is therefore not available in the memory image of the process.

Global symbols can be eliminated from the .symtab by using a mapfile together with the ELIMINATE keyword. See Symbol Elimination, and SYMBOL_SCOPE / SYMBOL_VERSION Directives. Local symbols can also be eliminated by using the link-editor -z redlocsym option.

.dynsym (SHT_DYNSYM)

This table contains a subset of the symbols from the .symtab table that are needed to support dynamic linking. This symbol table is allocable, and is therefore available in the memory image of the process.

The .dynsym table begins with the standard NULL symbol, followed by the files global symbols. STT_FILE symbols are typically not present in this symbol table. STT_SECTION symbols might be present if required by relocation entries.

.SUNW_ldynsym (SHT_SUNW_LDYNSYM)

An optional symbol table that augments the information that is found in the .dynsym table. The .SUNW_ldynsym table contains local function symbols. This symbol table is allocable, and is therefore available in the memory image of the process. This section allows debuggers to produce accurate stack traces in runtime contexts when the non-allocable .symtab is not available, or has been stripped from the file. This section also provides the runtime environment with additional symbolic information for use with dladdr(3C).

A .SUNW_ldynsym table only exists when a .dynsym table is present. When both a .SUNW_ldynsym section and a .dynsym section exist, the link-editor places their data regions directly adjacent to each other, with the .SUNW_ldynsym first. This placement allows the two tables to be viewed as a single larger contiguous symbol table. This symbol table follows the standard layout rules that were enumerated previously.

The .SUNW_ldynsym table can be eliminated by using the link-editor -z noldynsym option.

Symbol Sort Sections

The dynamic symbol table formed by the adjacent .SUNW_ldynsym section and .dynsym section can be used to map memory addresses to their corresponding symbol. This mapping can be used to determine which function or variable that a given address represents. However, analyzing the symbol tables to determine a mapping is complicated by the order in which symbols are written to symbol tables. See Symbol Table Layout and Conventions. This layout complicates associating an address to a symbol name in the follows ways.

Symbol sort sections are used to solve these problems. A symbol sort section is an array of Elf32_Word or Elf64_Word objects. Each element of this array is an index into the combined .SUNW_ldynsym.dynsym symbol table. The elements of the array are sorted so that the symbols that are reference are provided in sorted order. Only symbols representing functions or variables are included. The symbols that are associated with a sort array can be displayed using elfdump(1) with the -S option.

Regular symbols and thread-local storage symbols can not be sorted together. The value of a regular symbol is the address of the function or the address of the variable the symbol references. The value of a thread-local storage symbol is the variable's thread offset. Therefore, regular symbols and thread-local storage symbols use two different sort sections.

.SUNW_dynsymsort

A section of type SHT_SUNW_SYMSORT, containing indexes to regular symbols in the combined .SUNW_ldynsym.dynsym symbol table, sorted by address. Symbols that do not represent variables or functions are not included.

.SUNW_dyntlssort

A section of type SHT_SUNW_TLSSORT, containing indexes to TLS symbols in the combined .SUNW_ldynsym.dynsym symbol table, sorted by offset. This section is only produced if the object file contains TLS symbols.

The link-editor uses the following rules, in the order that is shown, to select which symbols are referenced by the sort sections.

These rules filter out automatically generated compiler and link-editor generated symbols. The symbols that are selected are of interest to the user. However, two cases exist where manual intervention might be necessary to improve the selection process.

The mapfile keywords DYNSORT and NODYNSORT provide for additional control over symbol selection. See SYMBOL_SCOPE / SYMBOL_VERSION Directives.

DYNSORT

Identifies a symbol that should be included in a sort section. The symbol type must be STT_FUNC, STT_OBJECT, STT_COMMON, or STT_TLS.

NODYNSORT

Identifies a symbol that should not be included in a sort section.

For example, an object might provide the following symbol table definitions.

$ elfdump -sN.symtab foo.so.1 | egrep "foo$|bar$"
      [37]  0x000004b0 0x0000001c  FUNC GLOB  D   0 .text      bar
      [38]  0x000004b0 0x0000001c  FUNC WEAK  D   0 .text      foo

The symbols foo and bar represent an aliases pair. By default, when creating a sorted array, only the symbol foo is represented.

$ cc -o foo.so.1 -G foo.c
$ elfdump -S foo.so.1 | egrep "foo$|bar$"
      [13]  0x000004b0 0x0000001c  FUNC WEAK  D   0 .text      foo

In the case where a global and a weak symbol are found by the link-editor to reference the same item, the weak symbol is normally kept. The symbol bar is omitted from the sorted array because of the association to the weak symbol foo.

The following mapfile results in the symbol bar being represented in the sorted array. The symbol foo is omitted.

$ cat mapfile
{
    global:
        bar = DYNSORT;
        foo = NODYNSORT;
};
$ cc -M mapfile -o foo.so.2 -Kpic -G foo.c
$ elfdump -S foo.so.2 | egrep "foo$|bar$"
      [13]  0x000004b0 0x0000001c  FUNC GLOB  D   0 .text      bar

The .SUNW_dynsymsort section and .SUNW_dyntlssort section, require that a .SUNW_ldynsym section be present. Therefore, use of the -z noldynsym option also prevents the creation of any sort section.

Register Symbols

The SPARC architecture supports register symbols, which are symbols that initialize a global register. A symbol table entry for a register symbol contains the entries that are listed in the following table.

Table 7-22 SPARC: ELF Symbol Table Entry: Register Symbol

Field
Meaning
st_name
Index into the string table for the name of the symbol, or the value 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.

The register values that are defined for SPARC are listed in the following table.

Table 7-23 SPARC: ELF 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.

Syminfo Table Section

The syminfo section contains multiple entries of the type Elf32_Syminfo or Elf64_Syminfo. The .SUNW_syminfo section contains one entry 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 entry 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 is used to store the current version of the Syminfo table, which is SYMINFO_CURRENT. Since symbol table entry 0 is always reserved for the UNDEF symbol table entry, this usage does not pose any conflicts.

An Syminfo entry has the following format. See sys/link.h.

typedef struct {
        Elf32_Half      si_boundto;
        Elf32_Half      si_flags;
} Elf32_Syminfo;

typedef struct {
        Elf64_Half      si_boundto;
        Elf64_Half      si_flags;
} Elf64_Syminfo;
si_boundto

An index to an entry in the .dynamic section, identified by the sh_info field, which augments the Syminfo flags. For example, a DT_NEEDED entry identifies a dynamic object associated with the Syminfo entry. The entries that follow are reserved values for si_boundto.

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.
SYMINFO_BT_NONE
0xfffd
Symbol has no special symbol binding.
SYMINFO_BT_EXTERN
0xfffc
Symbol definition is external.
si_flags

This bit-field can have flags set, as shown in the following table.

Name
Value
Meaning
SYMINFO_FLG_DIRECT
0x01
Symbol reference has a direct association to the object containing the definition.
SYMINFO_FLG_FILTER
0x02
Symbol definition acts as a standard filter.
SYMINFO_FLG_COPY
0x04
Symbol definition is the result of a copy-relocation.
SYMINFO_FLG_LAZYLOAD
0x08
Symbol reference is to an object that should be lazily loaded.
SYMINFO_FLG_DIRECTBIND
0x10
Symbol reference should be bound directly to the definition.
SYMINFO_FLG_NOEXTDIRECT
0x20
Do not allow an external reference to directly bind to this symbol definition.
SYMINFO_FLG_AUXILIARY
0x40
Symbol definition acts as an auxiliary filter.
SYMINFO_FLG_INTERPOSE
0x80
Symbol definition acts as an interposer. This attribute is only applicable for dynamic executables.
SYMINFO_FLG_CAP
0x100
Symbol is associated with capabilities.
SYMINFO_FLG_DEFERRED
0x200
Symbol should not be included in BIND_NOW relocations.

Versioning Sections

Objects created by the link-editor can contain two types of versioning information.

The structures that form these sections are defined in sys/link.h. Sections that contain versioning information are named .SUNW_version.

Version Definition Section

This section is defined by the type SHT_SUNW_verdef. If this section exists, a SHT_SUNW_versym section must also exist. These two structures provide an association of symbols to version definitions within the file. See Creating a Version Definition. 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;
vd_version

This member identifies the version of the structure, as listed in the following table.

Name
Value
Meaning
VER_DEF_NONE
0
Invalid version.
VER_DEF_CURRENT
>=1
Current version.

The value 1 signifies the original section format. Extensions require new versions with higher numbers. The value of VER_DEF_CURRENT changes as necessary to reflect the current version number.

vd_flags

This member holds version definition-specific information, as listed in the following table.

Name
Value
Meaning
VER_FLG_BASE
0x1
Version definition of the file.
VER_FLG_WEAK
0x2
Weak version identifier.

The base version definition is always present when version definitions, or symbol auto-reduction, have been applied to the file. The base version provides a default version for the files reserved symbols. A weak version definition has no symbols associated with the version. See Creating a Weak Version Definition.

vd_ndx

The version index. Each version definition has a unique index that is used to associate SHT_SUNW_versym entries to the appropriate version definition.

vd_cnt

The number of elements in the Elf32_Verdaux array.

vd_hash

The hash value of the version definition name. This value is generated using the same hashing function that is described in Hash Table Section.

vd_aux

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. This element points to the version definition string this structure defines. Additional elements can be present. The number of elements is 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.

vd_next

The byte offset from the start of this Elf32_Verdef structure to the next Elf32_Verdef entry.

vda_name

The string table offset to a null-terminated string, giving the name of the version definition.

vda_next

The byte offset from the start of this Elf32_Verdaux entry to the next Elf32_Verdaux entry.

Version Dependency Section

The version dependency section is defined by the type SHT_SUNW_verneed. This section complements the dynamic dependency requirements of the file by indicating the version definitions required from these dependencies. A recording is made in this section only if a dependency contains version definitions. 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;
vn_version

This member identifies the version of the structure, as listed in the following table.

Name
Value
Meaning
VER_NEED_NONE
0
Invalid version.
VER_NEED_CURRENT
>=1
Current version.

The value 1 signifies the original section format. Extensions require new versions with higher numbers. The value of VER_NEED_CURRENT changes as necessary to reflect the current version number.

vn_cnt

The number of elements in the Elf32_Vernaux array.

vn_file

The string table offset to a null-terminated string, providing the file name of a version dependency. This name matches one of the .dynamic dependencies found in the file. See Dynamic Section.

vn_aux

The byte offset, from the start of this Elf32_Verneed entry, to the Elf32_Vernaux array of version definitions that are required from the associated file dependency. At least one version dependency must exist. Additional version dependencies can be present, the number being indicated by the vn_cnt value.

vn_next

The byte offset, from the start of this Elf32_Verneed entry, to the next Elf32_Verneed entry.

vna_hash

The hash value of the version dependency name. This value is generated using the same hashing function that is described in Hash Table Section.

vna_flags

Version dependency specific information, as listed in the following table.

Name
Value
Meaning
VER_FLG_WEAK
0x2
Weak version identifier.
VER_FLG_INFO
0x4
SHT_SUNW_versym reference exists for informational purposes, and need not be validated at runtime.

A weak version dependency indicates an original binding to a weak version definition.

vna_other

If non-zero, the version index assigned to this dependency version. This index is used within the SHT_SUNW_versym to assign global symbol references to this version.

Versions of Solaris up to and including the Solaris 10 release, did not assign version symbol indexes to dependency versions. In these objects, the value of vna_other is 0.

vna_name

The string table offset to a null-terminated string, giving the name of the version dependency.

vna_next

The byte offset from the start of this Elf32_Vernaux entry to the next Elf32_Vernaux entry.

Version Symbol Section

The version symbol section is defined by the type SHT_SUNW_versym. This section consists of an array of elements of 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 that are contained in the associated symbol table. This number is determined by the section's sh_link value. Each element of the array contains a single index that can have the values shown in the following table.

Table 7-24 ELF Version Dependency Indexes

Name
Value
Meaning
VER_NDX_LOCAL
0
Symbol has local scope.
VER_NDX_GLOBAL
1
Symbol has global scope and is assigned to the base version definition.
>1
Symbol has global scope and is assigned to a user-defined version definition, SHT_SUNW_verdef, or a version dependency, SHT_SUNW_verneed.

A symbol may be assigned the special reserved index 0. This index can be assigned for any of the following reasons.

Versions defined by an object are assigned version indexes starting at 1 and incremented by 1 for each version. Index 1 is reserved for the first global version. If the object does not have a SHT_SUNW_verdef version definition section, then all the global symbols defined by the object receive index 1. If the object does have a version definition section, then VER_NDX_GLOBAL simply refers to the first such version.

Versions required by the object from other SHT_SUNW_verneed dependencies, are assigned version indexes that start 1 past the final version definition index. These indexes are also incremented by 1 for each version. Since index 1 is always reserved for VER_NDX_GLOBAL, the first possible index for a dependency version is 2.

Versions of Solaris up to and including the Solaris 10 release, did not assign a version index to a SHT_SUNW_verneed dependency version. In such an object, any symbol reference had a version index of 0 indicating that no versioning information is available for that symbol.