I use MCJIT on LLVM-3.8 and use LLVMAddGlobalMapping to register call-back functions. LLVMAddGlobalMapping needs a LLVMValueRef to a function call value. However, is this still valid after optimization? I always suspected that this is not true, but it worked in many occasions anyway. Now, I think I hit a case where it fails.
I do roughly this:
...
funcRef = LLVMAddFunction(module, funcName, funcType);
...
LLVMRunPassManager(passes, module);
...
LLVMCreateExecutionEngineForModule(&ee, module, &err);
...
// Is funcRef still valid here?
LLVMAddGlobalMapping(ee, funcRef, &myFunc);
...
Is this admissible? If not (what I assume), how can I manage call-backs in an optimization-proof way?