LLVM Discussion Forums

How to tell the LLVM 6 JIT ExecutionEngine that a function exists

In debug mode, I am getting errors like:

Global is external, but doesn’t have external or weak linkage!
double (i8*, double, double)* @rr_distrib_normal

due to failing

  Assert(!GV.isDeclaration() || GV.hasValidDeclarationLinkage(),
         "Global is external, but doesn't have external or weak linkage!", &GV);

from Verifier.cpp

for a function that draws from a normal distribution. In release mode, everything works fine (I indeed get draws from normals), so presumably, my problem is that I’m confusing the llvm verifier, not that I’m doing something actually wrong. I think the relevant code is:

executionEngine->addGlobalMapping(
    createGlobalMappingFunction("rr_distrib_normal",
        FunctionType::get(double_type, args_void_double_double, false), module),
        (void*) distrib_normal);

and then, later in the same file:

double distrib_normal(Random* random, double mu, double sigma)
{
    Log(Logger::LOG_DEBUG) << "distrib_normal("
            << static_cast<void*>(random)
            << ", " << mu << ", " << sigma << ")";

    NormalDist normal(mu, sigma);
    return normal(random->engine);
}

I also have:

        func = module->getFunction("rr_distrib_normal");

in a different file.

What is the canonical way to do something like this? Should I do something different?

Thank you!

Anybody? I still have this problem, and have resorted to copying llvm’s codebase and commenting out the assert in question, which seems less than ideal.