patch for broken thunk on sparc
Fri Apr 7 10:55:00 GMT 2006
> on sparc the thunk (support for C++ multiple inheritance)
> is created incorrectly if flag_pic or -mcmodel=*medany -m64 are present.
> The problem is in code (for -m32):
> sub %sp, 8, %sp
> st %o7, [%sp]
> st %l7, [%sp+4]
> which incorrectly uses window save space.
> If OS needs to save window after that sequence the restored registers
> will contain some junk.
Thanks for catching that! This part of sparc_output_mi_thunk really is
over-engineered and I should probably have refrained from writing it in the
first place. But let's make it correct now that it is there.
> For some reason -O and above optimize that thunk sequence away, so users
> at least have sort of workaround.
Because flag_delayed_branch is true. The whole stuff is aimed to emit a thunk
(i.e. essentially a sibling call) without using delay slots...
> Would be nice to patch all 4.x branches.
Indeed, I'll install the fix everywhere.
> Here is the proposed patch:
> * config/sparc/sparc.c (emit_and_preserve): Use
> correct slot offset to preserve registers
I think you'll be clobbering the previous frame. We probably need to build a
dummy frame of SPARC_STACK_ALIGN (FIRST_PARM_OFFSET(0) + 2*UNITS_PER_WORD)
bytes. And I also think that the offset can simply be STACK_POINTER_OFFSET.
More information about the Gcc-patches