Domanda

In my application i have 2 LLVM modules - the runtime one (which contains void foo(int * a) function definition) and executable one (which i'm creating using LLVM C++ API).

In my executable module i create int main(int argc, char ** argv) and want to put llvm::CallInst into it's body, which would call foo() function from runtime module.

Here is my code:

Function * fooF = Function::Create(runtimeModule->getFunction("foo")->getFunctionType(),
    GlobalValue::WeakAnyLinkage, "foo", execModule);

After that, i link two modules together:

Linker linker("blabla", execModule, false);
linker.LinkInFile("/path/to/runtime.bc", false);
execModule = linker.releaseModule();

This compiles OK, however when i run Verifier pass on linked module i get:

Global is external, but doesn't have external or dllimport or weak linkage!
void (%i32*)* @foo
invalid linkage type for function declaration
void (%i32*)* @foo

It's worth mentioning, that all globals in runtime module are internalized using Internalize pass. After linking, but before running Verifier, i'm running Dead Global Elimination pass amongst some other optimizations. And when i do dump() on resulting module, i see, that @foo which is coming from runtime module gets removed too, despite it's used by main(). It seems, LLVM thinks that @foo definition in runtime and @foo declaration in executable are unrelated.

I've tried to play with linkage types - no luck.

So, what is the right way to create a call to the function from another module?

È stato utile?

Soluzione

Ok, i've fixed it, but i still can't understand what was the problem. During building of my runtime bitcode module, i've been applying internalize transformation on it. So i tried to do this at run-time after linking and it helped me.

Ah, and i've been using GlobalValue::WeakAnyLinkage.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top