An object file's symbol table holds information needed to locate and relocate a program's symbolic definitions and references. A symbol table index is a subscript into this array. Index 0 both designates the first entry in the table and serves as the undefined symbol index. The contents of the initial entry are specified later in this section.
Name | Value |
---|---|
STN_UNDEF |
0 |
A symbol table entry has the following format.
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
st_value
st_size
st_info
#define ELF32_ST_BIND(i) ((i)>>4) #define ELF32_ST_TYPE(i) ((i)&0xf) #define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf)) #define ELF64_ST_BIND(i) ((i)>>4) #define ELF64_ST_TYPE(i) ((i)&0xf) #define ELF64_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
st_other
st_shndx
sh_link
and sh_info
interpretation
table
and the related text describe,
some section indexes indicate special meanings.
A symbol's binding determines the linkage visibility and behavior.
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
STB_GLOBAL
STB_WEAK
STB_LOOS
through STB_HIOS
STB_LOPROC
through STB_HIPROC
Global and weak symbols differ in two major ways.
STB_GLOBAL
symbols with the same name.
On the other hand, if a defined global symbol exists,
the appearance of a weak symbol with the same name
will not cause an error.
The link editor honors the global definition and ignores
the weak ones.
Similarly, if a common symbol exists
(that is, a symbol whose st_shndx
field holds SHN_COMMON
),
the appearance of a weak symbol with the same name will
not cause an error.
The link editor honors the common definition and
ignores the weak ones.
STB_LOCAL
binding precede the weak and global symbols.
As
``Sections'',
above describes,
a symbol table section's sh_info
section header member holds the symbol table index
for the first non-local symbol.
A symbol's type provides a general classification for the associated entity.
Name | Value |
---|---|
STT_NOTYPE |
0 |
STT_OBJECT |
1 |
STT_FUNC |
2 |
STT_SECTION |
3 |
STT_FILE |
4 |
STT_LOOS |
10 |
STT_HIOS |
12 |
STT_LOPROC |
13 |
STT_HIPROC |
15 |
STT_NOTYPE
STT_OBJECT
STT_FUNC
STT_SECTION
STB_LOCAL
binding.
STT_FILE
STB_LOCAL
binding, its section index is SHN_ABS
,
and it precedes the other STB_LOCAL
symbols for the file, if it is present.
STT_LOOS
through STT_HIOS
STT_LOPROC
through STT_HIPROC
Function symbols (those with type
STT_FUNC
) in shared object files have special significance.
When another object file references a function from
a shared object, the link editor automatically creates a procedure
linkage table entry for the referenced symbol.
Shared object symbols with types other than
STT_FUNC
will not
be referenced automatically through the procedure linkage table.
If a symbol's value refers to a
specific location within a section,
its section index member, st_shndx
,
holds an index into the section header table.
As the section moves during relocation, the symbol's value
changes as well, and references to the symbol
continue to ``point'' to the same location in the program.
Some special section index values give other semantics.
SHN_ABS
SHN_COMMON
sh_addralign
member.
The link editor will allocate the storage for the symbol
at an address that is a multiple of
st_value
.
The symbol's size tells how many bytes are required.
SHN_UNDEF
The symbol table entry for index 0 (STN_UNDEF
)
is reserved; it holds the following.
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 |
st_value
member.
st_value
holds alignment constraints for a symbol
whose section index is SHN_COMMON
.
st_value
holds
a section offset for a defined symbol.
st_value
is an offset from the beginning of the section that
st_shndx
identifies.
st_value
holds a virtual address.
To make these files' symbols more useful
for the dynamic linker, the section offset (file interpretation)
gives way to a virtual address (memory interpretation)
for which the section number is irrelevant.