typedef struct {
unsigned char e_ident[EI_NIDENT]; /* File identification. */
Elf32_Half e_type; /* File type. */
Elf32_Half e_machine; /* Machine architecture. */
Elf32_Word e_version; /* ELF format version. */
Elf32_Addr e_entry; /* Entry point. */
Elf32_Off e_phoff; /* Program header file offset. */
Elf32_Off e_shoff; /* Section header file offset. */
Elf32_Word e_flags; /* Architecture-specific flags. */
Elf32_Half e_ehsize; /* Size of ELF header in bytes. */
Elf32_Half e_phentsize; /* Size of program header entry. */
Elf32_Half e_phnum; /* Number of program header entries. */
Elf32_Half e_shentsize; /* Size of section header entry. */
Elf32_Half e_shnum; /* Number of section header entries. */
Elf32_Half e_shstrndx; /* Section name strings section. */
} Elf32_Ehdr;010 打开之后是这样的:

ELF header ELF 文件头 里面是基础信息,装载时看的是 Program header,涉及到 ELF header 里的变量 e_phoff 偏移 e_phentsize 每个的大小和 e_phnum 数量。同样,链接时看的是 Section header ,涉及到 ELF header 里的变量 e_shoff 偏移,e_shentsize 每个的大小和 e_shnum 数量,e_shstrndx section 的字符串表
Program header table 一般紧贴着 ELF header,里面长这样

类型、权限、文件里的位置、要加载到虚拟内存中的位置、(现在没用的物理位置)、在文件中的大小、在内存中的大小、对齐大小
Section header 里面长这样 段表


名字、类型、权限、虚拟内存位置(addr)、对应的文件偏移(offset)、大小、关联的 section、其他信息、对齐、某些特别的段的表的每一项的大小(如重定位表、符号表、哈希表、动态链接表这些)
s_name64_t s_name; /* Section name */
s_type64_e s_type; /* Section type */
s_flags64_e s_flags; /* Section attributes */
Elf64_Addr s_addr; /* Virtual address in memory */
Elf64_Off s_offset <format=hex>; /* Offset in file */
Elf64_Xword s_size; /* Size of section */
Elf64_Word s_link; /* Link to other section */
Elf64_Word s_info; /* Miscellaneous information */
Elf64_Xword s_addralign; /* Address alignment boundary */
Elf64_Xword s_entsize; /* Entry size, if section has table */dynamic 段里长这样:

linker 需要获取里面的比较关键的信息是:(d_tag)
DT_NEEDED:依赖的共享库列表。DT_SYMTAB:动态符号表( .dynsym )地址。DT_RELA/DT_REL:重定位表( .rela.plt )地址。DT_JMPREL:PLT 重定位表(通常与 .rela.plt 相同)。DT_HASH/DT_GNU_HASH:符号哈希表地址。