RFC: Mangling Unnamed Global Values

Hi all,

Right now the Mangler::getValueName() method will produce something like "__unnamed_1_37" for a global value that doesn't have a name. This is wrong for Objective-C where CFStrings will get these labels, thus preventing the linker from coalescing them.

[/tmp]> nm -s __DATA __cfstring -m foo.o
00000000000244d0 (__DATA,__cfstring) non-external __unnamed_1_0
00000000000244b0 (__DATA,__cfstring) non-external __unnamed_1_1

I think that prepending the PrivateGlobalPrefix to these names would be the way to go. My question is whether getValueName() should do the prepending or should the individual back-end do it? I think that getValueName() should do it so that it's consistent, but then the prefix needs to be passed in (as the mangler doesn't know about the TargetAsmInfo object).

What do you think?


Can symbols with external linkage but no name be converted
to have internal linkage? Would that solve the problem?


The symbols I'm interested in already have internal linkage (as you
would expect). But because the mangler is in charge of assigning them
names, they never seem to be decorated with the 'L' in front. . . .


If you use SET_DECL_ASSEMBLER_NAME (something like that) you can specify the full name for this stuff, including the L. This is how other Objc metadata works.


Yup. see start_var_decl() in objc-act.c and its uses of set_user_assembler_name().

I'll check it out. Thanks!


It's a bit more complicated than this. The metadata for this CFString
is created in darwin_build_constant_cfstring() in darwin.c. It
intentionally constructs an anonymous global variable for the
constructor. If I try to call "set_user_assembler_name" on that
variable, it crashes with this:

t.m: In function '-[A bork:]':
t.m:11: internal compiler error: tree check: expected tree that
contains 'decl with visibility' structure, have 'const_decl' in
change_decl_assembler_name, at cgraph.c:897
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://developer.apple.com/bugreporter&gt; for instructions.