Linux Kernel Architecture

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

Appendix E: The ELF Binary Format


The following two sections are used to hold data required by the dynamic linker:

❑ .dynsymholds a symbol table with all symbols resolved by means of external references.
❑ .dynamicholds an array with elements of theElf32_Dyntype — these supply the data described
in the following paragraphs.

The contents of.dynsymcan be queried usingreadelf, as shown here:

wolfgang@meitner>readelf — syms test
Symbol table ’.dynsym’ contains 7 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 08049474 0 OBJECT GLOBAL DEFAULT 15 __dso_handle
2: 0804829c 206 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.0 (2)
3: 080482ac 47 FUNC GLOBAL DEFAULT UND printf@GLIBC_2.0 (2)
4: 080482bc 257 FUNC GLOBAL DEFAULT UND exit@GLIBC_2.0 (2)
5: 08048444 4 OBJECT GLOBAL DEFAULT 14 _IO_stdin_used
6: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
...

The contents include not only a number of symbols added automatically when the executable file is
generated, but also theprintandexitfunctions used in the machine code.@GLIBC_2.0specifies that
at leastversion 2.0 of the GNU standard library must be used in order to resolve the references.

The data type of the array entries in the.dynamicsection is defined in the kernel as follows, but is not
used at all because the information is interpreted in userspace:

<elf.h>
typedef struct dynamic{
Elf32_Sword d_tag;
union{
Elf32_Sword d_val;
Elf32_Addr d_ptr;
} d_un;
} Elf32_Dyn;

d_tagis used to distinguish between various tags that specify the type of information described by the
entry.d_unholds either a virtual address or an integer that is interpreted differently depending on the
particular tag.

The most important tags are as follows:

❑ DT_NEEDEDspecifies which dynamic libraries are needed to execute the program.d_unpoints to
a string table entry with the name of the library.
Only the C standard library is required for thetest.ctest application, as the followingreadelf
test shows:
wolfgang@meitner>readelf — dynamic test
Dynamic segment at offset 0x480 contains 20 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libc.so.6]
...
Free download pdf