什么是 __i686.get_pc_thunk.bx?为什么我们需要这个电话?
当我反汇编我的小函数时,我碰巧看到这个调用,
call 0xf60d2f47 <__i686.get_pc_thunk.bx>.
我不知道为什么我的程序中需要这个调用。任何解释都会有帮助。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此调用用在 x86 上的位置无关代码中。它将代码的位置加载到
%ebx
寄存器中,这允许全局对象(与代码有固定的偏移量)作为该寄存器的偏移量进行访问。与位置无关的代码是可以在不同地址不经修改地加载和执行的代码。这对于将链接到共享库的代码很重要,因为它们可以映射到不同进程中的不同地址。
请注意,x86-64 上不需要等效调用,因为该架构具有 IP 相对寻址模式(即,它可以直接将内存位置寻址为当前指令位置的偏移量) 。
This call is used in position-independent code on x86. It loads the position of the code into the
%ebx
register, which allows global objects (which have a fixed offset from the code) to be accessed as an offset from that register.Position-independent code is code that can be loaded and executed, unmodified, at different addresses. It is important for code that will be linked into shared libraries, because these can be mapped at a different address in different processes.
Note that an equivalent call is not required on x86-64, because that architecture has IP-relative addressing modes (that is, it can directly address memory locations as an offset from the location of the current instruction).
通过示例添加更多信息:
假设在函数启动内对 gdb 进行 disass 后,您会发现如下内容:
然后在调用 __i686.get_pc_thunk.bx 后,寄存器 ebx 将由值 0x012c17a8< 填充/strong>,这是下一条指令的地址。
您可以将该函数读取为 get_pc(程序计数器)。
我发现这篇文章非常有助于更好地理解:
https://www.technovelty.org/linux/plt-and-got-the-key-to-code-sharing-and-dynamic-libraries.html
Adding more to the information by example:
Suppose after you do disass on gdb inside function startup, then you will find something like this:
Then after you have called __i686.get_pc_thunk.bx, register ebx will be populated by value 0x012c17a8, which is the address of next instruction.
You can read the function as get_pc(program counter).
I found this article very nice for better understanding:
https://www.technovelty.org/linux/plt-and-got-the-key-to-code-sharing-and-dynamic-libraries.html