<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:x="urn:schemas-microsoft-com:office:excel" 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=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:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 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",serif;}
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;}
span.hoenzb
{mso-style-name:hoenzb;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>I still wonder if this would be an issue in _<i>standard</i>_ (not thin) LTO? <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>This test seems to be OK on my (slightly modified) standard LTO flow, but I do wonder for a more general case.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>Sergei<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:10.5pt;font-family:Consolas;color:#1F497D'>---<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.5pt;font-family:"Calibri",sans-serif;color:#1F497D'>Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation</span><span style='font-size:10.5pt;font-family:Consolas;color:#1F497D'><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>From:</span></b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'> llvm-dev [mailto:llvm-dev-bounces@lists.llvm.org] <b>On Behalf Of </b>Peter Collingbourne via llvm-dev<br><b>Sent:</b> Wednesday, April 06, 2016 3:11 PM<br><b>To:</b> Teresa Johnson <tejohnson@google.com><br><b>Cc:</b> llvm-dev <llvm-dev@lists.llvm.org><br><b>Subject:</b> Re: [llvm-dev] LTO renaming of constants with inline assembly<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>On Wed, Apr 6, 2016 at 12:52 PM, Teresa Johnson <<a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</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><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>On Wed, Apr 6, 2016 at 11:16 AM, Peter Collingbourne <<a href="mailto:peter@pcc.me.uk" target="_blank">peter@pcc.me.uk</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><div><p class=MsoNormal>On Wed, Apr 6, 2016 at 10:49 AM, Teresa Johnson <<a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</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><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>On Wed, Apr 6, 2016 at 10:46 AM, Peter Collingbourne <<a href="mailto:peter@pcc.me.uk" target="_blank">peter@pcc.me.uk</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><p class=MsoNormal>I suspect that the right way to do promotion/renaming of this sort is to rename at the MC layer just before writing the symbol table to the object file.<o:p></o:p></p></div></blockquote><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>I think that is too late - how would the symbols be distinguished in the LTO case below after the IR is linked but before we renamed the duplicate?<o:p></o:p></p></div></div></div></div></blockquote><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Sorry, wasn't fully awake. I think we could do something along the lines of the symbol renaming idea, but with directives that limit their scope to inline asm blocks.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Specifically, we could teach the frontend to produce a mapping from symbol names to globalvalues, for any internal names with the used attribute, and attach that mapping to inline asm blocks.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>For example, if myvar were renamed to myvar.6, the IR would look like this:<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>@myvar.6 = global i8 [...]<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><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>call asm("movzbl myvar(%rip), ...", ..., "myvar")(..., i8* @myvar.6)<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>The backend would produce assembly that would look like this:<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>.rename myvar, myvar.6<o:p></o:p></p></div><div><p class=MsoNormal>movzbl myvar(%%rip), ...<o:p></o:p></p></div><div><p class=MsoNormal>.norename myvar<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>The .rename and .norename directives would delimit the scope of the renaming.<o:p></o:p></p></div></div></div></div></blockquote><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>That's an interesting idea, thanks. Are .rename and .norename standard directives? I did some web searches but couldn't find anything concrete on them (I did find a .rename in some IBM Power documentation, but it seemed to apply to string constants.<o:p></o:p></p></div></div></div></div></blockquote><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>These would be new directives that we'd need to implement. Perhaps if they're already being used elsewhere we can come up with a sufficiently unique name.<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><div><div><p class=MsoNormal>I think for ThinLTO purposes I will limit importing to/from modules with inline assembly for now to avoid the issue.<o:p></o:p></p></div></div></div></div></blockquote><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Sounds reasonable.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Peter<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><div><div><p class=MsoNormal><span style='color:#888888'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='color:#888888'>Teresa<o:p></o:p></span></p></div><div><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><div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Peter<o:p></o:p></p></div><div><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><div><div><p class=MsoNormal><span style='color:#888888'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='color:#888888'>Teresa<o:p></o:p></span></p></div><div><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=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Peter<o:p></o:p></p></div></div><div><p class=MsoNormal><o:p> </o:p></p><div><div><div><p class=MsoNormal>On Wed, Apr 6, 2016 at 10:37 AM, Teresa Johnson 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></div></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><div><p class=MsoNormal>I encountered an issue with ThinLTO handling of inline assembly, where the inline assembly referenced a constant that was a local variable. The local var was renamed because it was promoted in ThinLTO mode, but the inline assembly copy was not renamed and we ended up with an undef at link time.<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>It looks like this is a general problem with inline assembly and LTO. Wondering if it is a known issue. E.g. if I link in LTO mode two files that have inline assembly referencing local constants with the same name, the LTO linking will rename the second. However, the renaming doesn't propagate to inline assembly, resulting in the wrong output.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>For example, let's say we have two modules with inline assembly that writes a local constant var named "myvar" into the memory pointed to by its parameter "v", and a simple main that calls each function:<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><div><div><p class=MsoNormal>$ cat inlineasm1.c <o:p></o:p></p></div><div><p class=MsoNormal>static const unsigned char __attribute__((used)) __attribute__ ((aligned (1))) myvar = 1;<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>void foo(unsigned long int *v) {<o:p></o:p></p></div><div><p class=MsoNormal> __asm__ volatile("movzbl myvar(%%rip), %%eax\n\t"<o:p></o:p></p></div><div><p class=MsoNormal> "movq %%rax, %0\n\t"<o:p></o:p></p></div><div><p class=MsoNormal> : "=*m" (*v)<o:p></o:p></p></div><div><p class=MsoNormal> :<o:p></o:p></p></div><div><p class=MsoNormal> : "%eax"<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><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>$ cat inlineasm2.c <o:p></o:p></p></div><div><p class=MsoNormal>static const unsigned char __attribute__((used)) __attribute__ ((aligned (1))) myvar = 2;<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>void bar(unsigned long int *v) {<o:p></o:p></p></div><div><p class=MsoNormal> __asm__ volatile("movzbl myvar(%%rip), %%eax\n\t"<o:p></o:p></p></div><div><p class=MsoNormal> "movq %%rax, %0\n\t"<o:p></o:p></p></div><div><p class=MsoNormal> : "=*m" (*v)<o:p></o:p></p></div><div><p class=MsoNormal> :<o:p></o:p></p></div><div><p class=MsoNormal> : "%eax"<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><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>$ cat inlineasm.c <o:p></o:p></p></div><div><p class=MsoNormal>#include <stdio.h><o:p></o:p></p></div><div><p class=MsoNormal>extern void foo(unsigned long int *v);<o:p></o:p></p></div><div><p class=MsoNormal>extern void bar(unsigned long int *v);<o:p></o:p></p></div><div><p class=MsoNormal>int main() {<o:p></o:p></p></div><div><p class=MsoNormal> unsigned long int f,b;<o:p></o:p></p></div><div><p class=MsoNormal> foo(&f);<o:p></o:p></p></div><div><p class=MsoNormal> bar(&b);<o:p></o:p></p></div><div><p class=MsoNormal> printf("%lu %lu\n", f, b);<o:p></o:p></p></div><div><p class=MsoNormal>}<o:p></o:p></p></div></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>If compiled at -O2 (no LTO) this correctly prints out "1 2".<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>However, when linked with LTO, the second copy of local "myvar" is renamed to "myvar.6". But the inline assembly which is still hidden within a call that hasn't been lowered, still references "myvar" in that second linked copy in bar(). The output is thus incorrect: "1 1" (or "2 2" if the bar() copy was linked first).<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Is this a known issue? Any ideas on how we could handle this? <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><div><p class=MsoNormal><span style='color:#888888'><o:p> </o:p></span></p></div><p class=MsoNormal><span style='color:#888888'>-- <o:p></o:p></span></p><div><table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0><tr><td nowrap style='border:none;border-top:solid #D50F25 1.5pt;padding:0in 0in 0in 0in'><p class=MsoNormal><span style='font-family:"Arial",sans-serif;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:"Arial",sans-serif;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:"Arial",sans-serif;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:"Arial",sans-serif;color:#555555'> <a href="tel:408-460-2413" target="_blank">408-460-2413</a><o:p></o:p></span></p></td></tr></table></div></div></div><p class=MsoNormal><o:p> </o:p></p></div></div><p class=MsoNormal style='margin-bottom:12.0pt'>_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></p></blockquote></div><p class=MsoNormal><span style='color:#888888'><br><br clear=all><o:p></o:p></span></p><div><p class=MsoNormal><span style='color:#888888'><o:p> </o:p></span></p></div><p class=MsoNormal><span style='color:#888888'>-- <o:p></o:p></span></p><div><div><p class=MsoNormal><span style='color:#888888'>-- <o:p></o:p></span></p><div><p class=MsoNormal><span style='color:#888888'>Peter<o:p></o:p></span></p></div></div></div></div></blockquote></div></div></div><div><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><tr><td nowrap style='border:none;border-top:solid #D50F25 1.5pt;padding:0in 0in 0in 0in'><p class=MsoNormal><span style='font-family:"Arial",sans-serif;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:"Arial",sans-serif;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:"Arial",sans-serif;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:"Arial",sans-serif;color:#555555'> <a href="tel:408-460-2413" target="_blank">408-460-2413</a><o:p></o:p></span></p></td></tr></table></div></div></div></div></div></blockquote></div></div></div><p class=MsoNormal><span style='color:#888888'><br><br clear=all><o:p></o:p></span></p><div><p class=MsoNormal><span style='color:#888888'><o:p> </o:p></span></p></div><p class=MsoNormal><span style='color:#888888'>-- <o:p></o:p></span></p><div><div><p class=MsoNormal><span style='color:#888888'>-- <o:p></o:p></span></p><div><p class=MsoNormal><span style='color:#888888'>Peter<o:p></o:p></span></p></div></div></div></div></div></blockquote></div></div></div><div><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><tr><td nowrap style='border:none;border-top:solid #D50F25 1.5pt;padding:0in 0in 0in 0in'><p class=MsoNormal><span style='font-family:"Arial",sans-serif;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:"Arial",sans-serif;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:"Arial",sans-serif;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:"Arial",sans-serif;color:#555555'> <a href="tel:408-460-2413" target="_blank">408-460-2413</a><o:p></o:p></span></p></td></tr></table></div></div></div></div></div></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><div><p class=MsoNormal>-- <o:p></o:p></p><div><p class=MsoNormal>Peter<o:p></o:p></p></div></div></div></div></div></div></div></body></html>