vtable writeup

Jason Merrill jason at cygnus.com
Thu Sep 30 08:50:22 UTC 1999


Sorry this has taken so long.

The proposed vtable layout model is as follows.

At indices >= 0, a sequence of function pointers.
At index -1, a pointer to the RTTI information for the complete class.
At index -2, the adjustment from the object pointer we used to find 
  this vtable to the complete object.
At indices < -2, a sequence of offsets.  First, offsets from this object to
  various virtual bases, allocated outward in the same order as the vbase
  subobjects themselves.  Then, offsets used in virtual calls, allocated in
  order of the functions which use them.

Calling a virtual function involves adjusting 'this' to point to a vtable
containing the function we're interested in, extracting the function
pointer from the vtable, and calling it, just as in the traditional thunk
model.

If the object pointer used in the call refers to a non-virtual base of the
class where the final overrider of the function is defined, the callee
knows and performs the necessary adjustment, if any.  This is also
identical to the traditional thunk model, though the callee need not be
implemented using a thunk.

If the object pointer refers to a virtual base of the final overrider, the
callee finds the adjustment in the vtable for the most derived class of
which the subobject is a non-virtual base.  When a class A is used as a
virtual base, we add offset slots to the beginning of the A vtable for each
virtual function in the vtables from A's non-virtual bases.  In the vtable
example, A is used as a virtual base in B, so we allocate slots for each of
A's virtual functions.

I've also updated abi-layout.htm to reflect this proposal.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sourcerytools.com/pipermail/cxx-abi-dev/attachments/19990930/1b2d37cb/attachment.htm>


More information about the cxx-abi-dev mailing list