[llvm-dev] Since MCJIT I can't get libm functions to work

Frank Winter via llvm-dev llvm-dev at lists.llvm.org
Thu Jun 28 12:40:34 PDT 2018

I am upgrading our JIT application to use LLVM 6.0.0, and with this 
transition I am making the move to use the new MCJIT facility.

A problem I am encountering is that the math functions from libm are not 
resolved/found. I am using the lambda resolver from the KaleidoscopeJIT 
class which first searches the present modules and, if that is 
unsuccessful, continues the search in the whole process space.

The generated modules would declare external functions like

declare float @cosf(float)

and would call it like:

   %17 = call float @cosf(float %16)

The datalayout is set to

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"

The code snippet that adds the module is pretty much from the JIT tutorial:

       auto Resolver = llvm::orc::createLambdaResolver(
                               [&](const std::string &Name) {
                             if (auto Sym = 
CompileLayer.findSymbol(Name, false))
                               return Sym;
                             return llvm::JITSymbol(nullptr);
                               [](const std::string &Name) {
                             if (auto SymAddr =
                               return llvm::JITSymbol(SymAddr, 
                             return llvm::JITSymbol(nullptr);


When running the program I receive the following error:

LLVM ERROR: Program used external function 'cosf' which could not be 

This is on an Intel i7 CPU with LLVM targets configured as "X86".

Adding the '-lm' and '-ldl' option to the linker command that links the 
final program doesn't help. (I even called the 'cosf' function by hand 
in the host code to make sure it is mapped - didn't change the behavior 
of the MCJIT resolver.)

Any ideas?

Best wishes,


More information about the llvm-dev mailing list