[cfe-dev] Mangling & linkage of unnamed but instantiated nested classes
David Blaikie
dblaikie at gmail.com
Wed Oct 31 14:15:46 PDT 2012
On Wed, Oct 31, 2012 at 1:53 PM, John McCall <rjmccall at apple.com> wrote:
> On Oct 31, 2012, at 12:37 PM, David Blaikie wrote:
>> GCC 4.7 mangles them as:
>>
>> _Z1fIN1SUt_EEiT_
>> _Z1fIN1SUt0_EEiT_
>> _Z1fIN1TUt_EEiT_
>> _Z1fIN1TUt0_EEiT_
>>
>> I don't think we have any class-specific unnamed nested type counter
>> that would implement that Ut_, Ut0_, ... mangling scheme, though I can
>> imagine where one might be added (I'm not very familiar with IRGen
>> though, so I'll certainly be happy to have any pointers about how that
>> could/should be implemented).
>
> Probably we would want to record and remember this in the AST.
>
> This schema is indeed the one blessed by the ABI.
> <unnamed-type-name> ::= Ut [ <nonnegative number> ] _
> But as the ABI also notes:
> The mangling of such unnamed types defined in namespace scope is generally unspecified because they do not have to match across translation units. An implementation must only ensure that naming collisions are avoided.
Hmm, that sounds you're saying we're getting this mangling wrong for
namespace scope cases of similar constructs - but that in /that/ case
we don't have to worry about numbering. I assume the implication is
that we do have to worry about numbering in the external-linkage class
scope case I'm talking about?
> The interesting question is what linkage GCC actually gives these symbols.
Right, that's part of the puzzle. Not knowing much about how linkage
is represented in assembly I've just compared this fairly
mechanically.
Clang ToT emits something like this:
.type _Z1fIN1S3$_0EEiT_, at function
Clang with my linkage change (that changes the linkage of the nested
type from "no linkage" to (the linkage of the outer class)
"linkonce_odr") emits something like this:
.section
".text._Z1fIN1S3$_0EEiT_","axG", at progbits,_Z1fIN1S3$_0EEiT_,comdat
.weak _Z1fIN1S3$_0EEiT_
.align 16, 0x90
.type _Z1fIN1S3$_0EEiT_, at function
& GCC emits something similar, sans the alignment for whatever that's worth:
.section .text._Z1fIN1SUt_EEiT_,"axG", at progbits,_Z1fIN1SUt_EEiT_,comdat
.weak _Z1fIN1SUt_EEiT_
.type _Z1fIN1SUt_EEiT_, @function
So I'll assume GCC is emitting these with linkonce_odr. (sorry, I'm
not up on the actual ABI terminology for these different linkage
classes, so I'm using the LLVM one)
More information about the cfe-dev
mailing list