[(questionable but useful) patch] Let codegen write the filename for translation unit initializer functions

Nico Weber thakis at chromium.org
Tue May 6 12:26:16 PDT 2014


On Mon, May 5, 2014 at 11:13 PM, John McCall <rjmccall at apple.com> wrote:
> On May 5, 2014, at 10:11 PM, Nico Weber <thakis at chromium.org> wrote:
>> Here's a patch which replaces everything not in [a-zA-Z0-9._] with _.
>> It also adds a "sub_" to the symbol, because a) that's what gcc does
>> (with -fPIC) b) that way, constructors with priority are
>> lexicographically in front of constructors without priority.
>>
>> John, do you think this is ok? This patch adds a filename to global
>> constructor symbols without priority, i.e. instead of always being
>> called _GLOBAL__I_a they're now called _GLOBAL__sub_I_my_file.cc. I'm
>> asking because there are tests for _destructors_ for -fapple-kext, so
>> maybe kexts care about these symbol names in some way.
>
> I don’t believe the symbol name is relevant for kexts, but if it is, that’ll
> be something we’ve learned.
>
> You’ll need to look at binutils (I guess?) to find the exact schema,
> but if it’s specific to looking around the “_I_” symbol, you may be able
> to avoid potential confusion with an init_priority just by adding
> an extra underscore or something.
>
> Also, you should really find out what the “sub" means before blindly
> changing to it.  If it’s being emitted only under -fPIC, it might mean
> something like the functions being relatively addressed.  If it’s all
> handled magically by ld, then great, but you need to find out.

As far as I can tell, ld doesn't care about it. grepping for "GLOBAL"
in binutils/gold/ only finds references to _GLOBAL_OFFSET_TABLE_.
binutils/ld/ does look at these symbol names in binutils/ld/ldctor.c ,
but only for symbols with a priority number – the patch doesn't change
the names of symbols with priority. Maybe the _sub is so that ld
doesn't think your constructor has a priority just because your source
file is called 655535.c.

gcc/ipa.c in the gcc repo says something along the lines of "produce a
name not recognizable by collect2" above a line that adds "sub_" to
the symbol name (it's the only line I could find that adds "sub") –
since clang doesn't use collect2, gcc's reason for adding "sub_"
doesn't apply for clang.

So it sounds like this is good to go.




More information about the cfe-commits mailing list