Is the 64-bit x86 asm sequence:
pop r11
jmp r11
... equivalent to near ret
, except that it clobbers r11
?
Is the 64-bit x86 asm sequence:
pop r11
jmp r11
... equivalent to near ret
, except that it clobbers r11
?
Generally, the near return C3
is functionally equivalent to pop reg
followed by a jump of the form FF /4 reg
(jump near absolute indirect). They both pop a 64-bit value of the top of the stack into RIP
. They also both may raise the same exceptions in the same situation in 64-bit mode. In particular, when the load from stack is to a non-canonical address, #SS(0)
occurs. Also when the new RIP
value is to a non-canonical address, #GP(0)
occurs. Moreover, #PF
and #AC(0)
may be raised on any memory access. So if there is a possibility that one of these exceptions may occur and if the code handling the exception may behave differently depending on the instruction sequence used, then they would actually not be functionally equivalent, precisely speaking. I assume that there is some free GPR, such as r11
. Otherwise, if freeing a register is necessary by spilling one to memory, then such process may have an impact on the architectural state that would not have occurred by simply using C3
.