<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><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>