Closed erique closed 9 months ago
When a class method is called via vtable, and -mregparm is used, the callsite passes this in a0, while the subroutine assumes this being passed on the stack.
-mregparm
this
CEX: http://franke.ms/cex/z/xTj5Yr
Subroutine TheClass::Reset() is called like
TheClass::Reset()
void* r = static_cast<TheClass*>(c)->Reset(); // 'this' passed via a0
which translates to
move.l (a2),a0 move.l (a0),a1 move.l d0,a0 jsr (a1)
While TheClass::Reset() itself will try to use this from the stack:
__ZN8TheClass5ResetEv: move.l (4,sp),d0 move.l d0,a0 clr.b (4,a0) rts
( This example works fine in x86 GCC : https://godbolt.org/z/Exncnjqh4 )
confirmed: http://franke.ms/cex/z/5v88oo
confirmed working - thanks!
When a class method is called via vtable, and
-mregparm
is used, the callsite passesthis
in a0, while the subroutine assumesthis
being passed on the stack.CEX: http://franke.ms/cex/z/xTj5Yr
Subroutine
TheClass::Reset()
is called likewhich translates to
While
TheClass::Reset()
itself will try to usethis
from the stack:( This example works fine in x86 GCC : https://godbolt.org/z/Exncnjqh4 )