[cxx-abi-dev] Key functions and templates

Mark Mitchell mark at codesourcery.com
Mon Feb 22 19:41:51 UTC 2010


Alasdair Grant wrote:

> are G_key_defined<int>::f() and G_key_nodef<int>::f() key functions?
> 
> By the letter of the ABI they are, since each of them is the first
> non-inline non-pure virtual function of its class.

Yes, this has bothered me for a while.  They are key functions, but is
this useful?

> But surely the spirit of the ABI is to use the key function as a
> 'key' to identify a unique translation unit - but these functions
> may be multiply defined.  So if the vtables for G_key_defined<int>
> and G_key_nodef<int> are defined at all, they must be defined with
> vague linkage.

Yes, my interpretation is that the compiler must define the vtable every
time it provides a definition of the key function, and that those
vtables must have vague linkage.

> Implementations (at least of the ARM variant of the ABI) seem to
> differ about whether the code above should define the vtable for
> G_key_nodef<int>.  GCC 4.4 for ARM does define the vtable - which
> suggests it is not treating G_key_nodef<int>::f() as a key function
> (if it did, it could rely on some other unit to be defining f(),
> and hence the vtable).

Given that there is vague linkage involved, how does this matter?  It
sounds to me like GCC is being wasteful, in that it's defining a vtable
not needed in this object file, and guaranteed to be present anyhow, but
as vague linkage will collapse the definitions, it sounds like this is
"just" a waste of space in object files, not in final executables.

Even if -- as on Symbian, where I suspect this question arises :-) --
the waste makes it into a DSO, how is that an ABI conformance problem?

-- 
Mark Mitchell
CodeSourcery
mark at codesourcery.com
(650) 331-3385 x713



More information about the cxx-abi-dev mailing list