Recently I tried out the ORCv2 JIT, especially the LLJIT. I gotta say, that I really like the new interface and the way you use it! However there is one thing I’m missing. I wrote a small bit code file, which should force having a global constructor.
__declspec(noinline) int miau()
const int x = miau();
When I parse this IR file in my JIT and go through the ‘globals()’ of the llvm::Module, then I will encounter a symbol with the following name:
“_GLOBAL__sub_I_VectorBIOS.cpp” where VectorBIOS.cpp was the name of the source file I compiled to the bit code.
I then wanted to get the address of that symbol - from the MCJIT times I remember, that those functions are the global constructors, but when calling lookup on that name, I was not able to find the symbol.
So I tried a different way:
llvm::GlobalVariable *var = module->getNamedGlobal(“llvm.global_ctors”);
llvm::ConstantArray InitList = (llvm::ConstantArray)var->getInitializer();
for(unsigned int n = 0; n < InitList->getNumOperands(); n++)
llvm::ConstantStruct CS = (llvm::ConstantStruct)InitList->getOperand(n);
llvm::Constant *FP = CS->getOperand(1);
llvm::ConstantExpr CE = (llvm::ConstantExpr)FP;
FP = CE->getOperand(0);
I then printed the name of the llvm::Function but it was exactly the name I expected “_GLOBAL__sub_I_VectorBIOS.cpp”. This code was executed before I added module to the JIT.
For various reasons I wanted to store the address to the constructor – so I don’t want to call the LLJIT runConstructor – simply because I want to execute those functions later, when the LLJIT does not exist anymore.
I hope someone can help me with this…