Skip to content

[MC] Replace MCContext::GenericSectionID with MCSection::NonUniqueID #126202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions llvm/include/llvm/MC/MCContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,6 @@ class MCContext {
/// \name Section Management
/// @{

enum : unsigned {
/// Pass this value as the UniqueID during section creation to get the
/// generic section with the given name and characteristics. The usual
/// sections such as .text use this ID.
GenericSectionID = ~0U
};

/// Return the MCSection for the specified mach-o section. This requires
/// the operands to be valid.
MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
Expand Down Expand Up @@ -611,7 +604,7 @@ class MCContext {

MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
StringRef COMDATSymName, int Selection,
unsigned UniqueID = GenericSectionID);
unsigned UniqueID = MCSection::NonUniqueID);

MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics);

Expand All @@ -621,7 +614,7 @@ class MCContext {
/// as Sec and the function symbol as KeySym.
MCSectionCOFF *
getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym,
unsigned UniqueID = GenericSectionID);
unsigned UniqueID = MCSection::NonUniqueID);

MCSectionSPIRV *getSPIRVSection();

Expand Down
22 changes: 11 additions & 11 deletions llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
if (!SupportsUnique) {
Flags &= ~ELF::SHF_MERGE;
EntrySize = 0;
return MCContext::GenericSectionID;
return MCSection::NonUniqueID;
}

const bool SymbolMergeable = Flags & ELF::SHF_MERGE;
Expand All @@ -770,16 +770,16 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
if (TM.getSeparateNamedSections())
return NextUniqueID++;
else
return MCContext::GenericSectionID;
return MCSection::NonUniqueID;
}

// Symbols must be placed into sections with compatible entry sizes. Generate
// unique sections for symbols that have not been assigned to compatible
// sections.
const auto PreviousID =
Ctx.getELFUniqueIDForEntsize(SectionName, Flags, EntrySize);
if (PreviousID && (!TM.getSeparateNamedSections() ||
*PreviousID == MCContext::GenericSectionID))
if (PreviousID &&
(!TM.getSeparateNamedSections() || *PreviousID == MCSection::NonUniqueID))
return *PreviousID;

// If the user has specified the same section name as would be created
Expand All @@ -791,7 +791,7 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
if (SymbolMergeable &&
Ctx.isELFImplicitMergeableSectionNamePrefix(SectionName) &&
SectionName.starts_with(ImplicitSectionNameStem))
return MCContext::GenericSectionID;
return MCSection::NonUniqueID;

// We have seen this section name before, but with different flags or entity
// size. Create a new unique ID.
Expand Down Expand Up @@ -903,7 +903,7 @@ static MCSectionELF *selectELFSectionForGlobal(
unsigned EntrySize = getEntrySizeForKind(Kind);

bool UniqueSectionName = false;
unsigned UniqueID = MCContext::GenericSectionID;
unsigned UniqueID = MCSection::NonUniqueID;
if (EmitUniqueSection) {
if (TM.getUniqueSectionNames()) {
UniqueSectionName = true;
Expand Down Expand Up @@ -1073,7 +1073,7 @@ MCSection *TargetLoweringObjectFileELF::getSectionForMachineBasicBlock(
const Function &F, const MachineBasicBlock &MBB,
const TargetMachine &TM) const {
assert(MBB.isBeginSection() && "Basic block does not start a section!");
unsigned UniqueID = MCContext::GenericSectionID;
unsigned UniqueID = MCSection::NonUniqueID;

// For cold sections use the .text.split. prefix along with the parent
// function name. All cold blocks for the same function go to the same
Expand Down Expand Up @@ -1774,7 +1774,7 @@ MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal(
else
ComdatGV = GO;

unsigned UniqueID = MCContext::GenericSectionID;
unsigned UniqueID = MCSection::NonUniqueID;
if (EmitUniquedSection)
UniqueID = NextUniqueID++;

Expand Down Expand Up @@ -2220,8 +2220,8 @@ MCSection *TargetLoweringObjectFileWasm::getExplicitSectionGlobal(
}

unsigned Flags = getWasmSectionFlags(Kind, Used.count(GO));
MCSectionWasm *Section = getContext().getWasmSection(
Name, Kind, Flags, Group, MCContext::GenericSectionID);
MCSectionWasm *Section = getContext().getWasmSection(Name, Kind, Flags, Group,
MCSection::NonUniqueID);

return Section;
}
Expand Down Expand Up @@ -2249,7 +2249,7 @@ selectWasmSectionForGlobal(MCContext &Ctx, const GlobalObject *GO,
Name.push_back('.');
TM.getNameWithPrefix(Name, GO, Mang, true);
}
unsigned UniqueID = MCContext::GenericSectionID;
unsigned UniqueID = MCSection::NonUniqueID;
if (EmitUniqueSection && !UniqueSectionNames) {
UniqueID = *NextUniqueID;
(*NextUniqueID)++;
Expand Down
7 changes: 4 additions & 3 deletions llvm/lib/MC/MCContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ void MCContext::recordELFMergeableSectionInfo(StringRef SectionName,
unsigned Flags, unsigned UniqueID,
unsigned EntrySize) {
bool IsMergeable = Flags & ELF::SHF_MERGE;
if (UniqueID == GenericSectionID) {
if (UniqueID == MCSection::NonUniqueID) {
ELFSeenGenericMergeableSections.insert(SectionName);
// Minor performance optimization: avoid hash map lookup in
// isELFGenericMergeableSection, which will return true for SectionName.
Expand Down Expand Up @@ -727,14 +727,15 @@ MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,

MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
unsigned Characteristics) {
return getCOFFSection(Section, Characteristics, "", 0, GenericSectionID);
return getCOFFSection(Section, Characteristics, "", 0,
MCSection::NonUniqueID);
}

MCSectionCOFF *MCContext::getAssociativeCOFFSection(MCSectionCOFF *Sec,
const MCSymbol *KeySym,
unsigned UniqueID) {
// Return the normal section if we don't have to be associative or unique.
if (!KeySym && UniqueID == GenericSectionID)
if (!KeySym && UniqueID == MCSection::NonUniqueID)
return Sec;

// If we have a key symbol, make an associative section with the same name and
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/MC/MCObjectFileInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,
utostr(Hash), /*IsComdat=*/true);
case Triple::Wasm:
return Ctx->getWasmSection(Name, SectionKind::getMetadata(), 0,
utostr(Hash), MCContext::GenericSectionID);
utostr(Hash), MCSection::NonUniqueID);
case Triple::MachO:
case Triple::COFF:
case Triple::GOFF:
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/MC/MCParser/WasmAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class WasmAsmParser : public MCAsmParserExtension {

// TODO: Parse UniqueID
MCSectionWasm *WS = getContext().getWasmSection(
Name, *Kind, Flags, GroupName, MCContext::GenericSectionID);
Name, *Kind, Flags, GroupName, MCSection::NonUniqueID);

if (WS->getSegmentFlags() != Flags)
Parser->Error(loc, "changed section flags for " + Name +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
if (Group)
WasmSym->setComdat(true);
auto *WS = getContext().getWasmSection(SecName, SectionKind::getText(), 0,
Group, MCContext::GenericSectionID);
Group, MCSection::NonUniqueID);
getStreamer().switchSection(WS);
// Also generate DWARF for this section if requested.
if (getContext().getGenDwarfForAssembly())
Expand Down