Linux Kernel Architecture

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

Appendix E: The ELF Binary Format


0
10
20

01
\0 add Hyper\0
sepac s\0mai
n\0

23456789

Figure E-2: String table for ELF files.

The first byte of the table is a null byte, followed by strings separated by null bytes.

To reference a string, a position must be specified thatis an index into the array. This selects all characters
before the next null byte (if the position of a null byte is used as an index, this corresponds to an empty
string). This supports the (very limited) use of substrings by allowing not just the start position but any
position in the middle of a string to be selected as an index.

.strtabis not the only string table found by default in an ELF file..shstrtabis used to hold the text
names of the individual sections (.text, for example) in the file.

E.2 Data Structures in the Kernel


The ELF file format is used at two points in the kernel. First, it is used to handle executable files and
libraries, and then to implement modules. Different code is used at each of these points to read and
manipulate data, but both instances make use of the data structres introduced in this section. The basis is
the header file<elf.h>, in which the specifications of the standard are implemented virtually unchanged.

E.2.1 Data Types


Because ELF is a processor- and architecture-independent format, it cannot rely on a specific word length
or data alignment (little or big endian) — at least not for elements of the file that need to be read and
understood on all systems. (Machine code, as occurs in the.textsegment, is stored as a representation
of the host system so that no unwieldy conversion operations are needed.) For this reason the kernel
defines a number of data types that have the same bit number on all architectures, as shown here:

<elf.h>
/* 32-bit ELF base types. */
typedef __u32 Elf32_Addr;
typedef __u16 Elf32_Half;
typedef __u32 Elf32_Off;
typedef __s32 Elf32_Sword;
typedef __u32 Elf32_Word;

/* 64-bit ELF base types. */
typedef __u64 Elf64_Addr;
typedef __u16 Elf64_Half;
typedef __s16 Elf64_SHalf;
typedef __u64 Elf64_Off;
typedef __s32 Elf64_Sword;
typedef __u32 Elf64_Word;
typedef __u64 Elf64_Xword;
typedef __s64 Elf64_Sxword;
Free download pdf