If a function was entered via a near call, can it do a far tail call without breaking return address prediction?

Viewed 109

Consider this code:

.globl _non_tail, _tail
.text

.code32
_non_tail:
    lcall $0x33, $_non_tail.heavensgate
    ret

.code64
_non_tail.heavensgate:
    # do stuff. there's 12 bytes on the stack before the first argument
    lret

.code32
_tail:
    pushl (%esp)
    movw %cs, 4(%esp)
    ljmp $0x33, $_tail.heavensgate

.code64
_tail.heavensgate:
    # do stuff. there's 8 bytes on the stack before the first argument
    lret

Will _tail cause the return stack buffer to mispredict future returns? On the one hand, it's pairing a near call with a far return, but on the other hand, it's still returning to the exact same place that it would have normally.

0 Answers
Related