[cxx-abi-dev] Emission of vtables with a later-declared inline key function

John McCall rjmccall at apple.com
Mon Nov 5 19:46:32 UTC 2012


On Nov 5, 2012, at 9:07 AM, Sean Hunt wrote:
> Section 5.2.3 says "Note that if the key function is not declared
> inline in the class definition, but its definition later is always
> declared inline, it will be emitted in every object containing the
> definition."
> 
> I submit that this should be changed, so that if the key function is
> later declared inline, the vtable is emitted only if used in that TU.
> If the key function is inline, it must be defined in every TU in which
> it is odr-used, and since it is necessarily virtual and non-pure, it
> is odr-used in every TU containing a definition of the class. Hence
> any TU which may see a definition of the class also necessarily
> contains a definition of the key function, so we are no better off by
> selecting this key function than we would be if the function were
> declared inline in the class declaration.

This is all true, and I think your rule sounds fine.  I don't see any
binary-compatibility issues with it, either, since files compiled under
the old rule are always self-sufficient for this.

Note that your proposed rule is not the optimal way of taking
advantage of this language rule;  the optimal change is to ignore
functions with inline definitions for the purposes of choosing the
key function, and that's actually what ARM's modified ABI does.
I'm not sure whether any compilers actually implement this rule,
but it's there.  However, unlike your proposal, that rule is not
binary-compatible on platforms (like Darwin) that don't link strong
symbols with weak ones.

John.


More information about the cxx-abi-dev mailing list