【问题标题】:how compiler select which "get_pc_thunk" function to get current address?编译器如何选择哪个“get_pc_thunk”函数来获取当前地址?
【发布时间】:2018-08-15 14:44:34
【问题描述】:

PIE 二进制文件使用函数__x86.get_pc_thunk 来获取在加载时动态定义的地址。


i) 有时它会调用__x86.get_pc_thunk.ax

5ff:   e8 24 00 00 00          call   628 <__x86.get_pc_thunk.ax>
604:   05 fc 19 00 00          add    $0x19fc,%eax
609:   83 ec 0c                sub    $0xc,%esp
60c:   8d 90 b0 e6 ff ff       lea    -0x1950(%eax),%edx
612:   52                      push   %edx
613:   89 c3                   mov    %eax,%ebx
615:   e8 36 fe ff ff          call   450 <printf@plt>


ii) 有时它会调用__x86.get_pc_thunk.bx

634:   e8 87 fe ff ff          call   4c0  <__x86.get_pc_thunk.bx>
639:   81 c3 c7 19 00 00       add    $0x19c7,%ebx
63f:   83 ec 0c                sub    $0xc,%esp
642:   8b 6c 24 20             mov    0x20(%esp),%ebp
646:   8d b3 f0 fe ff ff       lea    -0x110(%ebx),%esi
64c:   e8 cb fd ff ff          call   41c <_init>


iii) 有时它调用__x86.get_pc_thunk.cx 或有时__x86.get_pc_thunk.dx



我知道__x86.get_pc_thunk.bx__x86.get_pc_thunk.ax 之间的区别在于寄存器,将返回地址存储在.bxEBX.axEAX


那么,我的问题是:

编译器如何在__x86.get_pc_thunk.ax/__x86.get_pc_thunk.bx/__x86.get_pc_thunk.cx/__x86.get_pc_thunk.dx中选择使用哪个函数?

它是在编译时真正随机选择的吗?
或者有什么算法可以选择吗?

【问题讨论】:

    标签: gcc assembly x86 register-allocation position-independent-code


    【解决方案1】:

    编译器为它想要使用的任何寄存器选择适当的函数。使用哪个寄存器是编译器对它所编译的函数的寄存器分配的结果,一般是不可预测的。

    【讨论】:

    • 我明白了。。谢谢你的回答。
    猜你喜欢
    • 2020-09-30
    • 1970-01-01
    • 1970-01-01
    • 2017-04-05
    • 1970-01-01
    • 2021-03-16
    • 2014-10-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多