Linux Kernel Architecture

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

Appendix E: The ELF Binary Format


As you can see in the following code, a similar data structure is defined for 64-bit architectures. The only
difference as compared to the 32-bit variant is that other data types are used. Nevertheless, the meaning
of the entries is the same:

<elf.h>
typedef struct elf64_phdr {
Elf64_Word p_type;
Elf64_Word p_flags;
Elf64_Off p_offset; /* Segment file offset */
Elf64_Addr p_vaddr; /* Segment virtual address */
Elf64_Addr p_paddr; /* Segment physical address */
Elf64_Xword p_filesz; /* Segment size in file */
Elf64_Xword p_memsz; /* Segment size in memory */
Elf64_Xword p_align; /* Segment alignment, file & memory */
} Elf64_Phdr;

SectionHeader


The section header table is implemented by means of an array in which each entry contains a section. The
individual sections form the contents of the segments defined in the program header table. The following
data structure represents a section:

<elf.h>
typedef struct {
Elf32_Word sh_name;
Elf32_Word sh_type;
Elf32_Word sh_flags;
Elf32_Addr sh_addr;
Elf32_Off sh_offset;
Elf32_Word sh_size;
Elf32_Word sh_link;
Elf32_Word sh_info;
Elf32_Word sh_addralign;
Elf32_Word sh_entsize;
} Elf32_Shdr;

The elements have the following meanings:

❑ sh_namespecifies the name of the section. Its value is not the string itself but an index into the
section header string table.
❑ sh_typespecifies the section type. The following section types are available:

❑ SH_NULLindicates that the section is not used. Its data are ignored.
❑ SH_PROGBITSholds program-specific information whose format is undefined and is irrele-
vant to this discussion.
❑ SH_SYMTABholds a symbol table whose structure is discussed in Section E.2.4.SH_DYNSYM
also holds a symbol table. The difference between these two types is discussed later in this
appendix.
❑ SH_STRTABindicates a section that contains a string table.
❑ SH_RELAandSHT_RELAhold relocation sections whose structure is discussed in
Section E.2.5.
Free download pdf