Skip to content

Commit 5517923

Browse files
author
Chen Zheng
committed
[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
1 parent 9301507 commit 5517923

File tree

6 files changed

+77
-51
lines changed

6 files changed

+77
-51
lines changed

llvm/include/llvm/BinaryFormat/XCOFF.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,13 @@ enum ExtendedTBTableFlag : uint8_t {
406406
StringRef getNameForTracebackTableLanguageId(TracebackTable::LanguageID LangId);
407407
SmallString<32> getExtendedTBTableFlagString(uint8_t Flag);
408408

409+
struct CsectProperties {
410+
CsectProperties(StorageMappingClass SMC, SymbolType ST)
411+
: MappingClass(SMC), Type(ST) {}
412+
StorageMappingClass MappingClass;
413+
SymbolType Type;
414+
};
415+
409416
} // end namespace XCOFF
410417
} // end namespace llvm
411418

llvm/include/llvm/MC/MCContext.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -579,11 +579,11 @@ namespace llvm {
579579
const MCSymbolWasm *Group, unsigned UniqueID,
580580
const char *BeginSymName);
581581

582-
MCSectionXCOFF *getXCOFFSection(StringRef Section,
583-
XCOFF::StorageMappingClass MappingClass,
584-
XCOFF::SymbolType CSectType, SectionKind K,
585-
bool MultiSymbolsAllowed = false,
586-
const char *BeginSymName = nullptr);
582+
MCSectionXCOFF *
583+
getXCOFFSection(StringRef Section, SectionKind K,
584+
Optional<XCOFF::CsectProperties> CsectProp = None,
585+
bool MultiSymbolsAllowed = false,
586+
const char *BeginSymName = nullptr);
587587

588588
// Create and save a copy of STI and return a reference to the copy.
589589
MCSubtargetInfo &getSubtargetCopy(const MCSubtargetInfo &STI);

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,8 +2157,9 @@ MCSection *TargetLoweringObjectFileXCOFF::getExplicitSectionGlobal(
21572157
else
21582158
report_fatal_error("XCOFF other section types not yet implemented.");
21592159

2160-
return getContext().getXCOFFSection(SectionName, MappingClass, XCOFF::XTY_SD,
2161-
Kind, /* MultiSymbolsAllowed*/ true);
2160+
return getContext().getXCOFFSection(
2161+
SectionName, Kind, XCOFF::CsectProperties(MappingClass, XCOFF::XTY_SD),
2162+
/* MultiSymbolsAllowed*/ true);
21622163
}
21632164

21642165
MCSection *TargetLoweringObjectFileXCOFF::getSectionForExternalReference(
@@ -2171,8 +2172,9 @@ MCSection *TargetLoweringObjectFileXCOFF::getSectionForExternalReference(
21712172

21722173
// Externals go into a csect of type ER.
21732174
return getContext().getXCOFFSection(
2174-
Name, isa<Function>(GO) ? XCOFF::XMC_DS : XCOFF::XMC_UA, XCOFF::XTY_ER,
2175-
SectionKind::getMetadata());
2175+
Name, SectionKind::getMetadata(),
2176+
XCOFF::CsectProperties(isa<Function>(GO) ? XCOFF::XMC_DS : XCOFF::XMC_UA,
2177+
XCOFF::XTY_ER));
21762178
}
21772179

21782180
MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal(
@@ -2183,8 +2185,9 @@ MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal(
21832185
SmallString<128> Name;
21842186
getNameWithPrefix(Name, GO, TM);
21852187
return getContext().getXCOFFSection(
2186-
Name, Kind.isBSSLocal() ? XCOFF::XMC_BS : XCOFF::XMC_RW, XCOFF::XTY_CM,
2187-
Kind);
2188+
Name, Kind,
2189+
XCOFF::CsectProperties(
2190+
Kind.isBSSLocal() ? XCOFF::XMC_BS : XCOFF::XMC_RW, XCOFF::XTY_CM));
21882191
}
21892192

21902193
if (Kind.isMergeableCString()) {
@@ -2200,7 +2203,7 @@ MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal(
22002203
getNameWithPrefix(Name, GO, TM);
22012204

22022205
return getContext().getXCOFFSection(
2203-
Name, XCOFF::XMC_RO, XCOFF::XTY_SD, Kind,
2206+
Name, Kind, XCOFF::CsectProperties(XCOFF::XMC_RO, XCOFF::XTY_SD),
22042207
/* MultiSymbolsAllowed*/ !TM.getDataSections());
22052208
}
22062209

@@ -2223,8 +2226,9 @@ MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal(
22232226
if (TM.getDataSections()) {
22242227
SmallString<128> Name;
22252228
getNameWithPrefix(Name, GO, TM);
2226-
return getContext().getXCOFFSection(Name, XCOFF::XMC_RW, XCOFF::XTY_SD,
2227-
SectionKind::getData());
2229+
return getContext().getXCOFFSection(
2230+
Name, SectionKind::getData(),
2231+
XCOFF::CsectProperties(XCOFF::XMC_RW, XCOFF::XTY_SD));
22282232
}
22292233
return DataSection;
22302234
}
@@ -2233,8 +2237,9 @@ MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal(
22332237
if (TM.getDataSections()) {
22342238
SmallString<128> Name;
22352239
getNameWithPrefix(Name, GO, TM);
2236-
return getContext().getXCOFFSection(Name, XCOFF::XMC_RO, XCOFF::XTY_SD,
2237-
SectionKind::getReadOnly());
2240+
return getContext().getXCOFFSection(
2241+
Name, SectionKind::getReadOnly(),
2242+
XCOFF::CsectProperties(XCOFF::XMC_RO, XCOFF::XTY_SD));
22382243
}
22392244
return ReadOnlySection;
22402245
}
@@ -2253,8 +2258,9 @@ MCSection *TargetLoweringObjectFileXCOFF::getSectionForJumpTable(
22532258
// the table doesn't prevent the removal.
22542259
SmallString<128> NameStr(".rodata.jmp..");
22552260
getNameWithPrefix(NameStr, &F, TM);
2256-
return getContext().getXCOFFSection(NameStr, XCOFF::XMC_RO, XCOFF::XTY_SD,
2257-
SectionKind::getReadOnly());
2261+
return getContext().getXCOFFSection(
2262+
NameStr, SectionKind::getReadOnly(),
2263+
XCOFF::CsectProperties(XCOFF::XMC_RO, XCOFF::XTY_SD));
22582264
}
22592265

22602266
bool TargetLoweringObjectFileXCOFF::shouldPutJumpTableInFunctionSection(
@@ -2345,9 +2351,11 @@ MCSymbol *TargetLoweringObjectFileXCOFF::getFunctionEntryPointSymbol(
23452351
Func->isDeclaration()) &&
23462352
isa<Function>(Func)) {
23472353
return getContext()
2348-
.getXCOFFSection(NameStr, XCOFF::XMC_PR,
2349-
Func->isDeclaration() ? XCOFF::XTY_ER : XCOFF::XTY_SD,
2350-
SectionKind::getText())
2354+
.getXCOFFSection(
2355+
NameStr, SectionKind::getText(),
2356+
XCOFF::CsectProperties(XCOFF::XMC_PR, Func->isDeclaration()
2357+
? XCOFF::XTY_ER
2358+
: XCOFF::XTY_SD))
23512359
->getQualNameSymbol();
23522360
}
23532361

@@ -2358,16 +2366,18 @@ MCSection *TargetLoweringObjectFileXCOFF::getSectionForFunctionDescriptor(
23582366
const Function *F, const TargetMachine &TM) const {
23592367
SmallString<128> NameStr;
23602368
getNameWithPrefix(NameStr, F, TM);
2361-
return getContext().getXCOFFSection(NameStr, XCOFF::XMC_DS, XCOFF::XTY_SD,
2362-
SectionKind::getData());
2369+
return getContext().getXCOFFSection(
2370+
NameStr, SectionKind::getData(),
2371+
XCOFF::CsectProperties(XCOFF::XMC_DS, XCOFF::XTY_SD));
23632372
}
23642373

23652374
MCSection *TargetLoweringObjectFileXCOFF::getSectionForTOCEntry(
23662375
const MCSymbol *Sym, const TargetMachine &TM) const {
23672376
// Use TE storage-mapping class when large code model is enabled so that
23682377
// the chance of needing -bbigtoc is decreased.
23692378
return getContext().getXCOFFSection(
2370-
cast<MCSymbolXCOFF>(Sym)->getSymbolTableName(),
2371-
TM.getCodeModel() == CodeModel::Large ? XCOFF::XMC_TE : XCOFF::XMC_TC,
2372-
XCOFF::XTY_SD, SectionKind::getData());
2379+
cast<MCSymbolXCOFF>(Sym)->getSymbolTableName(), SectionKind::getData(),
2380+
XCOFF::CsectProperties(
2381+
TM.getCodeModel() == CodeModel::Large ? XCOFF::XMC_TE : XCOFF::XMC_TC,
2382+
XCOFF::XTY_SD));
23732383
}

