Frederick Virchanza Gotham
2023-04-24 15:20:32 UTC
#include <cstdio> // puts
extern void LibFunc(void) noexcept(false); // likely to throw an exception
gets compiled to:
mov rdi, rax
mov edi, OFFSET FLAT:.LC0
mov rbx, rax
mov rdi, rbx
There's a few things I don't understand here:
(1) Why does Func save and restore the RBX register if it never changes it? I realise that RBX is callee-saved and so you must push it onto the stack before altering it, but I don't see anywhere where it's altered.
(2) If 'LibFunc' throws an exception, how does it know where to jump back to? In normal circumstances if the function returned normally, it would jump back to the 'jmp .L1' instruction, but instead it has to jump back to one instruction after that. How does it know what offset of the return address to jump back to?
(3) I don't know why those last four lines are there. They look like unreachable code to me.
Can anyone enlighten me please?