E1 Layout and Structure

As Figure E-1 shows, ELF files consist of various parts. Note that in this context, a distinction must be made between link objects and executable files:

In addition to a few bytes that identify the file as an ELF file, the ELF header holds information on the file type and size or on the entry point at which program execution starts when the file is loaded.

□ 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

Execution View

ELF Header

Program Header Table

Section 1

Section 2

Section n

Section Header Table

ELF Header

Program Header Table

Segment 1

Segment 2

Section Header Table

J Mandatory J Optional

Figure E-1: Basic layout of ELF files.

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

#include<stdio.h>

printf("Numbers are added together\n"); return a+b;

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:

[email protected]> gcc test.c -o test [email protected]> gcc test.c -c -o test.o file shows that the compiler has generated two ELF files — an executable file and a relocatable object file.

[email protected]> file test filetest: ELF 32-bit LSB executable, Intel 80386, version 1, dynamically linked (uses shared libs), not stripped [email protected]> file test.o test.o: ELF 32-bit LSB relocatable, Intel 80386, version 1, not stripped

Continue reading here: E11 ELF Header

Was this article helpful?

0 0