llvm/lib/MC/MCContext.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -671,12 +671,14 @@ MCSectionWasm *MCContext::getWasmSection(const Twine &Section, SectionKind Kind,
671671
}
672672

673673
MCSectionXCOFF *
674-
MCContext::getXCOFFSection(StringRef Section, XCOFF::StorageMappingClass SMC,
675-
XCOFF::SymbolType Type, SectionKind Kind,
674+
MCContext::getXCOFFSection(StringRef Section, SectionKind Kind,
675+
Optional<XCOFF::CsectProperties> CsectProp,
676676
bool MultiSymbolsAllowed, const char *BeginSymName) {
677677
// Do the lookup. If we have a hit, return it.
678-
auto IterBool = XCOFFUniquingMap.insert(
679-
std::make_pair(XCOFFSectionKey{Section.str(), SMC}, nullptr));
678+
// FIXME: handle the case for non-csect sections. Non-csect section has None
679+
// CsectProp.
680+
auto IterBool = XCOFFUniquingMap.insert(std::make_pair(
681+
XCOFFSectionKey{Section.str(), CsectProp->MappingClass}, nullptr));
680682
auto &Entry = *IterBool.first;
681683
if (!IterBool.second) {
682684
MCSectionXCOFF *ExistedEntry = Entry.second;
@@ -689,17 +691,18 @@ MCContext::getXCOFFSection(StringRef Section, XCOFF::StorageMappingClass SMC,
689691
// Otherwise, return a new section.
690692
StringRef CachedName = Entry.first.SectionName;
691693
MCSymbolXCOFF *QualName = cast<MCSymbolXCOFF>(getOrCreateSymbol(
692-
CachedName + "[" + XCOFF::getMappingClassString(SMC) + "]"));
694+
CachedName + "[" + XCOFF::getMappingClassString(CsectProp->MappingClass) +
695+
"]"));
693696

694697
MCSymbol *Begin = nullptr;
695698
if (BeginSymName)
696699
Begin = createTempSymbol(BeginSymName, false);
697700

698701
// QualName->getUnqualifiedName() and CachedName are the same except when
699702
// CachedName contains invalid character(s) such as '$' for an XCOFF symbol.
700-
MCSectionXCOFF *Result = new (XCOFFAllocator.Allocate())
701-
MCSectionXCOFF(QualName->getUnqualifiedName(), SMC, Type, Kind, QualName,
702-
Begin, CachedName, MultiSymbolsAllowed);
703+
MCSectionXCOFF *Result = new (XCOFFAllocator.Allocate()) MCSectionXCOFF(
704+
QualName->getUnqualifiedName(), CsectProp->MappingClass, CsectProp->Type,
705+
Kind, QualName, Begin, CachedName, MultiSymbolsAllowed);
703706
Entry.second = Result;
704707

705708
auto *F = new MCDataFragment();

llvm/lib/MC/MCObjectFileInfo.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -874,31 +874,37 @@ void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) {
874874
// the ABI or object file format. For example, the XL compiler uses an unnamed
875875
// csect for program code.
876876
TextSection = Ctx->getXCOFFSection(
877-
".text", XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD,
878-
SectionKind::getText(), /* MultiSymbolsAllowed*/ true);
877+
".text", SectionKind::getText(),
878+
XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD),
879+
/* MultiSymbolsAllowed*/ true);
879880

