文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
1. 段
可执行文件由不同用途的段(section/segment)组成。
.text
: 二进制机器码。.data
: 有初始化值的全局变量。.bss
: 无初始化值的全局变量。.rodata
: 只读数据。
查看段相关信息。
$ readelf -S ./test Section Headers: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0 [ 1] .text PROGBITS 0000000000401000 00001000 0000000000000029 0000000000000000 AX 0 0 16 [ 2] .roata PROGBITS 0000000000402000 00002000 000000000000000e 0000000000000000 A 0 0 1 [ 3] .stab PROGBITS 0000000000000000 00002010 000000000000009c 0000000000000014 4 0 4 [ 4] .stabstr STRTAB 0000000000000000 000020ac 0000000000000008 0000000000000000 0 0 1 [ 5] .symtab SYMTAB 0000000000000000 000020b8 0000000000000138 0000000000000018 6 9 8 [ 6] .strtab STRTAB 0000000000000000 000021f0 0000000000000030 0000000000000000 0 0 1 [ 7] .shstrtab STRTAB 0000000000000000 00002220 0000000000000037 0000000000000000 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), l (large), p (processor specific)
$ readelf -l ./test Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flags Align LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000 0x00000000000000e8 0x00000000000000e8 R 0x1000 LOAD 0x0000000000001000 0x0000000000401000 0x0000000000401000 0x0000000000000029 0x0000000000000029 R E 0x1000 LOAD 0x0000000000002000 0x0000000000402000 0x0000000000402000 0x000000000000000e 0x000000000000000e R 0x1000 Section to Segment mapping: Segment Sections... 00 01 .text 02 .roata
注意,段名区分大小写。错误拼写可能导致段无法被赋予正确的权限属性,造成程序头映射错误、反汇编故障、调试故障等。如果将源码中的 .text
改成 .TEXT
。
$ readelf -S ./test Section Headers: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [ 2] .TEXT PROGBITS 000000000040100e 0000100e 0000000000000029 0000000000000000 A 0 0 1 # 没有 X !!!
$ readelf -l ./test Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flags Align LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000 0x0000000000001037 0x0000000000001037 R 0x1000 Section to Segment mapping: Segment Sections... 00 .roata .TEXT # 和 rodata 混在一起。
$ objdump -d -M intel ./test ./test: file format elf64-x86-64 # 找不到代码段。
$ gdb ./test Reading symbols from ./test... Can't find any code sections in symbol file
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论