Hi, I would like to create an .init section in the LLVM backend. Can anyone shed me the light on how to do it? Do I have to create it in the clang? Thanks, Jin -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161014/4f262397/attachment.html>
Martin J. O'Riordan via llvm-dev
2016-Oct-14 18:51 UTC
[llvm-dev] creating an .init section
I don't use '.init', but I do use '.ctors' and '.dtors' for our target. This is implemented in '<Target>TargetObjectFile.cpp', in my case as follows: MCSection *SHAVETargetObjectFile::getStaticCtorSection(unsigned Priority, const MCSymbol * /* KeySym */) const { std::string ctorsSectionName; if (Priority == 65535u) ctorsSectionName = ".ctors"; else ctorsSectionName = std::string(".ctors.") + utostr(65535u - Priority); return getSHAVESection(ctorsSectionName, DATA); } and in 'SelectSectionForGlobal' in the same file, I have: if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(GV1)) { const StringRef gvName = GV->getName(); bool isLLVMSpecial = StringSwitch<bool>(gvName) .Case("llvm.used", true) .Case("llvm.metadata", true) .Case("llvm.global_ctors", true) .Case("llvm.global_dtors", true) .Default(false); if (isLLVMSpecial) { if (gvName == "llvm.global_ctors") return getStaticCtorSection(); Then use '__attribute__((constructor))' on the function definition you want to run in the initialisation phase. MartinO From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Lin, Jin via llvm-dev Sent: 14 October 2016 19:10 To: llvm-dev at lists.llvm.org Subject: [llvm-dev] creating an .init section Hi, I would like to create an .init section in the LLVM backend. Can anyone shed me the light on how to do it? Do I have to create it in the clang? Thanks, Jin -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161014/0b2945d5/attachment.html>
Thank a lot Martin. I will give a try. Have a good weekend, Jin From: Martin J. O'Riordan [mailto:martin.oriordan at movidius.com] Sent: Friday, October 14, 2016 11:52 AM To: Lin, Jin <jin.lin at intel.com> Cc: 'LLVM Developers' <llvm-dev at lists.llvm.org> Subject: RE: [llvm-dev] creating an .init section I don't use '.init', but I do use '.ctors' and '.dtors' for our target. This is implemented in '<Target>TargetObjectFile.cpp', in my case as follows: MCSection *SHAVETargetObjectFile::getStaticCtorSection(unsigned Priority, const MCSymbol * /* KeySym */) const { std::string ctorsSectionName; if (Priority == 65535u) ctorsSectionName = ".ctors"; else ctorsSectionName = std::string(".ctors.") + utostr(65535u - Priority); return getSHAVESection(ctorsSectionName, DATA); } and in 'SelectSectionForGlobal' in the same file, I have: if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(GV1)) { const StringRef gvName = GV->getName(); bool isLLVMSpecial = StringSwitch<bool>(gvName) .Case("llvm.used", true) .Case("llvm.metadata", true) .Case("llvm.global_ctors", true) .Case("llvm.global_dtors", true) .Default(false); if (isLLVMSpecial) { if (gvName == "llvm.global_ctors") return getStaticCtorSection(); Then use '__attribute__((constructor))' on the function definition you want to run in the initialisation phase. MartinO From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Lin, Jin via llvm-dev Sent: 14 October 2016 19:10 To: llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org> Subject: [llvm-dev] creating an .init section Hi, I would like to create an .init section in the LLVM backend. Can anyone shed me the light on how to do it? Do I have to create it in the clang? Thanks, Jin -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161014/efb7df7f/attachment.html>
Seemingly Similar Threads
- [LLVMdev] Re:question about Insert callInst to call a function in library
- [LLVMdev] How to tell whether a GlobalValue is user-defined
- [LLVMdev] Re: LLVM to SUIF-MACH VM binary
- [LLVMdev] How to tell whether a GlobalValue is user-defined
- [LLVMdev] How to tell whether a GlobalValue is user-defined