[llvm-bugs] [Bug 26876] New: llc generates wrong code for x86 with -march=atom
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Mar 8 04:20:20 PST 2016
https://llvm.org/bugs/show_bug.cgi?id=26876
Bug ID: 26876
Summary: llc generates wrong code for x86 with -march=atom
Product: new-bugs
Version: 3.7
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: arne.hasselbring at googlemail.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Created attachment 16004
--> https://llvm.org/bugs/attachment.cgi?id=16004&action=edit
A minimal source code example that compiles to bad code
Compiling the attached file with the following command line gives a program
that crashes when returning from foo because of improper stack operations.
Compilation command line:
$ clang++ -std=c++14 -m32 -march=atom -o prog main.cpp
Executing prog results in
$ ./prog
Before foo()
Segmentation fault
This seems to happen if std::chrono::system_clock::now() is the last operation
in a function. It doesn't seem to matter whether the result is written into a
variable or not. Initially the problem occured when initializing the last
member variable of a class with now(). For this minimal example, I had to add
an __attribute__((noinline)) to foo() to get the error, but it is exactly the
same as in the original code.
I traced this down to an error in the generated assembly code. foo is compiled
to the following code:
8048780: 55 push %ebp
8048781: 89 e5 mov %esp,%ebp
8048783: 8d 64 24 e8 lea -0x18(%esp),%esp
8048787: 8d 45 f8 lea -0x8(%ebp),%eax
804878a: 89 04 24 mov %eax,(%esp)
804878d: e8 3e fe ff ff call 80485d0
<_ZNSt6chrono3_V212system_clock3nowEv at plt>
8048792: 8d 64 24 19 lea 0x19(%esp),%esp
8048796: 5d pop %ebp
8048797: c3 ret
You can see that in the beginning, 0x18 is subtracted from %esp and in the end,
0x19 is added. std::chrono::system_clock::now() adds another 4 bytes to %esp
(by returning with ret 0x04, I suspect this has to do with some ABI
callee-cleanup things), so in the end, the stack pointer is 5 bytes higher than
it should be. So it leads to a corrupted stack and the ret at 0x8048797 jumps
into some undefined place.
Compiling without -march=atom leads to a correct addition of 0x14 to %esp.
The clang/llvm is compiled by crosstool-ng, clang++ --version gives:
clang version 3.7.0 (https://github.com/llvm-mirror/clang.git
40b68b4c02b9d9e1e4138815747adf5589496240)
(https://github.com/llvm-mirror/llvm.git
17611b180b77406671cf0819a452dd128ce7481c)
--
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/20160308/97a562d8/attachment.html>
More information about the llvm-bugs
mailing list