我知道ELF文件包含段和部分,以及提供有关其内容信息的标题。此外,ELF 部分用于组织段内的数据。
在下面的示例中,您可以清楚地看到 readelf 输出中列出的 .text 和 .data 部分,但程序标头没有列出"文本"或"数据"段。
ELF 文件中的文本和数据段与 .text 和 .data 部分有什么区别?
示例 Hello World 程序:
#include <stdio.h>
int main()
{
puts("hello world");
return 0;
}
显示 ELF 段标题:
$ readelf -l hello
Elf file type is EXEC (Executable file)
Entry point 0x8049050
There are 11 program headers, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
PHDR 0x000034 0x08048034 0x08048034 0x00160 0x00160 R 0x4
INTERP 0x000194 0x08048194 0x08048194 0x00013 0x00013 R 0x1
[Requesting program interpreter: /lib/ld-linux.so.2]
LOAD 0x000000 0x08048000 0x08048000 0x002e8 0x002e8 R 0x1000
LOAD 0x001000 0x08049000 0x08049000 0x0022c 0x0022c R E 0x1000
LOAD 0x002000 0x0804a000 0x0804a000 0x0019c 0x0019c R 0x1000
LOAD 0x002f0c 0x0804bf0c 0x0804bf0c 0x00110 0x00114 RW 0x1000
DYNAMIC 0x002f14 0x0804bf14 0x0804bf14 0x000e8 0x000e8 RW 0x4
NOTE 0x0001a8 0x080481a8 0x080481a8 0x00044 0x00044 R 0x4
GNU_EH_FRAME 0x002014 0x0804a014 0x0804a014 0x0004c 0x0004c R 0x4
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x10
GNU_RELRO 0x002f0c 0x0804bf0c 0x0804bf0c 0x000f4 0x000f4 R 0x1
Section to Segment mapping:
Segment Sections...
00
01 .interp
02 .interp .note.gnu.build-id .note.ABI-tag .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt
03 .init .plt .text .fini
04 .rodata .eh_frame_hdr .eh_frame
05 .init_array .fini_array .dynamic .got .got.plt .data .bss
06 .dynamic
07 .note.gnu.build-id .note.ABI-tag
08 .eh_frame_hdr
09
10 .init_array .fini_array .dynamic .got
段用于在文件运行时执行文件。节是用于链接和重新定位的数据文件。 Dot(.( 是目录(在 Unix 上(的快捷方式 当你找到路径时,这些就会出来。在 Linux 上,shell 不会通过 defaoult,从目录中查找,如果它不在 PATH 中。但是,如果您愿意,可以从您的/Home/.profile使用Vim,Nano等。