- 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, it 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. Depending on the context, this can be an absolute value, an address, and so forth. See "Symbol Values".
- st_size
Many symbols have associated sizes. For example, a data object's size is the number of bytes contained in the object. This member holds 0 if the symbol has no size or an unknown size.
- st_info
The symbol's type and binding attributes. A list of the values and meanings appears in Table 7-19. The following code shows how to manipulate the values, defined in 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-21. The following code shows how to manipulate the values for both 32-bit and 64-bit objects. Other bits contain 0 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, as listed in Table 7-12.
A symbol's binding, determined from its st_info field, determines the linkage visibility and behavior.
Table 7-19 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 will satisfy 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 and weak symbols differ in two major ways:
When the link-editor combines several relocatable object files, it does not allow multiple definitions of STB_GLOBAL symbols with the same name. On the other hand, if a defined global symbol exists, the appearance of a weak symbol with the same name will not cause an error. The link-editor honors the global definition and ignores the weak ones.
Similarly, if a common symbol exists, the appearance of a weak symbol with the same name does not cause an error. The link-editor uses the common definition and ignores the weak one. A common symbol has the st_shndx field holding SHN_COMMON. See "Symbol Resolution".
When the link-editor searches archive libraries it extracts archive members that contain definitions of undefined or tentative global symbols. The member's definition can be either a global or a weak symbol.
The link-editor, by default, does not extract archive members to resolve undefined weak symbols. Unresolved weak symbols have a zero value. The use of -z weakextract overrides this default behavior. It enables weak references to cause the extraction of archive members.
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 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, determined from its st_info field, provides a general classification for the associated entity.
Table 7-20 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_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 associated with the object file. A file symbol has STB_LOCAL binding and its section index is 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 file itself. Conventionally, this symbols is followed by the files STT_SECTION symbols, and any global symbols that have been reduced to locals.
- STT_COMMON
This symbol labels an uninitialized common block. It is treated exactly the same as STT_OBJECT.
- 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, determined from its st_other field, may be specified in a relocatable object. This visibility defines how that symbol may be accessed once the symbol has become part of an executable or shared object.
Table 7-21 ELF Symbol Visibility
Name | Value |
---|---|
STV_DEFAULT | 0 |
STV_INTERNAL | 1 |
STV_HIDDEN | 2 |
STV_PROTECTED | 3 |
- STV_DEFAULT
The visibility of symbols with the STV_DEFAULT attribute is as specified by the symbol's binding type. That is, global and weak symbols are visible outside of their defining component, the executable file or shared object. Local symbols are hidden. Global and weak symbols can also be preempted, that is, they may by interposed by definitions of the same name in another component.
- STV_PROTECTED
A symbol defined in the current component is protected if it 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, even if there is a definition 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 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 may 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 by the link-editor when the relocatable object is included in an executable file or shared object.
- STV_INTERNAL
This visibility attribute is currently reserved.
None of the visibility attributes affects 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 may have been optimized to take advantage of the attributes.
First, all of the non-default visibility attributes, when applied to a symbol reference, imply that a definition to satisfy that reference must be provided within the current executable or shared object. If this type of symbol reference has no definition within the component being linked, then the reference must have STB_WEAK binding and is resolved to zero.
Second, if any reference to or definition of a name is a symbol with a non-default visibility attribute, the visibility attribute must be propagated to the resolving symbol in the linked object. If different visibility attributes are specified for distinct references to or definitions of a symbol, the most constraining visibility attribute must be propagated to the resolving symbol in the linked object. The attributes, ordered from least to most constraining, are STV_PROTECTED, STV_HIDDEN and STV_INTERNAL.
If a symbol's value refers to a specific location within a section, its section index member, st_shndx, holds an index into the section header table. As the section moves during relocation, the symbol's value changes as well. References to the symbol continue to point to the same location in the program. Some special section index values give other semantics: