Resolving a function symbol using JIT.


I have a situation where in I need to intercept a call to a particular function and return a pointer to a separate implementation of that function using JIT. The scenario is like this:

  1. A test code or client code calls a function A() for which a dummy implementation is provided in a library which the test code/client links with during compilation.

  2. I create the .bc using -emit-llvm and run it with lli.

  3. Now, in the JIT, I have provided the concrete implementation of the function A(). I have to intercept this call to function A() and return a pointer to the concrete implementation in JIT.

I tried the way external library symbols are being resolved in JITMemoryManager.cpp but the error I get is as follows:

pseudo instructions should be removed before code emission
UNREACHABLE executed at /llvm/lib/Target/X86/X86CodeEmitter.cpp:1175!
0 lli 0x00000000011fa92e llvm::sys::PrintStackTrace(_IO_FILE*) + 46
1 lli 0x00000000011fabeb
2 lli 0x00000000011fae4a
3 0x00007f08378cecb0
4 0x00007f0836915425 gsignal + 53
5 0x00007f0836918b8b abort + 379
6 lli 0x00000000011e1726
7 lli 0x0000000000688f83
8 lli 0x0000000000688700
9 lli 0x0000000000b5789e llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 110
10 lli 0x0000000001168e7b llvm::FPPassManager::runOnFunction(llvm::Function&) + 427
11 lli 0x0000000001168777 llvm::FunctionPassManagerImpl::run(llvm::Function&) + 119
12 lli 0x00000000011686e7 llvm::FunctionPassManager::run(llvm::Function&) + 167
13 lli 0x0000000000ac478f llvm::JIT::jitTheFunction(llvm::Function*, llvm::MutexGuard const&) + 63
14 lli 0x0000000000ac467e llvm::JIT::runJITOnFunctionUnlocked(llvm::Function*, llvm::MutexGuard const&) + 94
15 lli 0x0000000000ac4a9e llvm::JIT::getPointerToFunction(llvm::Function*) + 734
16 lli 0x0000000000ad7e18
17 lli 0x000000000077eb85
18 lli 0x000000000077e9ca X86CompilationCallback + 74
Stack dump:
0. Program arguments: lli -jit-emit-debug test

  1. Running pass ‘X86 Machine Code Emitter’ on function ‘@_ZN4llvm5APInt15clearUnusedBitsEv

If this approach is not proper, where else can I intercept the call to that symbol and return a pointer to the concrete implementation?

Thanks in advance.


Hi All,

Any comments on this?