<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=koi8-r">
<style type="text/css" style="display:none"><!-- p { margin-top: 0px; margin-bottom: 0px; }--></style>
</head>
<body dir="ltr" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Thanks for making reproducer, Steven!<br>
</p>
<p><br>
</p>
<p>It turned out cache key is computed differently by newer API (LTO.cpp) and legacy API (ThinLTOCodeGenerator).<br>
</p>
<p>I was always wondering what piece of software uses legacy API and finally found this out - it is Mac OS X linker ld64.<br>
</p>
<p><br>
</p>
<p>On Linux lld and gold plugin use newer API, so the bug can't be reproduced.<br>
</p>
<div style="word-wrap:break-word; line-break:after-white-space">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>От:</b> stevenwu@apple.com <stevenwu@apple.com> от имени Steven Wu <stevenwu@apple.com><br>
<b>Отправлено:</b> 15 ноября 2018 г. 3:34<br>
<b>Кому:</b> Teresa Johnson<br>
<b>Копия:</b> Evgeny Leviant; Mehdi AMINI; reviews+D49362+public+6f0316d7b1456727@reviews.llvm.org; Xin Tong; Alex L; Daniel Grumberg; JF Bastien; Anton Korobeynikov; Bob Haarman; Easwaran Raman; Duncan Exon Smith; llvm-commits; George Rimar; Igor Kudrin; jun.l@samsung.com<br>
<b>Тема:</b> Re: [PATCH] D49362: [ThinLTO] Internalize read only globals</font>
<div> </div>
</div>
<div>
<div style="font-size:9pt; font-family:'Calibri',sans-serif">
<h3 style="background-color:#ffffff; font-size:10pt; border:1px dotted #003333; padding:.8em">
<span style="color:#ff6600">CAUTION:<strong> </strong></span>This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.</h3>
</div>
<div><br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On Nov 14, 2018, at 4:28 PM, Teresa Johnson <<a href="mailto:tejohnson@google.com" class="">tejohnson@google.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="" style="font-family:Helvetica; font-size:12px; font-style:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none">
<div dir="ltr" class=""><br class="">
<br class="">
<div class="gmail_quote">
<div dir="ltr" class="">On Wed, Nov 14, 2018 at 1:47 PM Steven Wu <<a href="mailto:stevenwu@apple.com" class="">stevenwu@apple.com</a>> wrote:<br class="">
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left-width:1px; border-left-style:solid; border-left-color:rgb(204,204,204); padding-left:1ex">
<div class="" style="">Here is a small reduced test case using the same main.c and foo.c from the review:
<div class="">cat main.c</div>
<div class="">
<div class=""></div>
<blockquote type="cite" class="">
<div class="">int foo();</div>
<div class="">int main() {</div>
<div class=""> <span class="Apple-converted-space"> </span>return foo();</div>
<div class="">}</div>
</blockquote>
<div class=""><br class="">
</div>
<div class="">
<div class="">cat foo.c</div>
<div class=""></div>
</div>
<blockquote type="cite" class="">
<div class="">
<div class="">#include <stdlib.h></div>
<div class="">static int gFoo = 1;</div>
<div class="">int foo() {</div>
<div class=""> <span class="Apple-converted-space"> </span>return gFoo;</div>
<div class="">}</div>
<div class="">void bar() {</div>
<div class=""> <span class="Apple-converted-space"> </span>gFoo = rand();</div>
<div class="">}</div>
</div>
</blockquote>
<div class="">
<div class=""><br class="">
</div>
<div class="">cat test1.c</div>
<div class="">
<div class="">
<div class=""></div>
</div>
<blockquote type="cite" class="">
<div class="">
<div class="">int foo();</div>
</div>
<div class="">int test() {</div>
<div class=""> <span class="Apple-converted-space"> </span>return foo();</div>
<div class="">}</div>
</blockquote>
<div class="">
<div class=""><br class="">
</div>
<div class="">cat test2.c</div>
<div class="">
<div class=""></div>
</div>
</div>
</div>
<blockquote type="cite" class="">
<div class="">
<div class="">
<div class="">
<div class="">int foo();</div>
<div class="">int bar();</div>
</div>
<div class="">int test() {</div>
<div class=""> <span class="Apple-converted-space"> </span>return foo() + bar();</div>
<div class="">}</div>
</div>
</div>
</blockquote>
<div class=""><br class="">
</div>
<div class="">To reproduce:</div>
<div class="">$ clang -O3 -flto=thin -c main.c test1.c test2.c foo.c</div>
<div class="">$ clang -O3 -flto=thin -Wl,-cache_path_lto,lto.cache main.o test2.o foo.o</div>
<div class="">$ clang -O3 -flto=thin -Wl,-cache_path_lto,lto.cache main.o test1.o foo.o</div>
<div class="">Undefined symbols for architecture x86_64:</div>
<div class="">
<div class=""> <span class="Apple-converted-space"> </span>"_gFoo.llvm.17695746433417383459", referenced from:</div>
<div class="">     <span class="Apple-converted-space"> </span>_main in lto.o</div>
</div>
</div>
</div>
</div>
</blockquote>
<div class=""><br class="">
</div>
<div class="">I can't reproduce this, although I am using gold (with  -Wl,-plugin-opt,cache-dir=lto.cache) since I don't have ld64. I notice that test() is dead, so with gold at least it is removed completely.</div>
<div class=""><br class="">
</div>
<div class="">Do you have any temp files you can share (i.e. IR before and after importing)?</div>
</div>
</div>
</div>
</div>
</blockquote>
<div><br class="">
</div>
<div>Attach all the intermediate file. I haven't had time to look in detail yet.</div>
<div><br class="">
</div>
<div></div>
</div>
</div>
</div>
</div>
</body>
</html>