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

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(GV1)) {

const StringRef gvName = GV->getName();

bool isLLVMSpecial = StringSwitch(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

Thank a lot Martin. I will give a try.

Have a good weekend,

Jin