[cxx-abi-dev] There is no obligation to unique virtual tables

John McCall rjmccall at apple.com
Sun Feb 17 01:58:33 UTC 2013


On Feb 15, 2013, at 6:19 PM, Richard Smith <richardsmith at google.com> wrote:

> On Fri, Feb 15, 2013 at 5:38 PM, John McCall <rjmccall at apple.com> wrote:
> Richard Smith has pointed out to me that the ABI document currently states, right at the beginning of section 2.5:
> 
>   A virtual table (vtable) is a table of information used to dispatch virtual functions, to access virtual base class subobjects, and to access information for runtime type identification (RTTI). Each class that has virtual member functions or virtual bases has an associated set of virtual tables. There may be multiple virtual tables for a particular class, if it is used as a base class for other classes. However, the virtual table pointers within all the objects (instances) of a particular most-derived class point to the same set of virtual tables.
> 
> This last sentence could be interpreted as a strict requirement that all objects of a most-derived class use the same v-table, as opposed to potentially a private copy of that v-table.
> 
> While it is obviously good to avoid redundant copies of a v-table in memory, an unconditional requirement to do so seems excessive.  Uniquing a symbol with vague linkage across dynamic-library boundaries may require a significant amount of work, probably at load time but at best at the first use of the symbol (a sort of laziness which would carry its own disadvantages).  This work is required for the RTTI symbol name (_ZTS*) in order to make RTTI comparison work, but it is not otherwise mandatory for the RTTI object (_ZTI*) or v-tables (_ZTV*) or VTT (_ZTT*).
> 
> It is currently mandatory for the _ZTI, per 2.9.1:
> 
> "It is intended that two type_info pointers point to equivalent type descriptions if and only if the pointers are equal. An implementation must satisfy this constraint, e.g. by using symbol preemption, COMDAT sections, or other mechanisms."

I didn't really mean to open that debate.  The question of what exactly is merged about RTTI is very complicated, with widespread divergence from the plain rule in the ABI;  in particular, neither GCC nor clang guarantees uniquing of _ZTI's, and GCC stopped even uniquing _ZTS's by default as of GCC 4.5, using a new comparison scheme on all platforms (which, incidentally, I think would be worth documenting as an official alternative, if anyone from GCC would mind describing the rules they use).

My point is just that AFAIK *nobody* has ever relied upon v-tables or VTTs being uniqued, and I would like to clean up a bit of the ABI spec which seems to imply that they need to be.

John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sourcerytools.com/pipermail/cxx-abi-dev/attachments/20130216/fbc9505b/attachment.html>


More information about the cxx-abi-dev mailing list