Moving to ORCv2 - Where are my global constructors and destructors?

Heyho,

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.

int wuff();

__declspec(noinline) int miau()

{

printf(“Huhuhu”);

return wuff();

}

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”);

if(var)

{

llvm::ConstantArray InitList = (llvm::ConstantArray)var->getInitializer();

for(unsigned int n = 0; n < InitList->getNumOperands(); n++)

{

llvm::ConstantStruct CS = (llvm::ConstantStruct)InitList->getOperand(n);

if(!CS)

{

continue;

}

llvm::Constant *FP = CS->getOperand(1);

if(FP->isNullValue())

continue;

llvm::ConstantExpr CE = (llvm::ConstantExpr)FP;

if(CE->isCast())

{

FP = CE->getOperand(0);

}

((llvm::Function*)FP)->getName();

}

}

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…

Kind Greetings

Björn

+Lang Hames owner/author of the ORC JIT (though I think he’s out of office at the moment, so replies from him might be delayed).

I believe there’s a way to wire up the global ctors, but I don’t know the details unfortunately - perhaps someone else will chime in if/before Lang gets a chance.

Is there a code example or maybe a documentation about this subject? Sadly it is an important part of my project to get the addresses of the constructors and destructors.

I really ran out of ideas though, every time when I try to look them up, they seem to be gone already .w.

Pinging Lang here. I think thi question comes up often enough - maybe needs an FAQ somewhere