[llvm-commits] [patch][pr11866] Drop linkonce_odr symbols from the symbol table when safe

Rafael Espíndola rafael.espindola at gmail.com
Fri Jun 22 09:20:09 PDT 2012


On 21 June 2012 22:40, Nick Kledzik <kledzik at apple.com> wrote:
> Rafael,
>
> I think LTO_SYMBOL_IS_LINKONCE_ODR_UNUSED_ADDR may actually be the same as the existing LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN flag.  That flag is only set on definitions of which the front end did not see the address taken.  If the linker does not see the address taken either, then the linker can change the visibility to hidden in the final linked image.  It might just be that the linker_private_weak_def_auto linkage type was only wired up for Darwin.

Is it? It looks stronger. It is set for linker_private_weak_def_auto
symbols. The IR documentation says:

> Similar to "linker_private_weak", but it's known that the address of the object is not taken.

Which I assume means "not taken anywhere". Given that, the linker
plugin would be allowed to just tell the linker the symbol is hidden
and the linker will not try to put it in the symbol table. No need for
the new gold API.

>From the above, I think  LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN can
also be used to handle unnamed_addr functions and constants.  I have
attached a patch that implements this bit, but now that I think of it,
this could very well be just an IL optimization that marks as hidden
linkonce_odr functions and constants that are also unnamed_addr. I
think mach-o needs the special linkages that have to reach the linker
because of things like objc metadata.

What it cannot be used for are regular linkonce_odr functions. The
semantics for those are that they can be made hidden/dropped if they
don't have their address taken anywhere in the DSO, but we will have
to wait for the linker to tell us if that is the case. Gold is a bit
more conservative, it doesn't tell us if the address was taken, only
if the symbol was used for anything else other than putting it in the
symbol table, but that is probably good enough.

With the attached patch the combined IL for clang goes from 1870
linkonce_odr symbols to 1598. Let me know if you like this patch of if
you agree that it should be just an IL optimization. In any case we
can handle the linkonce_odr functions case in a new patch.

> -Nick

Cheers,
Rafael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.patch
Type: application/octet-stream
Size: 3443 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120622/fdef37f3/attachment.obj>


More information about the llvm-commits mailing list