Re: [cxx-abi-dev] Key functions and templates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [cxx-abi-dev] Key functions and templates
- To: Mark Mitchell <mark@xxxxxxxxxxxxxxxx>
- Subject: Re: [cxx-abi-dev] Key functions and templates
- From: Lawrence Crowl <crowl@xxxxxxxxxx>
- Date: Mon, 22 Feb 2010 13:50:46 -0800
On 2/22/10, Mark Mitchell <mark@xxxxxxxxxxxxxxxx> wrote:
> 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?
I don't think so. The point of key functions is to prevent redundant
virtual table generation by making their generation a side effect
of something that is only done once. That property doesn't exist
with templates.
> > 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.
Plausible.
> > 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?
How about the following scenario?
A translation unit declares an "extern template" specialization
of G_key_defined<int>::f(). The compiler infers that the virtual
table need not be generated even though the translation unit
otherwise instantiates G_key_defined<int>. The specialization of
f() is not subsequently used, and so the vtable will fail to exist.
--
Lawrence Crowl