x86-64 GNU 汇编
在调查崩溃时,我遇到了以下代码片段,并立即意识到 mov
指令实际上应该是 movq
以获得正确的 64 位寄存器操作。
#elif defined(__x86_64__)
unsigned long rbp;
__asm__ volatile ("mov %%rbp, %0" : "=r" (rbp));
sp = (void **) rbp;
#else
除此之外,我还发现文档声称 x86-64 的 rbp 寄存器是通用的,不包含当前帧的地址。我还发现文档声称 rbp 确实包含当前帧的地址。有人可以澄清一下吗?
While investigating a crash, I came across the following code snippet and immediately recognized that the mov
instruction should actually be movq
to get the correct 64-bit register operation.
#elif defined(__x86_64__)
unsigned long rbp;
__asm__ volatile ("mov %%rbp, %0" : "=r" (rbp));
sp = (void **) rbp;
#else
Further to this, I also found documentation that claims that the rbp
register for x86-64 is general purpose and does not contain the address of the current frame. I have also found documentation that claims that rbp
does contain the address of the current frame. Can someone clarify?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于问题的第一部分(
movq
而不是mov
),汇编器(在本例中)将识别出您的操作数是 64 位,并且会正确地使用movq
。mov
不是一条有效的指令,它是一种告诉汇编器“根据操作数使用正确的mov
变体”的方法。关于第二部分,它实际上是两者:它是一个通用寄存器,从某种意义上说,它可以保存任何值。它还用作堆栈帧基指针。 AMD64 应用程序编程手册的“2.4 堆栈操作”部分说:
Regarding the first part of your question (
movq
instead ofmov
), the assembler (as, in this case), will recognize that your operand is 64 bits, and will correctly usemovq
.mov
is not a valid instruction, it's a way to tell the assembler "use the rightmov
variant depending on the operands".Regarding the second part, it's actually both: it's a general purpose register, in the sense that it can hold any value. It is also used as a stack-frame base pointer. The '2.4 Stack operation' section of the AMD64 Application programming manual says: