Linux Kernel Architecture

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

Appendix E: The ELF Binary Format.........................................


❑ The program header table provides the system with information on how the data of an
executable file is to be arranged in the virtual address space of a process. It also indicates
how many sections the file may contain, where they are located, and what purpose
they serve.
❑ The individual sections hold the various forms of data associated with a file; for example, the
symbol table, the actual binary code or fixed values such as strings, or numeric constants used
by the program.
❑ The section header table contains additional information on the individual sections.

Link View

Program
Header Table
Section 1
Section 2

...
Section n
Section
Header Table


ELF Header

Execution View

Program
Header Table

Segment 1

Segment 2

Section
Header Table

ELF Header Mandatory
Optional

...


Figure E-1: Basic layout of ELF files.

readelfis a useful tool for analyzing the structure of ELF files, as demonstrated in the following simple
program.

#include<stdio.h>

int add (int a, int b) {
printf("Numbers are added together\n");
return a+b;
}

int main() {
int a,b;
a=3;
b=4;
int ret = add(a,b);
printf("Result: %u\n");
exit(0);
}

Of course, this program is not necessarily the most useful of its kind, but it serves as a good example to
illustrate how an executable file and an object file are generated:

wolfgang@meitner>gcc test.c -o test
wolfgang@meitner>gcc test.c -c -o test.o
Free download pdf