且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

什么是程序连接表的目的是什么?

更新时间:2021-07-13 21:46:11

有关从PIC code的通话,你是正确的,是不是真的需要的PLT。编译器可能刚以及生成GOT查找和间接调用从GOT得到的地址。使用PLT往往使code稍微更有效,虽然(至少,每次通话较少的尺寸膨胀),所​​以它一般还是使用。

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 code这是动态的链接。 (这通常只发生在主程序;许多archs,非PIC code根本不准/共享库的支持。)当编译器为函数调用生成非PIC code,它有没有办法知道实际的目标地址将在通过GOT运行时动态解析。所以它只是产生一个普通的调用指令。然后,链接程序负责,当它看到一个呼叫类型的拆迁那不是本地解析的象征,需要运行时链接,生成加载从GOT的地址,使间接跳转到它的PLT条目。这样一来,原来的非PIC函数调用code工作不变。

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.