GOT & PLT
.got
和.plt
是ELF文件中存在的两个特殊的节
.got
:GOT(Global Offset Table)全局偏移表。这是「链接器」为「外部符号」填充的实际偏移表.plt
: PLT(Procedure Linkage Table)程序链接表。它有两个功能,要么在.got.plt
节中拿到地址,并跳转。要么当.got.plt
没有所需地址的时,触发「链接器」去找到所需地址
GOT和PLT的作用是什么?为什么要有这两个表?
got和plt是怎么工作的?
参考这篇文章学习了got和plt的工作流程。
新建一个程序
// gcc -m32 -no-pie -g -o plt plt.c
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
puts("Hello world!");
exit(0);
}
编译后来看一下节信息
root@kali:~/study# readelf -S plt
There are 34 section headers, starting at offset 0x3a2c:
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
...
[12] .plt PROGBITS 08049020 001020 000040 04 AX 0 0 16
...
[20] .dynamic DYNAMIC 0804bf14 002f14 0000e8 08 WA 6 0 4
[21] .got PROGBITS 0804bffc 002ffc 000004 04 WA 0 0 4
[22] .