ELF文件结构组成
①总共13个节
②每个节都有一个编号。从ELF头开始编号,编号从0开始,编号的作用就是用来索引(找到)不同节的。
③每个.o的都是这样的结构。链接时要做的就是,将ELF格式的.o全部合成为一个完整的ELF格式可执行文件。
④.o中每个节的逻辑地址都是从0开始的
ELF头
ELF格式头放什内容?
放ELF格式所需要的一些基本信息,比如
①系统所规定的字的大小。64 OS:字大小是64bit 32 OS:字大小是32bit
②字节顺序(字节序) 用于说明系统是大端序的还是小端序的。
③其它
1)ELF格式头的大小
2)目标文件类型(可重定位目标文件、可执行目标文件、共享目标文件)
3)CPU架构:X86 或 X86_64、AMD_64
4)等等
使用readelf,查看“可重定位目标文件”的ELF头信息
readelf:读取目标文件的ELF格式信息的,跟-h选项的话,就是查看ELF格式头信息。
[root@localhost ~]# readelf -h test.o 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 ABI Version: 0 Type: REL (Relocatable file) Machine: Advanced Micro Devices X86-64 Version: 0x1 Entry point address: 0x0 Start of program headers: 0 (bytes into file) Start of section headers: 664 (bytes into file) Flags: 0x0 Size of this header: 64 (bytes) Size of program headers: 0 (bytes) Number of program headers: 0 Size of section headers: 64 (bytes) Number of section headers: 13 Section header string table index: 12