<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 - _allocate bug during JIT linking"
href="https://bugs.llvm.org/show_bug.cgi?id=44553">44553</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>_allocate bug during JIT linking
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>9.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>other
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Common Code Generator Code
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>alexander_shishkin@relex.ru
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=23019" name="attach_23019" title="Sample code">attachment 23019</a> <a href="attachment.cgi?id=23019&action=edit" title="Sample code">[details]</a></span>
Sample code
Steps to reproduce:
1. On Windows in mingw32 ("mingw32/mingw-w64-i686-llvm 8.0.0-8" msys2 package)
environment compile code in attachment with:
gcc -m32 -g -o sum sum.c -lLLVM.dll -lz -lpsapi -lshell32 -lole32 -luuid
-ladvapi32 -lshlwapi -lshlwapi -Wl,-Bstatic -lstdc++ -lws2_32 -lcrypto -lws2_32
2. Run application: ./sum.exe 2 3
It will produce Segmentation fault
Resulting byte code:
ModuleID = 'sum.bc'
source_filename = "my_module"
define i32 @sum(i32, i32)
{ entry: %ret = alloca i32, i32 4096 %tmp = add i32 %0, %1 store i32 %tmp,
i32* %ret %loaded = load i32, i32* %ret ret i32 %loaded }
During the jit linking _alloca function is inserted. This function causes jump
to the next line instead of real stack check and allocation function:
(gdb)
52 if (LLVMCreateExecutionEngineForModule(&engine, mod, &error) != 0)
{
(gdb)
56 if (error) {
(gdb)
62 if (argc < 3) {
(gdb)
66 long long x = strtoll(argv[1], NULL, 10);
(gdb)
67 long long y = strtoll(argv[2], NULL, 10);
(gdb)
69 int (*sum_func)(int, int) = (int (*)(int,
int))LLVMGetFunctionAddress(engine, "sum");
(gdb)
[New Thread 2208.0xa54]
70 int result = sum_func(x, y);
(gdb) p sum_func
$1 = (int (*)(int, int)) 0x3f0000
(gdb) disas 0x3f0000, +200
Dump of assembler code from 0x3f0000 to 0x3f00c8:
0x003f0000: mov $0x4000,%eax
0x003f0005: call 0x3f000a
0x003f000a: mov 0x4004(%esp),%eax
0x003f0011: add 0x4008(%esp),%eax
0x003f0018: mov %eax,(%esp)
0x003f001b: add $0x4000,%esp
0x003f0021: ret
Error is in line 0x003f0005: call 0x3f000a</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>