[cxx-abi-dev] Vtable layout question

Mark Mitchell mark at codesourcery.com
Fri Jul 25 02:07:05 UTC 2003


> I was wondering if someone who understands the C++ ABI better then I do
> could answer a question for me.  Specifically in section 2.5.2 it says:
>
> | Following the primary virtual table of a derived class are secondary
> | virtual tables for each of its proper base classes, except any primary
> | base(s) with which it shares its primary virtual table.  These are
> | copies of the virtual tables for the respective base classes (copies in
> | the sense that they have the same layout, though the fields may have
> | different values).  We call the collection consisting of a primary
> | virtual table along with all of its secondary virtual tables a virtual
> | table group.  The order in which they occur is the same as the order in
> | which the base class subobjects are considered for allocation in the
> | derived object:
>
> My question is why does the location and order of the secondary vtables
> matter.  I *think* the only way to get to one of these secondary vtables
> is through the VTT, in which case all that really matters is that the
> pointers in the VTT point to the correct vtables and the actual ordering
> and location of those vtables is immaterial.  Is that correct or am I
> missing an important aspect of the ABI?

Compilers take advantage of the known relative positions of these vtables.
For example, a VTT initializer will compute the entries to put in the VTT by
starting with the first entry in the group and then advancing a known number
of bytes to reach the other entries in the group.  (That is the only
portable way to initialize the VTT because secondary vtables do not have
well-specified names.)

-- Mark




More information about the cxx-abi-dev mailing list