<html>
<head>
<base href="http://llvm.org/bugs/" />
</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 --- - MCJIT::addGlobalMapping not mapping functions in the current object correctly"
href="http://llvm.org/bugs/show_bug.cgi?id=20656">20656</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>MCJIT::addGlobalMapping not mapping functions in the current object correctly
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</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>MC
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>marcelo@grandata.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=12895" name="attach_12895" title="Snippet to reproduce the bug in MCJit and to show it works on JIT">attachment 12895</a> <a href="attachment.cgi?id=12895&action=edit" title="Snippet to reproduce the bug in MCJit and to show it works on JIT">[details]</a></span>
Snippet to reproduce the bug in MCJit and to show it works on JIT
In a .cpp file, I define a simple function that I want to call from within a
LLVM module like this:
extern "C"
void someFunction()
{
std::cout << "Called someFunction()" << std::endl;
}
Then, I register the function in the module:
llvm::FunctionType* functionType = llvm::FunctionType::get(
llvm::Type::getVoidTy( context ), false );
llvm::Function* someFunctionPtr = llvm::Function::Create( functionType,
llvm::Function::ExternalLinkage, "someFunction", &module );
I create a MCJIT engine and register the function like this:
llvm::ExecutionEngine* engine = llvm::EngineBuilder( &module )
.setUseMCJIT( true )
.create();
engine->addGlobalMapping( someFunctionPtr, (void*) someFunction );
engine->finalizeObject();
At runtime, I get the following error:
"LLVM ERROR: Program used external function 'someFunction' which could not be
resolved!"
If I use JIT instead of MCJIT (that is, if I switch the header file from
"ExecutionEngine/MCJIT.h" to "ExecutionEngine/JIT.h"), this works as expected,
that is, the module compiles correctly and the function gets called.
However, if I use the same mechanism to register a function in a shared
library, say, printf(), I get no errors and everything works.
So, it seems that this only happens for functions linked inside the current
binary when using MCJIT.
I am attaching a .cpp file with the code to reproduce this issue. It shows both
how it fails with MCJIT and how it succeeds with JIT. I compiled LLVM from
source from SVN revision 215207 (version 3.6.0svn) on a Linux x86_64 box.
Somebody on the IRC channel (DeadMG) was able to reproduce this problem using
LLVM 3.4.0 on a Windows x86 box.</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>