Calling virtual elf functions under windows -> Adding ASM code

Still no progress with this problem. Only that non-member functions seems to be working…
Even when I set the target triple of the Module (when the file was parsed at runtime) to “COFF” nothing changes…

asmELF.s (1.39 KB)

asmMSVC.s (2.32 KB)





Hi Bjoern,

It looks like you are casting a regular function pointer (returned from getFunctionAddress) to a virtual method pointer. This is undefined behavior.

The easiest way to achieve the effect you want would be to add a trampoline to your source (or at the IR level):

extern “C” SimpleResult call_Interface_init(Interface *Instance) { return Instance->init(); }

Then you can just use:

auto CallInit = (SimpleResult()(Interface))engine->getFunctionAddress(“call_Interface_init”);


Hi Björn,

It’s correct - I tried casting the virtual function to a regular function. But I also tried using the virtual function in the normal way.

Yes. If I understand your setup correctly you have a base class, Interface, which is currently compiled into your application, and you are creating a derived class in JIT’d code, and returning an Interface pointer to an instance of the derived class. In this case you are probably running into ABI incompatibility issues in the class layout between the ahead-of-time and JIT’d code. Your ahead-of-time code will always have to call virtual functions via trampolines. I would remove all references to the Interface class from your main application (so that the compiler catches anyone who tries to use it directly) and make it an opaque pointer type that you pass into JIT’d code.