★★ 演示
#include
int main(int argc, char *argv[])
{
printf("Hello, world\n");
return 0;
}
Relocation section '.rel.plt' at offset 0x278 contains 4 entries:
Offset Info Type Symbol's Value Symbol's Name
0804947c 00107 R_386_JUMP_SLOT 080482d8 __register_frame_info
08049480 00207 R_386_JUMP_SLOT 080482e8 __deregister_frame_info
08049484 00307 R_386_JUMP_SLOT 080482f8 __libc_start_main
08049488 00407 R_386_JUMP_SLOT 08048308 printf
只有R_386_JUMP_SLOT的才会出现在GOT中
Symbol table '.dynsym' contains 7 entries:
Num: Value Size Type Bind Ot Ndx Name
0: 0 0 NOTYPE LOCAL 0 UND
1: 80482d8 116 FUNC WEAK 0 UND __register_frame_info@GLIBC_2.0 (2)
2: 80482e8 162 FUNC WEAK 0 UND __deregister_frame_info@GLIBC_2.0 (
2)
3: 80482f8 261 FUNC GLOBAL 0 UND __libc_start_main@GLIBC_2.0 (2)
4: 8048308 41 FUNC GLOBAL 0 UND printf@GLIBC_2.0 (2)
5: 804843c 4 OBJECT GLOBAL 0 14 _IO_stdin_used
6: 0 0 NOTYPE WEAK 0 UND __gmon_start__
[alert7@redhat]$ gcc -o test test.c
[alert7@redhat]$ ./test
Hello, world
[alert7@redhat]$ gdb -q test
(gdb) disass main
Dump of assembler code for function main:
0x80483d0
0x80483d1
0x80483d3
0x80483d8
0x80483dd
0x80483e0
0x80483e2
0x80483e4
0x80483e5
...
0x80483ef
End of assembler dump.
(gdb) b * 0x80483d8
Breakpoint 1 at 0x80483d8
(gdb) r
Starting program: /home/alert7/test
Breakpoint 1, 0x80483d8 in main ()
(gdb) disass 0x8048308 ① ⑴
Dump of assembler code for function printf:
/****************************************/ //PLT4:
0x8048308
//此时,GOT[6]中存在的是0x804830e
0x804830e
0x8048313
//PLT0处存放着调用RTLD函数的指令
//当函数返回时候,把GOT[6]修改为真正的
//printf函数地址,然后直接跳到printf函数
//执行。
该部分为PLT的一部分
/****************************************/
End of assembler dump.
(gdb) x 0x8049488
0x8049488 <_GLOBAL_OFFSET_TABLE_ 24>: 0x0804830e
080482c8 <.plt>: ② //PLT0:
80482c8: ff 35 74 94 04 08 pushl 0x8049474 //pushl GOT[1]地址
//GOT[1]是个鉴别信息,是link_map类型的一个指针
80482ce: ff 25 78 94 04 08 jmp *0x8049478 //JMP GOT[2]
//跳到动态连接器解析函数执行
80482d4: 00 00 add %al,(陎)
80482d6: 00 00 add %al,(陎)
80482d8: ff 25 7c 94 04 08 jmp *0x804947c //PLT1:
80482de: 68 00 00 00 00 push x0
80482e3: e9 e0 ff ff ff jmp 80482c8 <_init 0x30>
80482e8: ff 25 80 94 04 08 jmp *0x8049480 //PLT2:
80482ee: 68 08 00 00 00 push x8
80482f3: e9 d0 ff ff ff jmp 80482c8 <_init 0x30>
80482f8: ff 25 84 94 04 08 jmp *0x8049484 //PLT3:
80482fe: 68 10 00 00 00 push x10
8048303: e9 c0 ff ff ff jmp 80482c8 <_init 0x30>
8048308: ff 25 88 94 04 08 jmp *0x8049488 //PLT4:
804830e: 68 18 00 00 00 push x18
8048313: e9 b0 ff ff ff jmp 80482c8 <_init 0x30>
(gdb) b * 0x80482c8
Breakpoint 2 at 0x80482c8
(gdb) c
Continuing.
Breakpoint 2, 0x80482c8 in _init ()
(gdb) x/8x 0x8049470
0x8049470 <_GLOBAL_OFFSET_TABLE_>: 0x08049490 0x40013ed0 0x4000a960 0x400fa550
0x8049480 <_GLOBAL_OFFSET_TABLE_ 16>: 0x080482ee 0x400328cc 0x0804830e 0x00000000
(gdb) x/50x 0x40013ed0 ( * link_map类型)
0x40013ed0: 0x00000000 0x40010c27 0x08049490 0x400143e0
0x40013ee0: 0x00000000 0x40014100 0x00000000 0x08049490
0x40013ef0: 0x080494e0 0x080494d8 0x080494a8 0x080494b0
0x40013f00: 0x080494b8 0x00000000 0x00000000 0x00000000
0x40013f10: 0x080494c0 0x080494c8 0x08049498 0x080494a0
0x40013f20: 0x00000000 0x00000000 0x00000000 0x080494f8
0x40013f30: 0x08049500 0x08049508 0x080494e8 0x080494d0
0x40013f40: 0x00000000 0x080494f0 0x00000000 0x00000000
0x40013f50: 0x00000000 0x00000000 0x00000000 0x00000000
0x40013f60: 0x00000000 0x00000000 0x00000000 0x00000000
(gdb) disass 0x4000a960 ③
Dump of assembler code for function _dl_runtime_resolve:
0x4000a960 <_dl_runtime_resolve>: push 陎
0x4000a961 <_dl_runtime_resolve 1>: push 靫
0x4000a962 <_dl_runtime_resolve 2>: push 韝
0x4000a963 <_dl_runtime_resolve 3>: mov 0x10(%esp,1),韝
0x4000a967 <_dl_runtime_resolve 7>: mov 0xc(%esp,1),陎
0x4000a96b <_dl_runtime_resolve 11>: call 0x4000a740
//调用真正的解析函数fixup(),修正GOT[6],使他指向真正的printf函数地址
0x4000a970 <_dl_runtime_resolve 16>: pop 韝
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




