1.1.1 整体结构
ELF对象格式用于目标文件(.o扩展名)和执行文件. 有些信息只出现在目标文件或执行文件中.
ELF文件由下列部件构成. ELF header必须放在文件的开始;其他部件可以随便排放(ELF header给出了其他部件的偏移量).
ELF文件构件:
Section
描述
ELF header
一般信息.
Program header table
执行文件信息;只出现在执行文件中.
Section data
Section的实际数据;一些section有特殊的含义,
例如: symbol table和string table.
Section headers
不同ELF section信息; 每个section一个.
典型ELF文件结构:
ELF Header
Program Header Table
Section 1 Data
……
Section n Data
Section Header Table
1.1.2 ELF头[ELF Header]
ELF头包含目标文件的一般信息;具有如下结构(from elf.h):
#define EI_NIDENT 16
typedef struct {
unsigned char e_ident[EI_NIDENT];
Elf32_Half e_e_type;
Elf32_Half e_machine;
Elf32_Word e_version;
Elf32_Addr e_entry;
Elf32_Off e_phoff;
Elf32_Off e_shoff;
Elf32_Word e_flags;
Elf32_Half e_ehsize;
Elf32_Half e_phentsize;
Elf32_Half e_phnum;
Elf32_Half e_shentsize;
Elf32_Half e_shnum;
Elf32_Half e_shstrndx;
};
ELF头域描述:
域
描述
e_ident
16字节串: 4字节标识: '_ELF'
1字节class: 32位对象->1
1字节数据编码: litte-endian->1,big-endian->2
1字节版本: 当前版本->1
9字节零填充
e_type
文件类型: 可重定位->1,可执行-