I am using llvm to generate jit code for numerical computation on window 7 64 platform. There is a function call, pow, in the jit code. The problem is that at run time, the pow function call sometimes links to msvcrt.dll, and sometimes to msvcr100.dll. These two calls from two dlls return different results, causing sporadic results.
I tried to make the pow function either intrinsic or function call. Both did not work.
My question is that:
Is there a way to tell the jit engine to link the pow function to a specific dll?
are there any other suggestions?
External symbol resolution is handled by the memory manager. The default memory manager used with the JIT execution engine uses sys::DynamicLibrary::SearchForAddressOfSymbol to look for symbols, and that’s how it’s finding ‘pow’ in your case. On Windows that ends up with a call to GetProcAddress for each loaded library and you get whichever one happens to be found first.
To link to a specific implementation of the symbol, you’ll need to provide a custom memory manager. You can create a memory manager that aggregates the default memory manager (created via JITMemoryManager::CreateDefaultMemManager()) and defers everything except getPointerToNamedFunction to the default memory manager. Then your custom implementation of getPointerToNamedFunction can provide the address of whichever pow function you prefer.
Note that if you ever switch over to the MCJIT execution engine you’ll find that it behaves just like this except that you’ll want a different default memory manager as your base.