我真的很想了解高级代码 -> 可执行文件的步骤.. 但我遇到了一些困难。
我写了一个空的 int main() {}
C 文件,并试图通过 objdump -d
破译反汇编。这是正在发生的事情:
- 在
_start
中,设置对齐方式,将参数压入堆栈,调用__libc_start_main
- 在
__libc_start_main
中,执行的第一行是jmp *0x8049658
但是,在使用objdump -R
来检查重定位记录时,0x8049658
中的值是__libc_start_main
本身!
我在这里遗漏了一些东西..
编辑:这是一些来源;
080482c0 <__libc_start_main@plt>:
80482c0: ff 25 58 96 04 08 jmp *0x8049658
80482c6: 68 08 00 00 00 push $0x8
80482cb: e9 d0 ff ff ff jmp 80482a0 <_init+0x2c>
Disassembly of section .text:
080482d0 <_start>:
80482d0: 31 ed xor %ebp,%ebp
80482d2: 5e pop %esi
80482d3: 89 e1 mov %esp,%ecx
80482d5: 83 e4 f0 and $0xfffffff0,%esp
80482d8: 50 push %eax
80482d9: 54 push %esp
80482da: 52 push %edx
80482db: 68 50 84 04 08 push $0x8048450
80482e0: 68 e0 83 04 08 push $0x80483e0
80482e5: 51 push %ecx
80482e6: 56 push %esi
80482e7: 68 d0 83 04 08 push $0x80483d0
80482ec: e8 cf ff ff ff call 80482c0 <__libc_start_main@plt>
80482f1: f4 hlt
80482f2: 66 90 xchg %ax,%ax
DYNAMIC RELOCATION RECORDS
OFFSET TYPE VALUE
08049644 R_386_GLOB_DAT __gmon_start__
08049654 R_386_JUMP_SLOT __gmon_start__
08049658 R_386_JUMP_SLOT __libc_start_main
最佳答案
第一个 block 以“@plt”结尾,是过程链接表 ( https://stackoverflow.com/a/5469334/994153 )。 jmp *0x8049658
是一个间接分支指令,所以它实际上是跳转到 __libc_start_main
,无论它在运行时 实际上 最终加载到 RAM 中。
__libc_start_main
的真实 RAM 地址可在 DYNAMIC RELOCATION RECORDS 表中找到,该表由动态加载程序在加载程序时在 RAM 中创建。
关于c - __libc_start_main 中发生了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16970281/