3 ms·
In addition to what others said, I'd simply point out that all 'ret' does on x86 is pop an address off the top of the stack and jump to it. It's more of a "help
by DSMan195276 2y ago
In addition to what others said, I'd simply point out that all 'ret' does on x86 is pop an address off the top of the stack and jump to it. It's more of a "helper" than a special instruction and it's use is never required as long as you ensure the stack will be kept correct (such as with a tail-call situation).
- dcrazy 2y ago`ret` also updates the branch predictor’s shadow stack. Failing to balance `call` and `ret` can seriously impact performance.
- dkersten 2y agoIf anyone else is looking for more information on this, like I was, this stack is called the “return stack buffer”.
- DSMan195276 2y agoRight, I didn't want to get into it but definitely using 'ret' "properly" has big performance benefits. My point was just that it won't prevent your code from running, it's not like x86 will trigger an exception if they don't match up.
- ack_complete 2y agoRET does more these days. If Intel CET is enabled then it also updates the hardware shadow stack, and the program will crash if RET is bypassed unless the SSP is adjusted. IIRC Windows x64 also has pertinent requirements on how the function epilog restores registers and returns since it will trace portions of the instruction stream during stack unwinding.