过程链接表的目的是什么? [英] What is the purpose of the procedure linkage table?

查看:14
本文介绍了过程链接表的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇为什么存在过程链接表.它的用途是什么?程序集不能直接调用全局偏移表吗?调用 PLT 比调用 Global Offset Table 有什么优势?

I'm curious why the Procedure Linkage Table exists. What purpose does it serve? Couldn't the assembly call the global offset table directly? What advantage does calling the PLT have over calling the Global Offset Table?

整个过程对我来说仍然有点困惑,我正在尝试找出动态链接的来龙去脉,因此我们将不胜感激.

The whole process is still kind of confusing to me and I'm trying to figure out the in's and out's of dynamic linking so any help would be appreciated.

推荐答案

对于从 PIC 代码进行的调用,您是正确的,PLT 并不是真正需要的.编译器可以很好地生成 GOT 查找并间接调用从 GOT 获得的地址.不过,使用 PLT 往往会使代码更高效(至少每次调用的体积膨胀较小),因此无论如何通常都会使用它.

For calls made from PIC code, you are correct that the PLT is not really needed. The compiler could just was well generate a GOT lookup and indirect call to the address obtained from the GOT. Using a PLT tends to make the code slightly more efficient though (at least, less size bloat per call) so it's generally used anyway.

然而,绝对需要 PLT 的地方是动态链接的非 PIC 代码.(通常这只发生在主程序中;在许多拱门上,共享库中甚至不允许/支持非 PIC 代码.)当编译器为函数调用生成非 PIC 代码时,它无法知道实际目标地址将在运行时通过 GOT 动态解析.所以它只是生成一个普通的调用指令.然后,当链接器看到一个未在本地解析且需要运行时链接的符号的调用类型重定位时,链接器负责生成一个 PLT 条目,该条目从 GOT 加载地址并间接跳转到它.这样,原始的非 PIC 函数调用代码无需修改即可工作.

Where the PLT is absolutely needed, however, is in non-PIC code that's dynamic linked. (Usually this occurs only in the main program; on many archs, non-PIC code is not even allowed/supported in shared libraries.) When the compiler generates non-PIC code for a function call, it has no way to know that the actual destination address will be resolved dynamically at runtime via the GOT. So it just generates an ordinary call instruction. The linker then is responsible, when it sees a call-type relocation for a symbol that's not resolved locally and that requires runtime linking, for generating a PLT entry that loads the address from the GOT and makes an indirect jump to it. This way, the original non-PIC function call code works unmodified.

这篇关于过程链接表的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