vcall offset question wrt. vtables

Coleen Phillimore coleen at zko.dec.com
Mon Feb 28 19:35:21 UTC 2000


/*
I'm trying to understand where vcall offsets fit into the virtual
function table.  I have to confess lack of motivation up to this
point (since I think regular adjusting thunks are good enough for
real code, and wasn't planning on implementing them).  Since we've
opened the issue and are proposing a spec change, I thought I'd see
if I could understand them enough to implement zero sized slots for
them.

It seems in our vtable layout section, that 2 things grow upward if a
vtable is shared between base classes and that these things change the
fundamental premise that a vtable has the same entries on either side
of the vptr whether it is most derived or a base class subobject, in
the latter case, some entries may be added.

Consider this example:
*/

struct V {
        virtual void f() {}
        virtual void g() {}
};

struct V2 : virtual V {
        virtual void h() {}
};

struct V3 : virtual V2 {
        int v3; // prevent sharing for D.
        virtual void i() {}
};

struct D : virtual V3
{
        virtual void f() {}
        virtual void g() {}
        virtual void h() {}
        virtual void i() {}
};

main() {
  // Make example generate something
  D *d = new D;
}

/*
D's vtable for V3 in D would be shared by V2 and V, since when the
vtable is shared, we append functions on the end and base offsets onto
the beginning, would a V3 vtable in D look like this:

        (start with V)

        vcall offset f
        vcall offset g
        offset to top
        D::typeinfo
        &f (or some way to get there, thunk, gp pair, I don't care)
        &g

        (add on V2's shared vtable)

        vbase offset for V
        vcall offset for h
        vcall offset for f
        vcall offset for g
        offset to top
        D::typeinfo
        &f
        &g
        &h

        (add on V3's shared vtable)

        vbase offset for V2
        ??? vcall offset to i
        vbase offset for V
        vcall offset for h        vcall offset for g
        vcall offset for f
        offset to top
        D::typeinfo
        &f
        &g
        &h
        &i

Does this mean V3's vtable does not have the same format as if it
weren't virtual derived?  If V3 was nonvirtually derived, wouldn't it's
vtable look like this:

        (V3's vtable most derived)

        vbase ofset for V2
        vbase offset for V
        vcall offset for h
        vcall offset for g
        vcall offset for f
        offset to top
        D::typeinfo
        &f
        &g
        &h
        &i
*/

-- 
-----------------------------------------------------------------------
Coleen Phillimore                  | mailto:coleen at zko.dec.com
Compaq Computer Corp.   Nashua, NH | COMPAQ C++ Compiler Development
-----------------------------------------------------------------------




More information about the cxx-abi-dev mailing list