Hi,
I have migrated an LLVM front-end from LLVM 3.5 to 3.8 and now to 3.9 and ORC, and there is a concept which I could not transfer. Consider:
extern "C" { void somefunc() {} }
…
auto llvmfunc = llvm::Function::Create(type, llvmFunction::PrivateLinkage, "bla", module));
executionengine.addGlobalMapping(llvmfunc, &somefunc);
// now I have llvmfunc to work with and don't need to consider anything else
The GlobalMappingLayer class seems to provide the functionality I want. I oriented myself on the example from cayman/llvm_orc_initial.cpp at aaa809c3758eed3fad5ef213a18e1a8575e3121f · AndySomogyi/cayman · GitHub (just oriented, because at least on 3.9, I can not stack the GlobalMappingLayer on the ObjectLinkingLayer. I have to put it onto the IRCompileLayer. One question I'd have: How does that order matter?)
The problem I have with that conceptually is: The name seems to matter. The abstraction I'd like is that I get an llvm::Function*, and that is mapped to &somefunc, the name "bla" I gave it should be irrelevant. (And that's what I'd like that to be like for all functions and function calls and whatnot: The name I give them is irrelevant, only the llvm::Function*/llvm::Value* matters.) Am I using the wrong API and there is a way to do this without the names, without any symbol resolution at all? (I don't want to use symbols from the current executable or anywhere else, either.)
The problem I have with that implementationally: It just doesn't work. I get a LLVM ERROR: Undefined temporary symbol from the ELFObjectWriter (and the error is actually about that symbol I'm trying to map), none of the llvm assertions fail. I compiled a minimal example of what I'm doing and attached it. The curious part is that the lambda resolver does not even get invoked… Can anybody tell me what I am doing wrong?
Thank you
Julius
PS: Related thread: http://lists.llvm.org/pipermail/llvm-dev/2015-August/thread.html#89230
PPS:
The whole thing I'm building is supposed to be a script engine for a game. As the scripts aren't supposed to have any access outside the game, I'd like as little linking magic as possible.
It's still in early stages. https://git.openclonk.org/jcaesar/experimental.git/blob/7be141ce667f4689428943592bae0a7568134213:/src/script/C4AulCompiler.cpp
mex.cpp (5.7 KB)
CMakeLists.txt (764 Bytes)