ELF file type
ELF (executable linkable format) is the executable file format under Linux, as in the PE (portable executable) format under Windows, COFF (Common File format) A variant of the file format. Under Linux, in addition to executable files, the target files (. o files) generated during compilation, dynamic link files (. so files), static link library files (. A files), and core dump files are stored in ELF format. View ELF file types can be used with the file command.
ELF file Structure
The ELF file structure is fully defined in/usr/include/elf.h, with some useful commands:
file elf_file 输出 ELF 各个段的 sizereadelf [options] elf_file-S 输出 section header-t 输出符号表 symbol table-h 输出 ELF 文件头信息objdump [options] elf_file-h 输出文件基本 ELF 信息-d 反汇编代码段-s 输出完整内容-r 查看重定位表-D 反汇编所有段内容-S 输出内容包含源代码(需要 gcc -g 参数支持)
Some of the more important segments of the ELF structure:
.data 数据段,存放已经初始化的全局/静态变量.bss(Block Started by Symbol) 存放未初始化的全局变量和静态变量,因为这些变量在程序加载的时候都会被初始化为零,所以不需要存放实际的数据,只需要预留位置就可以了。.text 代码段,存放源代码编译后的机器指令.rodata 只读数据段,存放只读变量.symtab(Symbol Table) 符号表.strtab(String Table) 字符串表.plt(Procedure Linkage Table) 动态链接跳转表.got(Global Offset Table) 动态链接全局入口表
Dynamic links and static links
During static linking, the compiler writes the symbols that need relocation to the relocation table in the ELF structure (relocation table), and then the linker (Linker) analyzes the relocation table, finds the address of the corresponding symbol from the global symbol table, and completes the relocation.
If you want the object file generated by a code file to be dynamically linked, you need to specify the-fpic parameter to GCC at compile time, and the PIC (Position Independent code) is the location-independent.
Linux ELF file format