[llvm-dev] Moving to ORCv2 - Where are my global constructors and destructors?

David Blaikie via llvm-dev llvm-dev at lists.llvm.org
Thu Dec 19 11:52:01 PST 2019


+Lang Hames <lhames at gmail.com> 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.

On Thu, Dec 19, 2019 at 5:53 AM Gaier, Bjoern via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> 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
> Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816,
> USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert
> Plank, Markus Bode, Heiko Lampert, Takashi Nagano, Takeshi Fukushima.
> Junichi Tajika
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191219/0c0600df/attachment-0001.html>


More information about the llvm-dev mailing list