880881
DataSection = Ctx->getXCOFFSection(
881-
".data", XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD,
882-
SectionKind::getData(), /* MultiSymbolsAllowed*/ true);
882+
".data", SectionKind::getData(),
883+
XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD),
884+
/* MultiSymbolsAllowed*/ true);
883885

884886
ReadOnlySection = Ctx->getXCOFFSection(
885-
".rodata", XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD,
886-
SectionKind::getReadOnly(), /* MultiSymbolsAllowed*/ true);
887+
".rodata", SectionKind::getReadOnly(),
888+
XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
889+
/* MultiSymbolsAllowed*/ true);
887890

888-
TOCBaseSection =
889-
Ctx->getXCOFFSection("TOC", XCOFF::StorageMappingClass::XMC_TC0,
890-
XCOFF::XTY_SD, SectionKind::getData());
891+
TOCBaseSection = Ctx->getXCOFFSection(
892+
"TOC", SectionKind::getData(),
893+
XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TC0,
894+
XCOFF::XTY_SD));
891895

892896
// The TOC-base always has 0 size, but 4 byte alignment.
893897
TOCBaseSection->setAlignment(Align(4));
894898

895-
LSDASection = Ctx->getXCOFFSection(".gcc_except_table",
896-
XCOFF::StorageMappingClass::XMC_RO,
897-
XCOFF::XTY_SD, SectionKind::getReadOnly());
899+
LSDASection = Ctx->getXCOFFSection(
900+
".gcc_except_table", SectionKind::getReadOnly(),
901+
XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO,
902+
XCOFF::XTY_SD));
898903

899-
CompactUnwindSection =
900-
Ctx->getXCOFFSection(".eh_info_table", XCOFF::StorageMappingClass::XMC_RW,
901-
XCOFF::XTY_SD, SectionKind::getData());
904+
CompactUnwindSection = Ctx->getXCOFFSection(
905+
".eh_info_table", SectionKind::getData(),
906+
XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW,
907+
XCOFF::XTY_SD));
902908

903909
// DWARF sections for XCOFF are not csects. They are special STYP_DWARF
904910
// sections, and the individual DWARF sections are distinguished by their

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5049,8 +5049,8 @@ static SDValue transformCallee(const SDValue &Callee, SelectionDAG &DAG,
50495049
const auto getExternalFunctionEntryPointSymbol = [&](StringRef SymName) {
50505050
auto &Context = DAG.getMachineFunction().getMMI().getContext();
50515051
MCSectionXCOFF *Sec = Context.getXCOFFSection(
5052-
(Twine(".") + Twine(SymName)).str(), XCOFF::XMC_PR, XCOFF::XTY_ER,
5053-
SectionKind::getMetadata());
5052+
(Twine(".") + Twine(SymName)).str(), SectionKind::getMetadata(),
5053+
XCOFF::CsectProperties(XCOFF::XMC_PR, XCOFF::XTY_ER));
50545054
return Sec->getQualNameSymbol();
50555055
};
50565056

0 commit comments

Comments
 (0)