This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: vtbl layout
- To: colin at field dot medicine dot adelaide dot edu dot au, egcs at cygnus dot com
- Subject: Re: vtbl layout
- From: mrs at wrs dot com (Mike Stump)
- Date: Mon, 4 Jan 1999 15:30:48 -0800
> Date: Sat, 02 Jan 1999 11:25:01 +1100
> From: Colin McCormack <colin@field.medicine.adelaide.edu.au>
> To: egcs@cygnus.com
> Now, as it happens (http://field.medicine.adelaide.edu.au/coldstore) I
> fall into that former category of people who implement object I/O
> facilities.
Just because you fall in that category doesn't automatically mean you
want to write to them, hopefully I am just stating the obvious.
> We currently use this->_vptr to copy the vtbl, but we have to guess
> about the size of the table, and we don't know anything much about
> its layout. I claim that this isn't necessarily a good thing.
You can read the debugging information, or you can add a size element
into the rtti information if you want. This will take a compiler mod
if you do the later. Though, I can't help but wonder what you want to
do to the vtable, when you know nothing about the vtable. Another
posibility is to add an extra element to the end (like 0/-1) to mark
the end of the vtable. finish_vtbls or set_rtti_entry might be the
right place to do this. Check out DECL_INITIAL and BINFO_VIRTUALS.
> So, is there anywhere apart from the code itself where this layout is
> documented?
See my privious posts in the last month about this. Roughly, for
thunks they are just an array of pointer to functions, fairly plain,
fairly simple. There are two slots in the front, one for rtti and one
for adjustment to the front of the complete object.
For normal vtable, one extra slot in the front, it has the two pieces
of data as above. Each entry is 8 bytes, 2 bytes of zeros, 2 bytes of
this offset and a pointer to the virtual function.
After that, I think it is stright forward to look at the assembler and
know which value adjusts the this pointer and which one is used for
the address of the virtual function.