Linux Kernel Architecture

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

Appendix E: The ELF Binary Format


Program Header


The program header table consists of several entries that are handled in the same way as the entries of an
array (the number of entries is specified bye_phnumin the ELF header). A separate structure is defined
as a data type for the entries. On 32-bit systems, it has the following contents:

<elf.h>
typedef struct elf32_phdr{
Elf32_Word p_type;
Elf32_Off p_offset;
Elf32_Addr p_vaddr;
Elf32_Addr p_paddr;
Elf32_Word p_filesz;
Elf32_Word p_memsz;
Elf32_Word p_flags;
Elf32_Word p_align;
} Elf32_Phdr;

The meaning of the elements is as follows:

❑ p_typeindicates what kind of segment the current entry describes. The following constants are
defined for this purpose:

❑ PT_NULLindicates an unused segment.
❑ PT_LOADis used for loadable segments that are mapped from the binary file into memory
before the program can be executed.
❑ PT_DYNAMICindicates that the segment contains information for the dynamic linker (dis-
cussed in Section E.2.6).
❑ PT_INTERPindicates that the current segment specifies the program interpreter used for
dynamic linking. Usually, this isld-linux.soas previously mentioned.
❑ PT_NOTEspecifies a segment that may contain additional proprietary compiler information.

Two further variants (PT_LOPROCandPT_HIGHPROC) are defined for processor-specific purposes
but are not used by the kernel.
❑ p_offsetgives the offset (in bytes from the beginning of the binary file) at which the data of the
segment described resides.
❑ p_vaddrgives the position in virtual address space to which the data of the segment is mapped
(for segments of thePT_LOADtype). Systems that support physical but not virtual addressing use
the information stored inp_paddrinstead.
❑ p_fileszspecifies the size (in bytes) of the segment in the binary file.
❑ p_memszspecifies the size (in bytes) of the segment in virtual address space. Size differences as
compared with the physical segments are compensated by truncating data or padding with null
bytes.
❑ p_flagsholds flags to define access permissions to the segment.PF_Rgives read permission,
PF_Wgives write permission, andPF_Xgives execute permission.
❑ p_alignspecifies how the segment is to be aligned in memory and in the binary file (thep_vaddr
andp_offsetaddresses must be modulop_align). Ap_alignvalue of 0x 1000 =4096 means,
for example, that the segment must be aligned on 4 KiB pages.
Free download pdf