E14 Symbol Table

libraries or by means of dynamic linking at load time (using ld-linux.so). The nm tool generates a list of all symbols defined and used by a program, as shown here:

[email protected]> nm test.o 00000000 T add

U exit 0000001a T main

U printf

The left column shows the symbol value — the object file position at which the symbol definition is located. The example includes two different symbol types — functions defined in the text segment (as indicated by the abbreviation t) and undefined references indicated by a U. Logically, the undefined references do not have a symbol value.

Many more symbols appear in executable files. However, because most are generated automatically by the compiler and are used for internal purposes of the runtime system, the following example shows only the elements that also appeared in the object file:

[email protected]> nm test 08048388 T add

U [email protected]@GLIBC_2.0 080483a2 T main

U [email protected]@GLIBC_2.0

exit and printf remain undefined, but in the meantime, information has been added indicating the earliest version of the GNU standard library from which the functions must be taken (in the example, no version earlier than 2.0 may be used, which means that the program does not function with Libc5 and Libc47). The add and main symbols defined by the program have been moved to fixed positions in virtual address space (their code was mapped to these positions when the file was loaded).

How is the symbol table mechanism implemented in ELF? The following three sections are used to accept the relevant data:

□ .symtab establishes the link between the name of a symbol and its value. However, the symbol name is not coded directly as a string but indirectly as a number that is used as an index into a string array.

□ .strtab holds the string array.

□ .hash holds a hash table that helps find symbols quickly.

Expressed in simple terms, each entry in the .symtab section consists of two elements — the position of the name in the string table and the associated value. (As you will see next, the real situation is a little more complicated, because more information needs to be considered for each entry.)

Continue reading here: E15 String Tables

Was this article helpful?

0 0