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

Nick Kledzik kledzik at apple.com
Thu Jun 21 19:40:47 PDT 2012


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.

-Nick

On Jun 16, 2012, at 5:12 PM, Rafael EspĂ­ndola wrote:
> The attached patch fixes PR11866.
> 
> My original idea on how to fix it (see comment 3 in that bug) is a bit
> hard to implement. The problem is that the LTO infrastructure reports
> an undefined reference when it sees a declaration.  For example, a
> file with just
> 
> declare void @foo()
> 
> is going to show up as having an undefined reference. Simple cases
> like this should be simple to filter out, but we also have to handle
> declarations used only in available_externally "definitions" like the
> ones in pr13124. Doable, but I think I found an easier way.
> 
> Gold's plugin api was updated some time ago to let the plugins know
> that a symbol is not used from any ELF file, but gold would still put
> it in a symbol table if present. In this case the plugin is free to
> drop the symbol if it knows it doesn't need to go in a shared object's
> symbol table. That is what this patch does.
> 
> In detail:
> 
> * The LTO code is updated to record which linkonce_odr functions  and
> constants don't have their address taken (or have an unnamed_addr
> flag).
> * The plugin still reports linkonce_odr symbols to gold.
> * The plugin doesn't force LTO to keep symbols that gold tells us
> would be needed only for the symbol table and have been marked as
> noted above.
> 
> When linking clang with LTO (and -export-dynamic,  so it is
> effectively a DSO), the number of linkonce_odr symbols goes from 1907
> to 63. Of these 63
> 
> * 61 are typeinfo names, so we do need to keep them visible since
> their address is compared.
> * 2 are linkonce_odr globals, which we also have to keep visible to
> observe mutations.
> 
> CCing nleycky for opinions on the plugin changes and the linker guys
> to know if this is also a reasonable way to go for lld.
> 
> Cheers,
> Rafael
> <pr11866.patch>





More information about the llvm-commits mailing list