[XCOFF][NFC] make csect properties optional for getXCOFFSection
We are going to support debug sections for XCOFF. So the csect
properties are not necessary. This patch makes these properties
optional.
Reviewed By: hubert.reinterpretcast
Differential Revision: https://reviews.llvm.org/D95931
GitOrigin-RevId: 5517923b1cacf3e0ace438fd536b333940c3153d
diff --git a/include/llvm/BinaryFormat/XCOFF.h b/include/llvm/BinaryFormat/XCOFF.h
index 48e1baf..803a3ab 100644
--- a/include/llvm/BinaryFormat/XCOFF.h
+++ b/include/llvm/BinaryFormat/XCOFF.h
@@ -406,6 +406,13 @@
StringRef getNameForTracebackTableLanguageId(TracebackTable::LanguageID LangId);
SmallString<32> getExtendedTBTableFlagString(uint8_t Flag);
+struct CsectProperties {
+ CsectProperties(StorageMappingClass SMC, SymbolType ST)
+ : MappingClass(SMC), Type(ST) {}
+ StorageMappingClass MappingClass;
+ SymbolType Type;
+};
+
} // end namespace XCOFF
} // end namespace llvm
diff --git a/include/llvm/MC/MCContext.h b/include/llvm/MC/MCContext.h
index 1eb31de..a06aabe 100644
--- a/include/llvm/MC/MCContext.h
+++ b/include/llvm/MC/MCContext.h
@@ -579,11 +579,11 @@
const MCSymbolWasm *Group, unsigned UniqueID,
const char *BeginSymName);
- MCSectionXCOFF *getXCOFFSection(StringRef Section,
- XCOFF::StorageMappingClass MappingClass,
- XCOFF::SymbolType CSectType, SectionKind K,
- bool MultiSymbolsAllowed = false,
- const char *BeginSymName = nullptr);
+ MCSectionXCOFF *
+ getXCOFFSection(StringRef Section, SectionKind K,
+ Optional<XCOFF::CsectProperties> CsectProp = None,
+ bool MultiSymbolsAllowed = false,
+ const char *BeginSymName = nullptr);
// Create and save a copy of STI and return a reference to the copy.
MCSubtargetInfo &getSubtargetCopy(const MCSubtargetInfo &STI);
diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index f0f4516..49c9d46 100644
--- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -2157,8 +2157,9 @@
else
report_fatal_error("XCOFF other section types not yet implemented.");
- return getContext().getXCOFFSection(SectionName, MappingClass, XCOFF::XTY_SD,
- Kind, /* MultiSymbolsAllowed*/ true);
+ return getContext().getXCOFFSection(
+ SectionName, Kind, XCOFF::CsectProperties(MappingClass, XCOFF::XTY_SD),
+ /* MultiSymbolsAllowed*/ true);
}
MCSection *TargetLoweringObjectFileXCOFF::getSectionForExternalReference(
@@ -2171,8 +2172,9 @@
// Externals go into a csect of type ER.
return getContext().getXCOFFSection(
- Name, isa<Function>(GO) ? XCOFF::XMC_DS : XCOFF::XMC_UA, XCOFF::XTY_ER,
- SectionKind::getMetadata());
+ Name, SectionKind::getMetadata(),
+ XCOFF::CsectProperties(isa<Function>(GO) ? XCOFF::XMC_DS : XCOFF::XMC_UA,
+ XCOFF::XTY_ER));
}
MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal(
@@ -2183,8 +2185,9 @@
SmallString<128> Name;
getNameWithPrefix(Name, GO, TM);
return getContext().getXCOFFSection(
- Name, Kind.isBSSLocal() ? XCOFF::XMC_BS : XCOFF::XMC_RW, XCOFF::XTY_CM,
- Kind);
+ Name, Kind,
+ XCOFF::CsectProperties(
+ Kind.isBSSLocal() ? XCOFF::XMC_BS : XCOFF::XMC_RW, XCOFF::XTY_CM));
}
if (Kind.isMergeableCString()) {
@@ -2200,7 +2203,7 @@
getNameWithPrefix(Name, GO, TM);
return getContext().getXCOFFSection(
- Name, XCOFF::XMC_RO, XCOFF::XTY_SD, Kind,
+ Name, Kind, XCOFF::CsectProperties(XCOFF::XMC_RO, XCOFF::XTY_SD),
/* MultiSymbolsAllowed*/ !TM.getDataSections());
}
@@ -2223,8 +2226,9 @@
if (TM.getDataSections()) {
SmallString<128> Name;
getNameWithPrefix(Name, GO, TM);
- return getContext().getXCOFFSection(Name, XCOFF::XMC_RW, XCOFF::XTY_SD,
- SectionKind::getData());
+ return getContext().getXCOFFSection(
+ Name, SectionKind::getData(),
+ XCOFF::CsectProperties(XCOFF::XMC_RW, XCOFF::XTY_SD));
}
return DataSection;
}
@@ -2233,8 +2237,9 @@
if (TM.getDataSections()) {
SmallString<128> Name;
getNameWithPrefix(Name, GO, TM);
- return getContext().getXCOFFSection(Name, XCOFF::XMC_RO, XCOFF::XTY_SD,
- SectionKind::getReadOnly());
+ return getContext().getXCOFFSection(
+ Name, SectionKind::getReadOnly(),
+ XCOFF::CsectProperties(XCOFF::XMC_RO, XCOFF::XTY_SD));
}
return ReadOnlySection;
}
@@ -2253,8 +2258,9 @@
// the table doesn't prevent the removal.
SmallString<128> NameStr(".rodata.jmp..");
getNameWithPrefix(NameStr, &F, TM);
- return getContext().getXCOFFSection(NameStr, XCOFF::XMC_RO, XCOFF::XTY_SD,
- SectionKind::getReadOnly());
+ return getContext().getXCOFFSection(
+ NameStr, SectionKind::getReadOnly(),
+ XCOFF::CsectProperties(XCOFF::XMC_RO, XCOFF::XTY_SD));
}
bool TargetLoweringObjectFileXCOFF::shouldPutJumpTableInFunctionSection(
@@ -2345,9 +2351,11 @@
Func->isDeclaration()) &&
isa<Function>(Func)) {
return getContext()
- .getXCOFFSection(NameStr, XCOFF::XMC_PR,
- Func->isDeclaration() ? XCOFF::XTY_ER : XCOFF::XTY_SD,
- SectionKind::getText())
+ .getXCOFFSection(
+ NameStr, SectionKind::getText(),
+ XCOFF::CsectProperties(XCOFF::XMC_PR, Func->isDeclaration()
+ ? XCOFF::XTY_ER
+ : XCOFF::XTY_SD))
->getQualNameSymbol();
}
@@ -2358,8 +2366,9 @@
const Function *F, const TargetMachine &TM) const {
SmallString<128> NameStr;
getNameWithPrefix(NameStr, F, TM);
- return getContext().getXCOFFSection(NameStr, XCOFF::XMC_DS, XCOFF::XTY_SD,
- SectionKind::getData());
+ return getContext().getXCOFFSection(
+ NameStr, SectionKind::getData(),
+ XCOFF::CsectProperties(XCOFF::XMC_DS, XCOFF::XTY_SD));
}
MCSection *TargetLoweringObjectFileXCOFF::getSectionForTOCEntry(
@@ -2367,7 +2376,8 @@
// Use TE storage-mapping class when large code model is enabled so that
// the chance of needing -bbigtoc is decreased.
return getContext().getXCOFFSection(
- cast<MCSymbolXCOFF>(Sym)->getSymbolTableName(),
- TM.getCodeModel() == CodeModel::Large ? XCOFF::XMC_TE : XCOFF::XMC_TC,
- XCOFF::XTY_SD, SectionKind::getData());
+ cast<MCSymbolXCOFF>(Sym)->getSymbolTableName(), SectionKind::getData(),
+ XCOFF::CsectProperties(
+ TM.getCodeModel() == CodeModel::Large ? XCOFF::XMC_TE : XCOFF::XMC_TC,
+ XCOFF::XTY_SD));
}
diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp
index bbff590..7d5a1db 100644
--- a/lib/MC/MCContext.cpp
+++ b/lib/MC/MCContext.cpp
@@ -671,12 +671,14 @@
}
MCSectionXCOFF *
-MCContext::getXCOFFSection(StringRef Section, XCOFF::StorageMappingClass SMC,
- XCOFF::SymbolType Type, SectionKind Kind,
+MCContext::getXCOFFSection(StringRef Section, SectionKind Kind,
+ Optional<XCOFF::CsectProperties> CsectProp,
bool MultiSymbolsAllowed, const char *BeginSymName) {
// Do the lookup. If we have a hit, return it.
- auto IterBool = XCOFFUniquingMap.insert(
- std::make_pair(XCOFFSectionKey{Section.str(), SMC}, nullptr));
+ // FIXME: handle the case for non-csect sections. Non-csect section has None
+ // CsectProp.
+ auto IterBool = XCOFFUniquingMap.insert(std::make_pair(
+ XCOFFSectionKey{Section.str(), CsectProp->MappingClass}, nullptr));
auto &Entry = *IterBool.first;
if (!IterBool.second) {
MCSectionXCOFF *ExistedEntry = Entry.second;
@@ -689,7 +691,8 @@
// Otherwise, return a new section.
StringRef CachedName = Entry.first.SectionName;
MCSymbolXCOFF *QualName = cast<MCSymbolXCOFF>(getOrCreateSymbol(
- CachedName + "[" + XCOFF::getMappingClassString(SMC) + "]"));
+ CachedName + "[" + XCOFF::getMappingClassString(CsectProp->MappingClass) +
+ "]"));
MCSymbol *Begin = nullptr;
if (BeginSymName)
@@ -697,9 +700,9 @@
// QualName->getUnqualifiedName() and CachedName are the same except when
// CachedName contains invalid character(s) such as '$' for an XCOFF symbol.
- MCSectionXCOFF *Result = new (XCOFFAllocator.Allocate())
- MCSectionXCOFF(QualName->getUnqualifiedName(), SMC, Type, Kind, QualName,
- Begin, CachedName, MultiSymbolsAllowed);
+ MCSectionXCOFF *Result = new (XCOFFAllocator.Allocate()) MCSectionXCOFF(
+ QualName->getUnqualifiedName(), CsectProp->MappingClass, CsectProp->Type,
+ Kind, QualName, Begin, CachedName, MultiSymbolsAllowed);
Entry.second = Result;
auto *F = new MCDataFragment();
diff --git a/lib/MC/MCObjectFileInfo.cpp b/lib/MC/MCObjectFileInfo.cpp
index 9690eaf..b4c4c87 100644
--- a/lib/MC/MCObjectFileInfo.cpp
+++ b/lib/MC/MCObjectFileInfo.cpp
@@ -874,31 +874,37 @@
// the ABI or object file format. For example, the XL compiler uses an unnamed
// csect for program code.
TextSection = Ctx->getXCOFFSection(
- ".text", XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD,
- SectionKind::getText(), /* MultiSymbolsAllowed*/ true);
+ ".text", SectionKind::getText(),
+ XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD),
+ /* MultiSymbolsAllowed*/ true);
DataSection = Ctx->getXCOFFSection(
- ".data", XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD,
- SectionKind::getData(), /* MultiSymbolsAllowed*/ true);
+ ".data", SectionKind::getData(),
+ XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD),
+ /* MultiSymbolsAllowed*/ true);
ReadOnlySection = Ctx->getXCOFFSection(
- ".rodata", XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD,
- SectionKind::getReadOnly(), /* MultiSymbolsAllowed*/ true);
+ ".rodata", SectionKind::getReadOnly(),
+ XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
+ /* MultiSymbolsAllowed*/ true);
- TOCBaseSection =
- Ctx->getXCOFFSection("TOC", XCOFF::StorageMappingClass::XMC_TC0,
- XCOFF::XTY_SD, SectionKind::getData());
+ TOCBaseSection = Ctx->getXCOFFSection(
+ "TOC", SectionKind::getData(),
+ XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TC0,
+ XCOFF::XTY_SD));
// The TOC-base always has 0 size, but 4 byte alignment.
TOCBaseSection->setAlignment(Align(4));
- LSDASection = Ctx->getXCOFFSection(".gcc_except_table",
- XCOFF::StorageMappingClass::XMC_RO,
- XCOFF::XTY_SD, SectionKind::getReadOnly());
+ LSDASection = Ctx->getXCOFFSection(
+ ".gcc_except_table", SectionKind::getReadOnly(),
+ XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO,
+ XCOFF::XTY_SD));
- CompactUnwindSection =
- Ctx->getXCOFFSection(".eh_info_table", XCOFF::StorageMappingClass::XMC_RW,
- XCOFF::XTY_SD, SectionKind::getData());
+ CompactUnwindSection = Ctx->getXCOFFSection(
+ ".eh_info_table", SectionKind::getData(),
+ XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW,
+ XCOFF::XTY_SD));
// DWARF sections for XCOFF are not csects. They are special STYP_DWARF
// sections, and the individual DWARF sections are distinguished by their
diff --git a/lib/Target/PowerPC/PPCISelLowering.cpp b/lib/Target/PowerPC/PPCISelLowering.cpp
index e9cdb50..116ab69 100644
--- a/lib/Target/PowerPC/PPCISelLowering.cpp
+++ b/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -5049,8 +5049,8 @@
const auto getExternalFunctionEntryPointSymbol = [&](StringRef SymName) {
auto &Context = DAG.getMachineFunction().getMMI().getContext();
MCSectionXCOFF *Sec = Context.getXCOFFSection(
- (Twine(".") + Twine(SymName)).str(), XCOFF::XMC_PR, XCOFF::XTY_ER,
- SectionKind::getMetadata());
+ (Twine(".") + Twine(SymName)).str(), SectionKind::getMetadata(),
+ XCOFF::CsectProperties(XCOFF::XMC_PR, XCOFF::XTY_ER));
return Sec->getQualNameSymbol();
};