标签:
l 可重定位:
编译器和汇编器创建
运行前需要被链接器处理
l 可执行
完成了所有重定位工作和符号解析
除了运行时解析的共享库符号
l 共享库
链接器需要的符号信息
运行时可以直接执行的代码

|
ELF头部 |
|
.text |
|
.rodata |
|
.data |
|
.bss |
|
.sym |
|
.rel.txt |
|
.rel.data |
|
.line |
|
.debug |
|
.strtab |
|
节头部表 |
自编一个简单的程序,并对其进行编译。生成一些elf文件:

在终端中键入hexdump -x hello,会看到很多16进制编码。
数据均为16进制数据(因为使用了-x选项),并且第一列为偏移地址。
使用下面命令来显示hello中各个段相关信息:objdump –x hello
输出结果如下:

也可以用下面的命令来查看各个段信息:
readelf -a hello
下面分析hello文件内容
首先是Elf文件头,其定义为(在/usr/include/elf.h中)64位系统包括两部分:



typedef struct
{
Elf32_Word sh_name; /* Section name (string tbl index) */
Elf32_Word sh_type; /* Section type */
Elf32_Word sh_flags; /* Section flags */
Elf32_Addr sh_addr; /* Section virtual addr at execution */
Elf32_Off sh_offset; /* Section file offset */
Elf32_Word sh_size; /* Section size in bytes */
Elf32_Word sh_link; /* Link to another section */
Elf32_Word sh_info; /* Additional section information */
Elf32_Word sh_addralign; /* Section alignment */
Elf32_Word sh_entsize; /* Entry size if section holds table */
} Elf32_Shdr;
typedef struct
{
Elf64_Word sh_name; /* Section name (string tbl index) */
Elf64_Word sh_type; /* Section type */
Elf64_Xword sh_flags; /* Section flags */
Elf64_Addr sh_addr; /* Section virtual addr at execution */
Elf64_Off sh_offset; /* Section file offset */
Elf64_Xword sh_size; /* Section size in bytes */
Elf64_Word sh_link; /* Link to another section */
Elf64_Word sh_info; /* Additional section information */
Elf64_Xword sh_addralign; /* Section alignment */
Elf64_Xword sh_entsize; /* Entry size if section holds table */
} Elf64_Shdr;


第二行:e_type(两个字节)值为0x0002,表示是可执行文件。
标签:
原文地址:http://www.cnblogs.com/20135302wei/p/5532421.html