<div dir="ltr">Hi Taewook,<div><br></div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 28, 2016 at 4:38 PM, Taewook Oh via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><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 bgcolor="white" lang="EN-US">
<div class="gmail-m_4327983519105031734WordSection1">
<p class="gmail-MsoNormal"><span style="font-size:11pt">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).<u></u><u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt">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.
<u></u><u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt">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.
<u></u><u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt">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></p></div></div></blockquote><div><br></div><div>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.</div><div> </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 bgcolor="white" lang="EN-US"><div class="gmail-m_4327983519105031734WordSection1"><p class="gmail-MsoNormal"><span style="font-size:11pt"> <u></u><u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt">; Materializable<u></u><u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt">; Function Attrs: nounwind uwtable<u></u><u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt">define weak_odr void @foo(%1*) unnamed_addr #7 comdat($comdat1) align 2 personality i32 (...)* @__gxx_personality_v0 {}<u></u><u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt">(I renamed the function and comdat)<u></u><u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt">is materialized with GlobalValueMaterializer, (so the IRLinker::materialize function is called with ForAlias == false), and the materialized value is<u></u><u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt">; Function Attrs: nounwind uwtable<u></u><u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt">declare void @foo(%"type1"*) unnamed_addr #2 align 2<u></u><u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt">Then, later, the same value is materialized again with LocalValueMaterializer (so ForAlias == true for IRLinker::materialize), and the materialized value is<u></u><u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt">; Function Attrs: nounwind uwtable<u></u><u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt">define internal void @foo.1(%"type 0x7efb6ee89d80"*) unnamed_addr #2 comdat($comdat1) align 2 personality i32 (...)* @__gxx_personality_v0 !dbg !12345 {<u></u><u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt">  // function definition<u></u><u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt">}<u></u><u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt">(here, “type 0x7efb6ee89d80” is not “type1” )<u></u><u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt">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://llvm.org/bugs/show_bug.cgi?id=28760)" target="_blank">https://llvm.org/bugs/show_bug.cgi?id=28760)</a>.</span></p></div></div></blockquote><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>Thanks,</div><div>Teresa</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 bgcolor="white" lang="EN-US"><div class="gmail-m_4327983519105031734WordSection1"><p class="gmail-MsoNormal"><span style="font-size:11pt">
<u></u><u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt">Thanks,<u></u><u></u></span></p>
<p class="gmail-MsoNormal"><span style="font-size:11pt">Taewook<u></u><u></u></span></p>
</div>
</div>

<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><span style="font-family:times;font-size:medium"><table cellspacing="0" cellpadding="0"><tbody><tr style="color:rgb(85,85,85);font-family:sans-serif;font-size:small"><td nowrap style="border-top-style:solid;border-top-color:rgb(213,15,37);border-top-width:2px">Teresa Johnson |</td><td nowrap style="border-top-style:solid;border-top-color:rgb(51,105,232);border-top-width:2px"> Software Engineer |</td><td nowrap style="border-top-style:solid;border-top-color:rgb(0,153,57);border-top-width:2px"> <a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</a> |</td><td nowrap style="border-top-style:solid;border-top-color:rgb(238,178,17);border-top-width:2px"> 408-460-2413</td></tr></tbody></table></span></div>
</div></div>