[cxx-abi-dev] What thunks are needed?

Jason Merrill jason_merrill at redhat.com
Wed Jun 6 14:16:58 UTC 2001


>>>>> "Nathan" == Nathan Sidwell <nathan at codesourcery.com> writes:

> Jason Merrill wrote:
>> 
>> Consider:
>> 
>> class A { virtual void f (); };
>> class B1 : virtual public A { virtual void f (); };
>> class B2 : virtual public A { virtual void f (); };
>> class C: public B1, public B2 { virtual void f (); };

>> So: For C::f, we need a virtual thunk for A, no thunk for B1, and a
>> non-virtual thunk for B2. 

> Disagree.

> C::f needs a virtual thunk for A, no thunk for B1 no thunk for B2.
> In C's vtable there will be a subvtable for B1 which contains a sub
> vtable for A. There will be a secondary vtable for B2, which will
> contain a sub vtable for the A base of B2. There is no A base inside
> the B2 base in an object, but B2's vtable will need space allocating
> as if there was one.

Yes.

> Also it has to be set up correctly, so that if we have a pointer to the
> B2 base in C, a call to f will correctly adjust. (As B2 also defines an
> f, we don't have to convert the pointer down to an A * before the virtual
> function call.)

Yes.  But B2 is not a virtual base, so according to the current ABI
converting from B2 to C should use a non-virtual thunk.

>> But it occurs to me that since the B2 vtable
>> already has a vcall slot for f, we can use the virtual thunk there, too,
>> so we only really need one thunk.

> agreed.

But this is a change from what the ABI currently says.

>> Thoughts?  The current g++ implementation doesn't generate the non-virtual
>> thunk, so this change would actually improve compatibility between a
> The current g++ implementation is wrong in this regard. I've
> just fixed some stuff concerning nearly-empty virtual primary base
> classes that g++ was getting wrong. Mark's looking at that patch
> at the moment, and, if he doesn't find anything amiss, it'll go in
> tomorrow.

Ack!  Please don't put it in; I've just overhauled this stuff, which is why
I'm thinking about it.  Didn't he mention to you that I was working on
this?  Sorry I didn't cc you on the heads-up I sent him.

Please send your patch to me, and I'll integrate any bits I missed.

> here is what C's vtable should look like (and does with my patch)

> Vtable for C
> C::_ZTV1C: 10 entries
> 0     0
> 4     0
> 8     0
> 12    &_ZTI1C
> 16    C::_ZTv0_n12_N1C1fEv
> 20    -4
> 24    -4		<- vcall adjust from B2 to C is -4
> 28    -4
> 32    &_ZTI1C
> 36    C::_ZTv0_n12_N1C1fEv <- virtual adjust

With my patch, it looks like

Vtable for C
C::_ZTV1C: 10 entries
0     0
4     0
8     0
12    &_ZTI1C
16    C::f              <- no thunk necessary
20    -4
24    -4		<- vcall adjust from B2 to C is -4
28    -4
32    &_ZTI1C
36    C::_ZTv0_n12_N1C1fEv <- virtual adjust

Jason




More information about the cxx-abi-dev mailing list