[llvm] [MC][x86-64] Decide if each individual mergeable constants is small or large (PR #209881)
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 10 15:49:20 PDT 2026
================
@@ -1053,59 +1051,89 @@ bool TargetLoweringObjectFileELF::shouldPutJumpTableInFunctionSection(
/// Given a mergeable constant with the specified size and relocation
/// information, return a section that it should be placed in.
+bool TargetLoweringObjectFileELF::isLargeConstant(const DataLayout &DL,
+ SectionKind Kind,
+ const Constant *C) const {
+ if (!TM)
+ return false;
+ if (TM->getCodeModel() == CodeModel::Large)
+ return TM->getTargetTriple().getArch() == Triple::x86_64;
+ if (Kind.isMergeableCString() && C) {
+ assert(C->getType()->isSized());
+ return TM->isLargeDataSize(DL.getTypeAllocSize(C->getType()));
+ }
+ return false;
+}
+
MCSection *TargetLoweringObjectFileELF::getSectionForConstant(
const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment,
const Function *F) const {
- if (Kind.isMergeableConst4() && MergeableConst4Section)
- return MergeableConst4Section;
- if (Kind.isMergeableConst8() && MergeableConst8Section)
- return MergeableConst8Section;
- if (Kind.isMergeableConst16() && MergeableConst16Section)
- return MergeableConst16Section;
- if (Kind.isMergeableConst32() && MergeableConst32Section)
- return MergeableConst32Section;
+ auto &Context = getContext();
+ StringRef CstPrefix = ".rodata";
+ unsigned MergeableCstFlags = ELF::SHF_ALLOC;
+ if (Kind.isMergeableConst() || Kind.isMergeableCString())
+ MergeableCstFlags |= ELF::SHF_MERGE;
+ if (isLargeConstant(DL, Kind, C)) {
+ MergeableCstFlags |= ELF::SHF_X86_64_LARGE;
+ CstPrefix = ".lrodata";
+ }
+
+ if (Kind.isMergeableConst4())
+ return Context.getELFSection(CstPrefix + ".cst4", ELF::SHT_PROGBITS,
+ MergeableCstFlags, 4);
+ if (Kind.isMergeableConst8())
+ return Context.getELFSection(CstPrefix + ".cst8", ELF::SHT_PROGBITS,
+ MergeableCstFlags, 8);
+ if (Kind.isMergeableConst16())
+ return Context.getELFSection(CstPrefix + ".cst16", ELF::SHT_PROGBITS,
+ MergeableCstFlags, 16);
+ if (Kind.isMergeableConst32())
+ return Context.getELFSection(CstPrefix + ".cst32", ELF::SHT_PROGBITS,
+ MergeableCstFlags, 32);
if (Kind.isReadOnly())
- return ReadOnlySection;
+ return Context.getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
- return DataRelROSection;
+ return Context.getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
----------------
aeubanks wrote:
now that we've combined the SectionSuffix version of `getSectionForConstant()` into this one returning the stored section is not doable
https://github.com/llvm/llvm-project/pull/209881
More information about the llvm-commits
mailing list