Note that there are some explanatory texts on larger screens.

plurals
  1. POGet a function declaration from another llvm::Module
    primarykey
    data
    text
    <p>In my application i have 2 LLVM modules - the runtime one (which contains <code>void foo(int * a)</code> function definition) and executable one (which i'm creating using LLVM C++ API).</p> <p>In my executable module i create <code>int main(int argc, char ** argv)</code> and want to put <code>llvm::CallInst</code> into it's body, which would call <code>foo()</code> function from runtime module.</p> <p>Here is my code:</p> <pre><code>Function * fooF = Function::Create(runtimeModule-&gt;getFunction("foo")-&gt;getFunctionType(), GlobalValue::WeakAnyLinkage, "foo", execModule); </code></pre> <p>After that, i link two modules together:</p> <pre><code>Linker linker("blabla", execModule, false); linker.LinkInFile("/path/to/runtime.bc", false); execModule = linker.releaseModule(); </code></pre> <p>This compiles OK, however when i run Verifier pass on linked module i get:</p> <pre><code>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 </code></pre> <p>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 <code>dump()</code> on resulting module, i see, that <code>@foo</code> which is coming from runtime module gets removed too, despite it's used by <code>main()</code>. It seems, LLVM thinks that <code>@foo</code> definition in runtime and <code>@foo</code> declaration in executable are unrelated.</p> <p>I've tried to play with linkage types - no luck.</p> <p>So, what is the right way to create a call to the function from another module?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload