[llvm-bugs] [Bug 37672] New: Unsafe optimization with inline asm using static variable defined via attribute section.

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jun 4 00:45:05 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=37672

            Bug ID: 37672
           Summary: Unsafe optimization with inline asm using static
                    variable defined via attribute section.
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: zahira.ammarguellat at intel.com
                CC: llvm-bugs at lists.llvm.org

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180604/aa6966ef/attachment.html>


More information about the llvm-bugs mailing list