Linux Kernel Architecture

(Jacob Rumans) #1
Mauerer runapp05.tex V1 - 09/04/2008 6:13pm Page 1258

Appendix E: The ELF Binary Format


The primary task of a symbol is to associate a string with a value. For example, theprintfsymbol
represents the address of theprintffunction in virtual address space where the function machine code
resides. Symbols may also have absolute values that are interpreted, for example, as numeric constants.

Theexactpurposeofasymbolisdefinedbyst_info, which is divided into two parts (how the bits
are divided between the two parts is not relevant to this discussion). The following information is
defined:

❑ Thebindingof the symbol. This determines the visibility of a symbol and allows the following
three different settings:

❑ Local symbols(STB_LOCAL), which are visible only within theobject file and are not visible to
other parts of the program when combined. There is no problem if several object files of a
program define symbols with the same names. As long as they are all local symbols, they
do not interfere with each other.
❑ Global symbols(STB_GLOBAL), which are visible within the object file in which they are
defined and can also be referenced by all other object files that make up the program. Each
global symbol may be defined only once within a program; otherwise, the linker would
report an error.
Undefined references that point to a global symbol are supplied with the symbol position
during relocation. If undefined references to global symbols cannot be satisfied, program
execution or static binding is rejected.
❑ Weak symbols(STB_WEAK), which are also visible to the entire program, but can have multi-
ple definitions. If a global symbol and a local symbol have the same name in a program, the
global symbol is automatically given precedence.
Programs are statically or dynamically linked even if a weak symbol remains
undefined — in this case, the value 0 is assigned.

❑ The symboltypeis selected from a number of alternatives, of which only the following three
are relevant to the current topic (a description of the other alternatives is provided in the ELF
standard):

❑ STT_OBJECTindicates that the symbol is associated with a data object such as a variable, an
array, or a pointer.
❑ STT_FUNCis used when the symbol is associated with a function or a procedure.
❑ STT_NOTYPEmeans that the symbol type is not specified. It is used for undefined references.

TheElf32_Symstructure includes other elements in addition tost_name,st_value,andst_info.Their
meanings are as follows:

❑ st_sizespecifies the size of the object; for example, the length of a pointer or the number of
bytes contained in astructobject. Its value can be set to 0 if the size is not known.
❑ st_otheris not used in the current version of the standard.
❑ st_shndxholds the index of a section (in the section header table) with which the symbol is
bound — it is usually defined in the code of this section. However, the following two values
have special meanings:
Free download pdf