[llvm-dev] creating an .init section
Martin J. O'Riordan via llvm-dev
llvm-dev at lists.llvm.org
Fri Oct 14 11:51:35 PDT 2016
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>
More information about the llvm-dev
mailing list