Vlad Ivanov via llvm-dev
2020-Nov-10 11:41 UTC
[llvm-dev] Fwd: Select output section for a function based on a subtarget feature
Hello, I'm implementing a port of LLVM for PowerPC VLE. It's a compressed instruction set similar to mips16 and ARM Thumb. Instruction encoding (VLE/non-vle) is selected for a given memory region by an attribute in a memory area descriptor. Targets supporting this that I know of are all bare-metal (so powerpc-none-elf). I'm trying to implement ELF support right now. VLE ELF files should have a section header flag set (SHF_PPC_VLE = 0x10000000). I have added a subtarget feature "vle", similar to Altivec, SPE, VSX etc and I'm enabling this feature for appropriate CPUs. Now, functions that are compiled with "vle" feature should go into a different text section (text_vle). I can see that TargetMachine has a method getSubtargetImpl which can be overridden for the implementation and it can return different subtargets for different function attributes. What I'm struggling with is connecting it to section selection; in MCObjectFileInfo::initELFMCObjectFileInfo a default text section is created but since here section should be selected based on function, I'm not sure where object file writer implementation should be "connected" to the subtarget info. What would be the appropriate place for this kind of logic? Best Regards, Vlad
Vlad Ivanov via llvm-dev
2020-Nov-10 20:13 UTC
[llvm-dev] Fwd: Select output section for a function based on a subtarget feature
For anyone stumbling upon this, here's what I ended up with: 1. in llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp, selectELFSectionForGlobal returns a section for a given object. Since TargetMachine is available there as well, it's possible to call checkFeatures() on MCSubtargetInfo 2. In lld/elf/OutputSections.cpp, getPhdrFlags can be updated to propagate section header flags to program header flags 10.11.2020, 14:41, "Vlad Ivanov via llvm-dev" <llvm-dev at lists.llvm.org>:> Hello, > > I'm implementing a port of LLVM for PowerPC VLE. It's a compressed > instruction set similar to mips16 and ARM Thumb. Instruction > encoding (VLE/non-vle) is selected for a given memory region by an > attribute in a memory area descriptor. Targets supporting this that > I know of are all bare-metal (so powerpc-none-elf). > > I'm trying to implement ELF support right now. VLE ELF files should > have a section header flag set (SHF_PPC_VLE = 0x10000000). I have > added a subtarget feature "vle", similar to Altivec, SPE, VSX etc > and I'm enabling this feature for appropriate CPUs. > > Now, functions that are compiled with "vle" feature should go into > a different text section (text_vle). I can see that TargetMachine > has a method getSubtargetImpl which can be overridden for the > implementation and it can return different subtargets for different > function attributes. What I'm struggling with is connecting it > to section selection; in MCObjectFileInfo::initELFMCObjectFileInfo > a default text section is created but since here section should > be selected based on function, I'm not sure where object file > writer implementation should be "connected" to the subtarget info. > > What would be the appropriate place for this kind of logic? > > Best Regards, > > Vlad