<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [LTO] undefined reference to global variable that was used only in asm"
   href="https://bugs.llvm.org/show_bug.cgi?id=35197">35197</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[LTO] undefined reference to global variable that was used only in asm
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>ilia.taraban@intel.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This test fails at linkage with "undefined reference" with LTO:

================= nice.c ==============
int f[2];

int
main()
{
    __asm {
        mov     f[rax], rax
    }
    return 0;
}

=======================================

<span class="quote">>>> clang -v</span >
clang version 6.0.0 (trunk 317339)
Target: x86_64-unknown-linux-gnu
Thread model: posix
...

<span class="quote">>>> clang -c -O0 -fasm-blocks nice.c 
>>> clang -O1        nice.o</span >

But fails with -flto
<span class="quote">>>> clang -c -O0 -fasm-blocks nice.c -flto
>>> clang -O1 -flto  nice.o</span >
/tmp/lto-llvm-61977c.o:ld-temp.o:function main: error: undefined reference to
'f'
clang-6.0: error: linker command failed with exit code 1 (use -v to see
invocation)

<span class="quote">>>> clang -O1 -flto  nice.o  -Wl,-plugin-opt,-opt-bisect-limit=1</span >
BISECT: running pass (1) Dead Global Elimination on module (ld-temp.o)
...
BISECT: NOT running pass (46) X86 LEA Fixup on function (main)
/tmp/lto-llvm-7d6d61.o:ld-temp.o:function main: error: undefined reference to
'f'
clang-6.0: error: linker command failed with exit code 1 (use -v to see
invocation)


If we look at nice.o, we'll see that we still have variable 'f' before linkage
stage:

================= nice.o.ll ===========
@f = common global [2 x i32] zeroinitializer, align 4

; Function Attrs: noinline nounwind optnone uwtable
define i32 @main() #0 {
entry:
  %retval = alloca i32, align 4
  store i32 0, i32* %retval, align 4
  call void asm sideeffect inteldialect "mov f[rax], rax",
"~{dirflag},~{fpsr},~{flags}"() #1, !srcloc !2
  ret i32 0
}
=======================================</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>