[llvm-branch-commits] [llvm] [SystemZ] Implement ctor/dtor emission via @@SQINIT and .xtor sections (PR #171476)
Ulrich Weigand via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Jan 7 05:53:38 PST 2026
================
@@ -2857,3 +2861,45 @@ MCSection *TargetLoweringObjectFileGOFF::SelectSectionForGlobal(
}
return TextSection;
}
+
+static MCSectionGOFF *getStaticStructorSectionGOFF(MCContext &Ctx,
+ const MCSection *TextSection,
+ unsigned Priority) {
+ // xl compilers on z/OS support priorities from min-int to max-int, with
+ // sinit as source priority 0. For clang, sinit has source priority 65535.
+ // For GOFF, the priority sortkey field is an unsigned value. So, we
+ // add min-int to get sorting to work properly but also subtract the
+ // clang sinit (65535) value so internally xl sinit and clang sinit have
+ // the same unsigned GOFF priority sortkey field value (i.e. 0x80000000).
+ static constexpr const uint32_t ClangDefaultSinitPriority = 65535;
+ uint32_t Prio = Priority + (0x80000000 - ClangDefaultSinitPriority);
+
+ std::string Name(".xtor");
+ if (Priority != ClangDefaultSinitPriority)
+ Name = llvm::Twine(Name).concat(".").concat(llvm::utostr(Priority)).str();
+
+ MCSectionGOFF *SInit = Ctx.getGOFFSection(
+ SectionKind::getMetadata(), GOFF::CLASS_SINIT,
+ GOFF::EDAttr{false, GOFF::ESD_RMODE_64, GOFF::ESD_NS_Parts,
+ GOFF::ESD_TS_ByteOriented, GOFF::ESD_BA_Merge,
+ GOFF::ESD_LB_Initial, GOFF::ESD_RQ_0,
+ GOFF::ESD_ALIGN_Doubleword},
+ static_cast<const MCSectionGOFF *>(TextSection)->getParent());
+
+ MCSectionGOFF *Xtor = Ctx.getGOFFSection(
+ SectionKind::getData(), Name,
+ GOFF::PRAttr{true, GOFF::ESD_EXE_DATA, GOFF::ESD_LT_XPLink,
+ GOFF::ESD_BSC_Section, Prio},
+ SInit);
+ return Xtor;
+}
+
+MCSection *TargetLoweringObjectFileGOFF::getStaticCtorSection(
+ unsigned Priority, const MCSymbol *KeySym) const {
+ return getStaticStructorSectionGOFF(getContext(), TextSection, Priority);
+}
+
+MCSection *TargetLoweringObjectFileGOFF::getStaticDtorSection(
+ unsigned Priority, const MCSymbol *KeySym) const {
+ return getStaticStructorSectionGOFF(getContext(), TextSection, Priority);
+}
----------------
uweigand wrote:
It's still a bit weird to have these two functions that do the same thing. I understand this is to mirror what other platforms do, but on those the sections are in fact different ... Maybe it would be better to just have a single `getStaticXtorSection` on GOFF instead, if that matches more directly what GOFF actually does ...
https://github.com/llvm/llvm-project/pull/171476
More information about the llvm-branch-commits
mailing list