ELF Header Fields

15 minintermediateModule 2: ELF HeaderContinues from elf-identification

Why This Matters

The ELF header is the first thing any tool reads. It tells the linker where sections are, the loader where program headers are, and the debugger what architecture the code targets. Every field has a specific purpose — and understanding them means you can read any ELF file.

A Simple Model

The ELF header (after the 16-byte e_ident) contains metadata about the file. Think of it as a table of contents:

The Actual Detail

Here are all fields in the 64-bit ELF header (52 bytes after e_ident, total 64 bytes):

FieldOffsetSizeDescription
e_ident016Identification array (previous concept)
e_type162ET_EXEC (2), ET_DYN (3), ET_REL (1)
e_machine182Architecture: 0x03=x86, 0x3E=x86-64, 0x28=ARM, 0xF3=RISC-V
e_version204ELF version (always 1)
e_entry248Virtual address of entry point
e_phoff328Program header table offset
e_shoff408Section header table offset
e_flags484Processor-specific flags
e_ehsize522ELF header size (64 for 64-bit)
e_phentsize542Program header entry size (56 for 64-bit)
e_phnum562Number of program header entries
e_shentsize582Section header entry size (64 for 64-bit)
e_shnum602Number of section header entries
e_shstrndx622Section name string table index

A Real Example

Here's a real ELF header from a 64-bit Linux binary:

ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  Type:                              DYN (Position-Independent Executable)
  Machine:                           Advanced Micro Devices x86-64
  Entry point address:               0x6810
  Start of program headers:          64 (bytes into file)
  Start of section headers:          16400 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program header entries:    56 (bytes)
  Number of program headers:         9
  Size of section header entries:    64 (bytes)
  Number of section headers:         27
  Section header string table index: 26

Try It

Use readelf -h on different binaries to compare headers. Try the ls, python3, or any compiled program in bin directories.

Check Your Understanding

What field in the ELF header tells the loader where the program header table begins?

Apply It

If e_phnum = 9 and e_phentsize = 56, how many bytes does the program header table occupy?

9 entries × 56 bytes each = 504 bytes total.

Connect

You now understand every field in the ELF header. The entry point field (next concept) deserves special attention — it's where execution begins.