[cxx-abi-dev] Problem with vcall offsets
Nathan Sidwell
nathan at codesourcery.com
Tue Jul 2 19:27:47 UTC 2002
Mark Mitchell wrote:
> Section 2.5.3 says:
>
> If virtual base A has a primary virtual base class P sharing its
> virtual table, P's vbase and vcall offsets come first in the
> primary virtual table, in the same order they would appear if P
> itself were the virtual base, and those from A that do not replicate
> those from P precede them.
Every time I look at this stuff it makes my head spin. I think you're
falling into the same trap I do, because you've reached the same
(erroneous) conclusion. The wording about this is not good,
unfortunately I've never found a more obvious simpler version.
>
> In other words, the vtable for A, when used as a virtual base is:
>
> A's vcall offset for A::a
> A's vbase offset to P
> P's vcall offset for P::p
> P's vbase offset to V
> V's vcall offset for V::v
> Offset-to-top
> Typeinfo
> Entry for V::v
> Entry for P::p
> Entry for A::a
not quite. you've mislabeled things. Think of the vcall offset as belonging
to the derived clss. After all you only need the vcall offset when there's
a virtual base involved.
I.e. A's vtable is
A's vbase offset to P
A's vcall offset for P::p
P's vbase offset to V
P's vcall offset for V::v
Offset to top
typeinfo
vptr points here: V::v
P::p
A::a
When A is a primary virtual (of say Z), the A-in-Z vtable is the same shape
as A's vtable. It is prepended by
Z's vbase offset to A (which will be zero 'cos A is primary)
Z's vcall offset to A::a (also zero 'cos of A's primality)
> This cannot possibly be right. If you want to be able to generate
> code to cast from an A* to a P*, then the index of A's vbase offset
> for P must be constant; it cannot depend on whether or not A itself is
> a virtual base in something else.
Huh? its always at aptr->vtable[-6]
> That implies that the vbase and
> vcall offsets cannot be interleaved; instead, the vbase offsets must
> always come nearest the address point.
Don't follow. When you have virtual polymorphic base first prepend a
vcall offset for all inherited virtual functions which have now
*just become* morally virtual, then prepend a vbase offset for the
virtually inherited base.
> I think that we need to always emit vcall offsets, even for bases that
> are not virtual.
No.
> Thoughts?
You are confused by a maze of twisty vcalls. I always find the output
of -fdump-class-hierarchy enlightening.
nathan
--
Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
'But that's a lie.' - 'Yes it is. What's your point?'
nathan at codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan at acm.org
More information about the cxx-abi-dev
mailing list