Frederick Virchanza Gotham dixit:
>(1) Why does Func save and restore the RBX register if it never changes it?
Compilers tend to do that (frame pointer things).
>(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?
This is only one form of exception handling: it uses unwind information
from a separate part of the executable to know where to jump back to.
In normal operation, the call returns normally, then the jmp is
executed terminating the function. If an exception is thrown, the
handler walks back the call stack then changes the return address.
There’s also setjmp/longjmp-based exception handling (“sjlj” if you
ever compile GCC) which uses these libc functions instead of relying
on magic debugging information to unwind. That may be easier to
understand so I suggest having a look at that.
>(3) I don't know why those last four lines are there. They look like
>unreachable code to me.
As above, they’ll be reached by changing the return address. Your
compiler probably added some .cfi_* pseudo-ops for the assembler
there which would have the corresponding debugging info.
bye,
//mirabilos
--
15:41⎜<Lo-lan-do:#fusionforge> Somebody write a testsuite for helloworld :-)