<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 - Unsafe optimization with inline asm using static variable defined via attribute section."
   href="https://bugs.llvm.org/show_bug.cgi?id=37672">37672</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Unsafe optimization with inline asm using static variable defined via attribute section.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>Frontend
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>zahira.ammarguellat@intel.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider this reproducer.

static const int foo __attribute__((section("bar"))) = 176;
int main(){
  int x;
  __asm__ ("movl      foo(%rip), %eax");
  __asm__ ("movl %%eax, %0 ": "=r" (x)::);
  return x;
}

bash-4.2$ clang -O0 t7.c
bash-4.2$ ./a.out
bash-4.2$ echo $?
176
bash-4.2$ clang -O2 t7.c
/tmp/t7-4769e9.o: In function `main':
t7.c:(.text+0x2): undefined reference to `foo'
clang-7: error: linker command failed with exit code 1 (use -v to see
invocation)
bash-4.2$
bash-4.2$ clang -c -O0 t7.c
bash-4.2$ objdump --syms t7.o | grep foo
0000000000000000 l     O bar    0000000000000004 foo
bash-4.2$ clang -c -O2 t7.c
bash-4.2$ objdump --syms t7.o | grep foo
0000000000000000         *UND*  0000000000000000 foo
bash-4.2$


Please notice that the same test case without the static specifier compiles and
runs with -O0 and -O2.</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>