I'm implementing a JIT and getting some strange crashes. I'm unsure exactly what's causing them, but it seems to occur when I call the getReturnType() method on some LLVM function objects. More precisely, I'm registering some native C++ functions as LLVM functions through the addGlobalMapping method of an execution engine object. I then keep a pointer to those LLVM function objects, which I use later on to create call instructions to those native C++ functions. // Create a function type object for the function llvm::FunctionType* pFuncType = llvm::FunctionType::get(returnType, argTypes, false); // Create a function object with external linkage and the specified function type llvm::Function* pFuncObj = llvm::Function::Create( pFuncType, llvm::Function::ExternalLinkage, name, s_pModule ); // Add a global mapping in the execution engine for the function pointer s_pExecEngine->addGlobalMapping(pFuncObj, pFuncPtr); The crash does not occur the first time I JIT compile a function, but the second or third time I compile some other function, I will get a crash when trying to create a call instruction. If I try to call the getReturnType() method on the function object before creating the call, I also get a crash. All of my functions are getting put into the same LLVM module, so I'm wondering if LLVM somehow invalidates my function object pointers when I JIT functions, perhaps when I run optimization passes on my LLVM module? Should I not keep pointers to those function objects? Any hints will be appreciated. -- View this message in context: http://www.nabble.com/Strange-LLVM-Crash-tp22508882p22508882.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Hi Nyx,> I'm implementing a JIT and getting some strange crashes. I'm unsure exactly > what's causing them, but it seems to occur when I call the getReturnType() > method on some LLVM function objects. More precisely, I'm registering some > native C++ functions as LLVM functions through the addGlobalMapping method > of an execution engine object. I then keep a pointer to those LLVM function > objects, which I use later on to create call instructions to those native > C++ functions.sounds like memory corruption to me. Try running under valgrind. Ciao, Duncan.
Valgrind seems to not like the Boehm's GC and cause a seg fault of its own before I can even test anything. Anyways, I don't see how I could be causing "memory corruption". If I do something wrong, it has to be some kind of unintended use of the LLVM API. I'm definitely not writing data into the LLVM function objects myself. Could LLVM be deleting those objects is the question I'm basically asking. - Maxime Duncan Sands wrote:> > Hi Nyx, > >> I'm implementing a JIT and getting some strange crashes. I'm unsure >> exactly >> what's causing them, but it seems to occur when I call the >> getReturnType() >> method on some LLVM function objects. More precisely, I'm registering >> some >> native C++ functions as LLVM functions through the addGlobalMapping >> method >> of an execution engine object. I then keep a pointer to those LLVM >> function >> objects, which I use later on to create call instructions to those native >> C++ functions. > > sounds like memory corruption to me. Try running under valgrind. > > Ciao, > > Duncan. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-- View this message in context: http://www.nabble.com/Strange-LLVM-Crash-tp22508882p22514378.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Ok, well, I seem to have pinpointed the cause of the problem more accurately. I'm running some optimization passes on my module after I compile each function in my scripting language (functions can be compiled at various times, when scripts are loaded). Now it seems these optimization passes will prune some of the native C++ functions I'm registering in my module (the functions that haven't been called/used yet). I'd like to find a way to disable this so that all the native functions I register will stay in the module. Here are the optimization passes I'm running: passManager.add(new llvm::TargetData(s_pModule)); passManager.add(llvm::createLowerSetJmpPass()); passManager.add(llvm::createRaiseAllocationsPass()); passManager.add(llvm::createCFGSimplificationPass()); passManager.add(llvm::createPromoteMemoryToRegisterPass()); passManager.add(llvm::createGlobalOptimizerPass()); passManager.add(llvm::createGlobalDCEPass()); passManager.add(llvm::createFunctionInliningPass()); I would like to know either which pass does this (global optimizer maybe?) so I can disable it, or what flag I can set on my C++ function objects to keep them from being pruned out. -- View this message in context: http://www.nabble.com/Strange-LLVM-Crash-tp22508882p22515204.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Functions that have an entry in llvm.used should not be deleted. Not entirely sure the JIT honors that but I think it does. On Mar 14, 2009, at 10:46 AM, Nyx wrote:> Ok, well, I seem to have pinpointed the cause of the problem more > accurately. > I'm running some optimization passes on my module after I compile each > function in my scripting language (functions can be compiled at > various > times, when scripts are loaded). Now it seems these optimization > passes will > prune some of the native C++ functions I'm registering in my module > (the > functions that haven't been called/used yet). I'd like to find a way > to > disable this so that all the native functions I register will stay > in the > module. > > Here are the optimization passes I'm running: > > passManager.add(new llvm::TargetData(s_pModule)); > passManager.add(llvm::createLowerSetJmpPass()); > passManager.add(llvm::createRaiseAllocationsPass()); > passManager.add(llvm::createCFGSimplificationPass()); > passManager.add(llvm::createPromoteMemoryToRegisterPass()); > passManager.add(llvm::createGlobalOptimizerPass()); > passManager.add(llvm::createGlobalDCEPass()); > passManager.add(llvm::createFunctionInliningPass()); > > I would like to know either which pass does this (global optimizer > maybe?) > so I can disable it, or what flag I can set on my C++ function > objects to > keep them from being pruned out. > -- > View this message in context: http://www.nabble.com/Strange-LLVM-Crash-tp22508882p22515204.html > Sent from the LLVM - Dev mailing list archive at Nabble.com. > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Nyx wrote:> Ok, well, I seem to have pinpointed the cause of the problem more accurately. > I'm running some optimization passes on my module after I compile each > function in my scripting language (functions can be compiled at various > times, when scripts are loaded). Now it seems these optimization passes will > prune some of the native C++ functions I'm registering in my module (the > functions that haven't been called/used yet). I'd like to find a way to > disable this so that all the native functions I register will stay in the > module."externally visible" functions should never be deleted. What's the linkage type on your functions? internal? Don't mark things internal unless you don't mind if they go away. :) Nick> Here are the optimization passes I'm running: > > passManager.add(new llvm::TargetData(s_pModule)); > passManager.add(llvm::createLowerSetJmpPass()); > passManager.add(llvm::createRaiseAllocationsPass()); > passManager.add(llvm::createCFGSimplificationPass()); > passManager.add(llvm::createPromoteMemoryToRegisterPass()); > passManager.add(llvm::createGlobalOptimizerPass()); > passManager.add(llvm::createGlobalDCEPass()); > passManager.add(llvm::createFunctionInliningPass()); > > I would like to know either which pass does this (global optimizer maybe?) > so I can disable it, or what flag I can set on my C++ function objects to > keep them from being pruned out.