<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 6, 2016 at 11:16 AM, Peter Collingbourne <span dir="ltr"><<a href="mailto:peter@pcc.me.uk" target="_blank">peter@pcc.me.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">On Wed, Apr 6, 2016 at 10:49 AM, Teresa Johnson <span dir="ltr"><<a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Wed, Apr 6, 2016 at 10:46 AM, Peter Collingbourne <span dir="ltr"><<a href="mailto:peter@pcc.me.uk" target="_blank">peter@pcc.me.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">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.</div></blockquote><div><br></div></span><div>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?</div></div></div></div></blockquote><div><br></div></span><div>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.</div><div><br></div><div>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.</div><div><br></div><div>For example, if myvar were renamed to myvar.6, the IR would look like this:</div><div><br></div><div>@myvar.6 = global i8 [...]</div><div><br></div><div>[...]</div><div><br></div><div>call asm("movzbl  myvar(%rip), ...", ..., "myvar")(..., i8* @myvar.6)</div><div><br></div><div>The backend would produce assembly that would look like this:</div><div><br></div><div>.rename myvar, myvar.6</div><div>movzbl     myvar(%%rip), ...<br></div><div>.norename myvar</div><div><br></div><div>The .rename and .norename directives would delimit the scope of the renaming.</div></div></div></div></blockquote><div><br></div><div>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.</div><div><br></div><div>I think for ThinLTO purposes I will limit importing to/from modules with inline assembly for now to avoid the issue.</div><div><br></div><div>Teresa</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Peter</div><div><div class="h5"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><font color="#888888"><div><br></div><div>Teresa</div></font></span><div><div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>Peter</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Wed, Apr 6, 2016 at 10:37 AM, Teresa Johnson 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></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div><div dir="ltr">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.<div><br></div><div>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.</div><div><br></div><div>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:</div><div><br></div><div><div><div>$ cat inlineasm1.c </div><div>static const unsigned char __attribute__((used)) __attribute__ ((aligned (1))) myvar = 1;</div><div><br></div><div>void foo(unsigned long int *v) {</div><div>  __asm__ volatile("movzbl     myvar(%%rip), %%eax\n\t"</div><div>                   "movq %%rax, %0\n\t"</div><div>                       : "=*m" (*v)</div><div>    :</div><div>    : "%eax"</div><div>    );</div><div>}</div><div><br></div><div>$ cat inlineasm2.c </div><div>static const unsigned char __attribute__((used)) __attribute__ ((aligned (1))) myvar = 2;</div><div><br></div><div>void bar(unsigned long int *v) {</div><div>  __asm__ volatile("movzbl     myvar(%%rip), %%eax\n\t"</div><div>                   "movq %%rax, %0\n\t"</div><div>                       : "=*m" (*v)</div><div>    :</div><div>    : "%eax"</div><div>    );</div><div>}</div><div><br></div><div>$ cat inlineasm.c </div><div>#include <stdio.h></div><div>extern void foo(unsigned long int *v);</div><div>extern void bar(unsigned long int *v);</div><div>int main() {</div><div>  unsigned long int f,b;</div><div>  foo(&f);</div><div>  bar(&b);</div><div>  printf("%lu %lu\n", f, b);</div><div>}</div></div><div><br></div><div><br></div><div>If compiled at -O2 (no LTO) this correctly prints out "1 2".</div><div><br></div><div>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).</div><div><br></div><div>Is this a known issue? Any ideas on how we could handle this? </div><div><br></div><div>Thanks,</div><div>Teresa</div><span><font color="#888888"><div><br></div>-- <br><div><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"> <a href="tel:408-460-2413" value="+14084602413" target="_blank">408-460-2413</a></td></tr></tbody></table></span></div>
</font></span></div></div>
<br></div></div>_______________________________________________<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" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><span><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr">-- <div>Peter</div></div></div>
</font></span></div>
</blockquote></div></div></div><div><div><br><br clear="all"><div><br></div>-- <br><div><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"> <a href="tel:408-460-2413" value="+14084602413" target="_blank">408-460-2413</a></td></tr></tbody></table></span></div>
</div></div></div></div>
</blockquote></div></div></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr">-- <div>Peter</div></div></div>
</font></span></div></div>
</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>