<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br>On Jan 10, 2014, at 1:29 PM, Duncan P. N. Exon Smith <<a href="mailto:dexonsmith@apple.com">dexonsmith@apple.com</a>> wrote:<br><blockquote type="cite">This patch adds API to LTOCodeGenerator to specify a strategy for the<br>-internalize pass.<br><br>This is a new attempt at your change in r185882, which you reverted in<br>r188029 due to problems with the gold linker.  This puts the onus on the<br>linker to decide whether (and what) to internalize.<br><br>In particular, running internalize before outputting an object file may<br>change a 'weak' symbol into an internal one, even though that symbol<br>could be needed by an external object file --- e.g., with arclite.<br><br>This patch enables three strategies:<br><br>- LTO_INTERNALIZE_FULL: the default (and the old behaviour).<br>- LTO_INTERNALIZE_NOWEAK: skip weak symbols in -internalize.<br>- LTO_INTERNALIZE_NONE: skip -internalize entirely.<br></blockquote><div>Duncan and I had a long discussion about this.  This style of API addition</div><div>is good from the linker’s perspective, because old linker’s still work and</div><div>new linker’s can run with old libLTO by not calling this new API.</div><div><br></div><div>We do need three states, but the middle one needs to be changed to:</div><div><font face="Monaco" size="1"><br></font></div><div><div><font face="Monaco" size="1">LTO_INTERNALIZE_FULL      the default (and the old behaviour).<br>LTO_INTERNALIZE_HIDDEN    only internalize hidden symbols.<br>LTO_INTERNALIZE_NONE      skip -internalize entirely.<br></font></div><br></div><div>One of the key insights in our discussion is that the Internalize pass does</div><div>not make sense to run when doing “ld -r” to merge object files.  Internalize</div><div>assumes you are about to do code-gen and see all symbols involved.</div><div>With ld -r you are not about to do code-gen and the symbols that will exist</div><div>in the final link are unknowable.  </div><div><br></div><div>So, in -r mode, the linker will use this new API to stop internalize pass.  </div><div>But, ld -r has a twist.  By default ld -r wants visibility=hidden symbols to be </div><div>internalized, unless -keep_private_externs is used. Thus, the linker will do:</div><div><br></div><div>    ld -r                                         => LTO_INTERNALIZE_HIDDEN</div><div><div>    ld -r  -keep_private_externs   => LTO_INTERNALIZE_NONE</div></div><div><br></div><div>-Nick </div><br><blockquote type="cite"><br>They are exposed to the LTO C-API through a new method,<br>lto_codegen_set_internalize_strategy().  It affects the behaviour of<br>lto_codegen_write_merged_modules() and lto_codegen_compile*().<br><br><<a href="rdar://problem/14334895">rdar://problem/14334895</a>><br><br><span><lto-internalize-noweak.patch></span><br></blockquote><br></body></html>