<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Title" content="">
<meta name="Keywords" content="">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:"맑은 고딕";}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.gmail-msonormal, li.gmail-msonormal, div.gmail-msonormal
        {mso-style-name:gmail-msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman";}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:Calibri;
        color:windowtext;}
span.msoIns
        {mso-style-type:export-only;
        mso-style-name:"";
        text-decoration:underline;
        color:teal;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body bgcolor="white" lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">Hello Teresa,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">Thank you for your reply. I’m trying to create a small repro but find it hard to nail down because originally it is a big build. This happens with gold linker.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">Taewook<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"><o:p> </o:p></span></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-family:Calibri;color:black">From: </span>
</b><span style="font-family:Calibri;color:black">Teresa Johnson <tejohnson@google.com><br>
<b>Date: </b>Thursday, July 28, 2016 at 5:08 PM<br>
<b>To: </b>Taewook Oh <twoh@fb.com><br>
<b>Cc: </b>via llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Subject: </b>Re: [llvm-dev] [ThinLTO] assert(GS != DefinedGlobals.end()) failed in FunctionImport.cpp<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal">Hi Taewook, <o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Thu, Jul 28, 2016 at 4:38 PM, Taewook Oh via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="gmail-msonormal"><span style="font-size:11.0pt">Encountered “assert(GS != DefinedGlobals.end())” failure while running ThinLTO. The assertion statement is in MustPreserveGV lambda function in llvm::thinLTOInternalizeModule (lib/Transforms/IPO/FunctionImport.cpp).</span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt">It seems that the assertion fails because it fails to recover the "original name" of the global value. ModuleSummaryIndex::getOriginalNameBeforePromote attempts to get the original name by stripping
 .llvm.{HASH}, but what I observe is that ".1" is still appended to the expected original name.
</span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt">Then where this extra ".1" comes from? It is appended when the global value is materialized. IRLinker::materialize function calls IRLinker::linkGlobalValueProto function, and inside that function if
 DGV is nullptr or ShouldLink is true then IRLinker::copyGlobalValueProto function is called to create a global variable in the destination module that corresponds to SGV. I found that newly created global variable has the extra ".1" added to the name of the
 SGV. </span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt">When this happens? I don't have a complete understanding but I observed that the same global value is materialized twice during the single invocation of IRLinker::run, once with GlobalValueMaterializer
 and once with LocalValueMaterializer. First, the global value</span><o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Yes, the IRLinker will append an integer if it encounters a naming conflict. Normally this would happen in full LTO, but I guess is happening here since we are linking twice due to the alias.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="gmail-msonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt">; Materializable</span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt">; Function Attrs: nounwind uwtable</span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt">define weak_odr void @foo(%1*) unnamed_addr #7 comdat($comdat1) align 2 personality i32 (...)* @__gxx_personality_v0 {}</span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt">(I renamed the function and comdat)</span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt">is materialized with GlobalValueMaterializer, (so the IRLinker::materialize function is called with ForAlias == false), and the materialized value is</span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt">; Function Attrs: nounwind uwtable</span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt">declare void @foo(%"type1"*) unnamed_addr #2 align 2</span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt">Then, later, the same value is materialized again with LocalValueMaterializer (so ForAlias == true for IRLinker::materialize), and the materialized value is</span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt">; Function Attrs: nounwind uwtable</span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt">define internal void @foo.1(%"type 0x7efb6ee89d80"*) unnamed_addr #2 comdat($comdat1) align 2 personality i32 (...)* @__gxx_personality_v0 !dbg !12345 {</span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt">  // function definition</span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt">}</span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt">(here, “type 0x7efb6ee89d80” is not “type1” )</span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt">So for me it seems that we need a mechanism to retrieve the original name of the global value even when it is renamed during the materialization. I submitted the bug report as well (<a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D28760-29&d=CwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=kOsLCgQzH7N8ptZ7diJD9g&m=XtlNH01OW0mwOi0no2wur-HO6RY5szj-dgWaIcCki-k&s=9pGLGnxeOI3J3lvx9-ayiZJUImAefSzcGGJN5xo9_Kc&e=" target="_blank">https://llvm.org/bugs/show_bug.cgi?id=28760)</a>.</span><o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Interestingly, we are already trying to handle a similar case in that lambda (see the comment about weak values linked in as a local copy due to an alias). However, we weren't anticipating the original weak value being linked in as well,
 which is causing the rename.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Do you have a small reproducer? Is this with gold? I need to think about the best way to handle this case. One way of course is to conservatively return true if we can't find it in the map, but I don't love that since we may miss other
 cases that need to be handled.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Teresa<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="gmail-msonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt">Thanks,</span><o:p></o:p></p>
<p class="gmail-msonormal"><span style="font-size:11.0pt">Taewook</span><o:p></o:p></p>
</div>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_llvm-2Ddev&d=CwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=kOsLCgQzH7N8ptZ7diJD9g&m=XtlNH01OW0mwOi0no2wur-HO6RY5szj-dgWaIcCki-k&s=eA2ODuBrwjiWfuW-_sPfCVr1H774iHS5j89ydb7KY2E&e=" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></p>
</blockquote>
</div>
<p class="MsoNormal"><br>
<br clear="all">
<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal">-- <o:p></o:p></p>
<div>
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td nowrap="" style="border:none;border-top:solid #D50F25 1.5pt;padding:0in 0in 0in 0in">
<p class="MsoNormal"><span style="font-family:Helvetica;color:#555555">Teresa Johnson |<o:p></o:p></span></p>
</td>
<td nowrap="" style="border:none;border-top:solid #3369E8 1.5pt;padding:0in 0in 0in 0in">
<p class="MsoNormal"><span style="font-family:Helvetica;color:#555555"> Software Engineer |<o:p></o:p></span></p>
</td>
<td nowrap="" style="border:none;border-top:solid #009939 1.5pt;padding:0in 0in 0in 0in">
<p class="MsoNormal"><span style="font-family:Helvetica;color:#555555"> <a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</a> |<o:p></o:p></span></p>
</td>
<td nowrap="" style="border:none;border-top:solid #EEB211 1.5pt;padding:0in 0in 0in 0in">
<p class="MsoNormal"><span style="font-family:Helvetica;color:#555555"> 408-460-2413<o:p></o:p></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>