[PATCH] LTO: add API to set strategy for -internalize

Nick Kledzik kledzik at apple.com
Fri Jan 10 16:31:34 PST 2014


On Jan 10, 2014, at 1:29 PM, Duncan P. N. Exon Smith <dexonsmith at apple.com> wrote:
> This patch adds API to LTOCodeGenerator to specify a strategy for the
> -internalize pass.
> 
> This is a new attempt at your change in r185882, which you reverted in
> r188029 due to problems with the gold linker.  This puts the onus on the
> linker to decide whether (and what) to internalize.
> 
> In particular, running internalize before outputting an object file may
> change a 'weak' symbol into an internal one, even though that symbol
> could be needed by an external object file --- e.g., with arclite.
> 
> This patch enables three strategies:
> 
> - LTO_INTERNALIZE_FULL: the default (and the old behaviour).
> - LTO_INTERNALIZE_NOWEAK: skip weak symbols in -internalize.
> - LTO_INTERNALIZE_NONE: skip -internalize entirely.
Duncan and I had a long discussion about this.  This style of API addition
is good from the linker’s perspective, because old linker’s still work and
new linker’s can run with old libLTO by not calling this new API.

We do need three states, but the middle one needs to be changed to:

LTO_INTERNALIZE_FULL      the default (and the old behaviour).
LTO_INTERNALIZE_HIDDEN    only internalize hidden symbols.
LTO_INTERNALIZE_NONE      skip -internalize entirely.

One of the key insights in our discussion is that the Internalize pass does
not make sense to run when doing “ld -r” to merge object files.  Internalize
assumes you are about to do code-gen and see all symbols involved.
With ld -r you are not about to do code-gen and the symbols that will exist
in the final link are unknowable.  

So, in -r mode, the linker will use this new API to stop internalize pass.  
But, ld -r has a twist.  By default ld -r wants visibility=hidden symbols to be 
internalized, unless -keep_private_externs is used. Thus, the linker will do:

    ld -r                                         => LTO_INTERNALIZE_HIDDEN
    ld -r  -keep_private_externs   => LTO_INTERNALIZE_NONE

-Nick 

> 
> They are exposed to the LTO C-API through a new method,
> lto_codegen_set_internalize_strategy().  It affects the behaviour of
> lto_codegen_write_merged_modules() and lto_codegen_compile*().
> 
> <rdar://problem/14334895>
> 
> <lto-internalize-noweak.patch>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140110/f7096c74/attachment.html>


More information about the llvm-commits mailing list