- 论坛徽章:
- 0
|
看例子:
int main()
{
printf("hello\n");
} |
a.out:
08048354 <main>:
8048354: 8d 4c 24 04 lea 0x4(%esp),%ecx
8048358: 83 e4 f0 and $0xfffffff0,%esp
804835b: ff 71 fc pushl 0xfffffffc(%ecx)
804835e: 55 push %ebp
804835f: 89 e5 mov %esp,%ebp
8048361: 51 push %ecx
8048362: 83 ec 04 sub $0x4,%esp
8048365: c7 04 24 58 84 04 08 movl $0x8048458,(%esp)
804836c: e8 0b ff ff ff call 804827c <puts@plt>
8048371: 83 c4 04 add $0x4,%esp
8048374: 59 pop %ecx
8048375: 5d pop %ebp
8048376: 8d 61 fc lea 0xfffffffc(%ecx),%esp
8048379: c3 ret
|
1、
804836c: e8 0b ff ff ff call 804827c <puts@plt>
2、
0804827c <puts@plt>:
804827c: ff 25 50 95 04 08 jmp *0x8049550
8048282: 68 00 00 00 00 push $0x0
8048287: e9 e0 ff ff ff jmp 804826c <_init+0x18>
--------------------------------------------------------------------------------------------------------
跳到 [0x8049550]
3、看看 [0x8049550] 是啥:
8049550: 82 (bad)
8049551: 82 (bad)
8049552: 04 08 add $0x8,%al
---------------------------------------------------------------------------------------------
8049550 ~ 8049553 四个字节是: 0x08048282
也就是 jmp 到 0x08048282
4、再看看 0x08048282 处:
804827c: ff 25 50 95 04 08 jmp *0x8049550
8048282: 68 00 00 00 00 push $0x0
8048287: e9 e0 ff ff ff jmp 804826c <_init+0x18>
----------------------------------------------------------------------------------------------------
再跳到 0x084826c:
看看 0x084826c:
0804826c <puts@plt-0x10>:
804826c: ff 35 48 95 04 08 pushl 0x8049548
8048272: ff 25 4c 95 04 08 jmp *0x804954c
8048278: 00 00 add %al,(%eax)
---------------------------------------------------------------------------------------------------------------
又跳到 [0x084954c]
5、最终去到:
08049544 <_GLOBAL_OFFSET_TABLE_>:
8049544: 78 94 js 80494da <_DYNAMIC+0x62>
8049546: 04 08 add $0x8,%al
...
8049550: 82 (bad)
8049551: 82 (bad)
8049552: 04 08 add $0x8,%al
8049554: 92 xchg %eax,%edx
8049555: 82 (bad)
8049556: 04 08 add $0x8,%al
8049558: a2 .byte 0xa2
8049559: 82 (bad)
804955a: 04 08 add $0x8,%al
------------------------------------------------------------------------------------------------------
这是真正的 puts() 函数的入口地方
上面没有列出 0x804954c 处的值
将上面的共享库中的函数调用流程归纳为:
main():----> <puts@plt>: -----> <_GLOBAL_OFFSET_TABLE_>: -----> <puts@plt>: ---> <puts@plt-0x10>:
-----------------------> <_GLOBAL_OFFSET_TABLE_>: ---------> /lib/ld-linux.so.2 ----------> puts()
在 linux 下所有的共享库函数调用流程都是这样:
(1)每个导入的函数生成 PLT 表格
(2)GLOBAL_OFFSET_TABLE 中存放最入动态加载器 ld-linux.so.2 入口
(3)由 ld-linux.so.2 最终动态加载共享函数实体
------------------------------------------------------------------------------
PLT 与 GOT 表是在用户程序代码中生成,/lib/ld-linux.so.2 与 <函数实体> 是在共享库中。 |
|