2.1 Symbol Table

The symbol table uses Hanson's table ADT. Its type is Table_T, and its functions include Table_get, Table_put, Table_length, Table_map, etc. Each entry in the symbol table is a key-value pair. The key is a string of symbol name. And the value is of type Elf32_Sym (defined in sys/elf.h) that has the following structure:
 
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;

st_name

This member is always 0.
st_value
For a defined symbol, this member holds its section offset. That is, st_value is a byte offset from the beginning of the section that st_shndx identifies. For an undefined symbol, it holds 0.
st_size
This member is always 0.
st_info
This member specifies a symbol's binding attribute and type. Table 2.1.1 shows the bindings and types for different symbols. Table 2.1.2 shows how to manipulate the value of st_info with macros (defined in sys/elf.h):

Table 2.1.1 Symbol Bindings and Types

Symbol
Example
Binding
 Type
Local Symbol
defined local symbol
STB_LOCAL
STT_NOTYPE
Global Symbol
global symbol
STB_GLOBAL
STT_NOTYPE

Table 2.1.2 st_info Macros

Macro
Meaning
ELF32_ST_BIND(i)
Extract binding from st_info i
ELF32_ST_TYPE(i)
Extract type from st_info i
ELF32_ST_INFO(b, t)
Compose st_info with binding b and type t

st_other

This member holds a symbol's unique non-negative sequence number.
st_shndx
Every symbol is defined in relation to some section; this member holds the relevant section header table index. Table 2.1.3 shows its values.

Table 2.1.3 Section Header Table Indices of Symbols

Section Header Table Index
Symbol
UNDEF_NDX
undefined symbol
TEXT_NDX
symbol defined in .text section
DATA_NDX
symbol defined in .data section
BSS_NDX
symbol defined in .bss section
table of content