How to JIT c++ code with classes having virtual functions via LLVM?
<p>I'm a bit confused. I'm trying to jit this primitive C++ code using LLVM and CLANG:</p>

<pre><code>class Test {
    int _v;
public:
    Test() : _v(0) { }
    ~Test() { }
    void Set(int v) {
        _v = v;
    }
    int Get() {
        return _v;
    }
};

extern "C" Test* CreateTest() {
    return new Test;
}

extern "C" void DestroyTest(Test** o) {
        delete *o;
        *o = 0;
}
</code></pre>

<p>I got <em>llvm::Module</em> as a result of <em>clang::CompilerInstance</em> invocation. When I pass that module into <em>llvm::ExecutionEngine</em> I can obtain proper pointers to "<em>CreateTest</em>" and "<em>DestroyTest</em>" routines, and everything works fine.</p>

<p>However, if I make "<em>Test::Set</em>" and "<em>Test::Get</em>" <strong>virtual</strong> in my class specification, any <em>llvm::ExecutionEngine::getFunctionAddress()</em> fails in <em>RuntimeDyldImpl::ResolveExternalSymbols()</em>.</p>

<p>It reports a fatal error, something like "Program used external function ??_7type_info@@6B@ which could not be resolved", and terminates my host process. </p>

<p>How can I resolve that linking issue??</p>

<p>BTW, are there any linking tricks to invoke libc functions, like malloc, printf, etc. from jit code?</p>