[LLVMbugs] [Bug 20656] New: MCJIT::addGlobalMapping not mapping functions in the current object correctly

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Aug 13 15:07:23 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=20656

            Bug ID: 20656
           Summary: MCJIT::addGlobalMapping not mapping functions in the
                    current object correctly
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: MC
          Assignee: unassignedbugs at nondot.org
          Reporter: marcelo at grandata.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 12895
  --> http://llvm.org/bugs/attachment.cgi?id=12895&action=edit
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.

-- 
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/20140813/82967097/attachment.html>


More information about the llvm-bugs mailing list