Gaier, Bjoern via llvm-dev
2020-Jan-07 14:13 UTC
[llvm-dev] Moving to ORCv2 - Where are my global constructors and destructors? + More information
Sorry for the spam, but I made some progress with my issue and wanted to share what I found out. I tried the following line before adding my module to the LLJIT: “this->mainModule->getFunction("_GLOBAL__sub_I_VectorBIOS.cpp")->isDiscardableIfUnused();” This actually returned true So I tried the following line: “this->mainModule->getFunction("_GLOBAL__sub_I_VectorBIOS.cpp")->setLinkage(llvm::GlobalValue::ExternalLinkage);” Now I was able to find the function and execute the global constructor. For a workaround this works for me. However, running LLJITs ‘runConstructors’ does still not work, they are still empty. From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of Gaier, Bjoern via llvm-dev Sent: 06 January 2020 15:02 To: David Blaikie <dblaikie at gmail.com>; Lang Hames <lhames at gmail.com> Cc: llvm-dev at lists.llvm.org Subject: Re: [llvm-dev] Moving to ORCv2 - Where are my global constructors and destructors? 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. From: David Blaikie <dblaikie at gmail.com<mailto:dblaikie at gmail.com>> Sent: 19 December 2019 20:52 To: Gaier, Bjoern <Bjoern.Gaier at horiba.com<mailto:Bjoern.Gaier at horiba.com>>; Lang Hames <lhames at gmail.com<mailto:lhames at gmail.com>> Cc: llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org> Subject: Re: [llvm-dev] Moving to ORCv2 - Where are my global constructors and destructors? +Lang Hames<mailto: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<mailto: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<mailto:llvm-dev at lists.llvm.org> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev 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 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200107/2d34d962/attachment.html>
Lang Hames via llvm-dev
2020-Jan-17 02:49 UTC
[llvm-dev] Moving to ORCv2 - Where are my global constructors and destructors? + More information
HI Bjoern, Thanks for your patience — It’s going to take some time for me to get through all the emails that built up while I was away last month. I’m glad you found a workaround for your issue, and thanks for pointing out the runConstructors problem. I’m working on a big update to the static initializers/deinitializers problem which I hope to land in the next week or so. Hopefully that will address this issue. — Lang. Sent from my iPad> On Jan 7, 2020, at 6:13 AM, Gaier, Bjoern <Bjoern.Gaier at horiba.com> wrote: > > > Sorry for the spam, but I made some progress with my issue and wanted to share what I found out. > > I tried the following line before adding my module to the LLJIT: > “this->mainModule->getFunction("_GLOBAL__sub_I_VectorBIOS.cpp")->isDiscardableIfUnused();” This actually returned true > So I tried the following line: > “this->mainModule->getFunction("_GLOBAL__sub_I_VectorBIOS.cpp")->setLinkage(llvm::GlobalValue::ExternalLinkage);” > Now I was able to find the function and execute the global constructor. For a workaround this works for me. > However, running LLJITs ‘runConstructors’ does still not work, they are still empty. > > > From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of Gaier, Bjoern via llvm-dev > Sent: 06 January 2020 15:02 > To: David Blaikie <dblaikie at gmail.com>; Lang Hames <lhames at gmail.com> > Cc: llvm-dev at lists.llvm.org > Subject: Re: [llvm-dev] Moving to ORCv2 - Where are my global constructors and destructors? > > 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. > > From: David Blaikie <dblaikie at gmail.com> > Sent: 19 December 2019 20:52 > To: Gaier, Bjoern <Bjoern.Gaier at horiba.com>; Lang Hames <lhames at gmail.com> > Cc: llvm-dev at lists.llvm.org > Subject: Re: [llvm-dev] Moving to ORCv2 - Where are my global constructors and destructors? > > +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. > > 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 > 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 > 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-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200116/58b1dd5e/attachment-0001.html>