Why does the PLT exist in addition to the GOT, instead of just using the GOT?

前端 未结 2 1141
说谎
说谎 2020-12-04 23:01

I understand that in a typical ELF binary, functions get called through the Procedure Linkage Table (PLT). The PLT entry for a function usually contains a jump to a Global O

2条回答
  •  一生所求
    2020-12-04 23:42

    Now I'm wondering why there are two indirections (calling into the PLT and then jumping to an address from the GOT),

    First of all there are two calls, but just one indirection (call to PLT stub is direct).

    instead of just sparing the PLT and calling the address from the GOT directly.

    In case you do not need lazy binding, you can use -fno-plt which bypasses the PLT.

    But if you wanted to keep it, you'd need some stub code to see if symbol has been resolved and branch accordingly. Now, to facilitate branch prediction, this stub code has to be duplicated for every called symbol and voila, you re-invented the PLT.

提交回复
热议问题