[llvm-bugs] [Bug 26389] New: [x86-64] clang generate wrong instruction for cygwin
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Jan 29 20:36:34 PST 2016
https://llvm.org/bugs/show_bug.cgi?id=26389
Bug ID: 26389
Summary: [x86-64] clang generate wrong instruction for cygwin
Product: clang
Version: 3.8
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: LLVM Codegen
Assignee: unassignedclangbugs at nondot.org
Reporter: swigger at gmail.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
when access data that may be far away (than 4G) on x86-64, clang generate a
wrong instruction cause program fail to run (Segment fault).
sample code:
test.cpp:
[code]
struct OSTREAM { char buf[100]; } ;
extern OSTREAM cout;
extern void show(void*);
int main()
{
show(&cout);
}
[/code]
command: clang -target x86_64-pc-cygwin -S -o - ext.cpp
output:
[code]
.text
.def main;
.scl 2;
.type 32;
.endef
.globl main
.align 16, 0x90
main: # @main
.Ltmp0:
.seh_proc main
# BB#0:
pushq %rbp
.Ltmp1:
.seh_pushreg 5
subq $32, %rsp
.Ltmp2:
.seh_stackalloc 32
leaq 32(%rsp), %rbp
.Ltmp3:
.seh_setframe 5, 32
.Ltmp4:
.seh_endprologue
callq __main
leaq cout(%rip), %rcx <=============== WRONG!!
callq _Z4showPv
xorl %eax, %eax
addq $32, %rsp
popq %rbp
retq
.seh_handlerdata
.text
.Ltmp5:
.seh_endproc
[/code]
look at the leaq instruction, when cout is far than 4G away, this will take an
invalid address and then cause a segment fault.
If target is x86_64-pc-linux-gnu, the generated instruction is movabsq that
works.
This is a reduced test case. I can show it on clang 3.8 on ubuntu. the orignal
case is that I found clang compiled program failed to run cout<<"hello"<<endl
on 64 bits msys2 on windows7 x64.
$ clang --version
Ubuntu clang version 3.8.0-svn257311-1~exp1 (trunk) (based on LLVM 3.8.0)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-3.8/bin
--
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/20160130/c89ca47a/attachment-0001.html>
More information about the llvm-bugs
mailing list