Skip to content

Commit 2571924

Browse files
committed
MCSectionELF: Remove classof
The object file format specific derived classes are used in context like MCStreamer and MCObjectTargetWriter where the type is statically known. We don't use isa/dyn_cast and we want to eliminate MCSection::SectionVariant in the base class.
1 parent ae5537e commit 2571924

File tree

10 files changed

+21
-26
lines changed

10 files changed

+21
-26
lines changed

llvm/include/llvm/MC/MCSectionELF.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ class MCSectionELF final : public MCSection {
100100
std::pair<uint64_t, uint64_t> getOffsets() const {
101101
return std::make_pair(StartOffset, EndOffset);
102102
}
103-
104-
static bool classof(const MCSection *S) {
105-
return S->getVariant() == SV_ELF;
106-
}
107103
};
108104

109105
} // end namespace llvm

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ MCSection *TargetLoweringObjectFileELF::getSectionForLSDA(
995995
if (!LSDASection || (!F.hasComdat() && !TM.getFunctionSections()))
996996
return LSDASection;
997997

998-
const auto *LSDA = cast<MCSectionELF>(LSDASection);
998+
const auto *LSDA = static_cast<const MCSectionELF *>(LSDASection);
999999
unsigned Flags = LSDA->getFlags();
10001000
const MCSymbolELF *LinkedToSym = nullptr;
10011001
StringRef Group;

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,8 @@ uint64_t ELFWriter::writeObject() {
10871087
// Remember the offset into the file for this section.
10881088
const uint64_t SecStart = align(RelSection->getAlign());
10891089

1090-
writeRelocations(cast<MCSectionELF>(*RelSection->getLinkedToSection()));
1090+
writeRelocations(
1091+
static_cast<const MCSectionELF &>(*RelSection->getLinkedToSection()));
10911092

10921093
uint64_t SecEnd = W.OS.tell();
10931094
RelSection->setOffsets(SecStart, SecEnd);
@@ -1260,7 +1261,7 @@ bool ELFObjectWriter::useSectionSymbol(const MCValue &Val,
12601261
// that it pointed to another string and subtracting 42 at runtime will
12611262
// produce the wrong value.
12621263
if (Sym->isInSection()) {
1263-
auto &Sec = cast<MCSectionELF>(Sym->getSection());
1264+
auto &Sec = static_cast<const MCSectionELF &>(Sym->getSection());
12641265
unsigned Flags = Sec.getFlags();
12651266
if (Flags & ELF::SHF_MERGE) {
12661267
if (C != 0)
@@ -1312,13 +1313,14 @@ bool ELFObjectWriter::checkRelocation(SMLoc Loc, const MCSectionELF *From,
13121313
void ELFObjectWriter::recordRelocation(const MCFragment &F,
13131314
const MCFixup &Fixup, MCValue Target,
13141315
uint64_t &FixedValue) {
1315-
const MCSectionELF &Section = cast<MCSectionELF>(*F.getParent());
1316+
auto &Section = static_cast<const MCSectionELF &>(*F.getParent());
13161317
MCContext &Ctx = getContext();
13171318

13181319
const auto *SymA = cast_or_null<MCSymbolELF>(Target.getAddSym());
1319-
const MCSectionELF *SecA = (SymA && SymA->isInSection())
1320-
? cast<MCSectionELF>(&SymA->getSection())
1321-
: nullptr;
1320+
const MCSectionELF *SecA =
1321+
(SymA && SymA->isInSection())
1322+
? static_cast<const MCSectionELF *>(&SymA->getSection())
1323+
: nullptr;
13221324
if (DwoOS && !checkRelocation(Fixup.getLoc(), &Section, SecA))
13231325
return;
13241326

llvm/lib/MC/MCParser/ELFAsmParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,8 @@ bool ELFAsmParser::parseSectionArguments(bool IsPush, SMLoc loc) {
644644
}
645645

646646
if (UseLastGroup) {
647-
if (const MCSectionELF *Section =
648-
cast_or_null<MCSectionELF>(getStreamer().getCurrentSectionOnly()))
647+
if (auto *Section = static_cast<const MCSectionELF *>(
648+
getStreamer().getCurrentSectionOnly()))
649649
if (const MCSymbol *Group = Section->getGroup()) {
650650
GroupName = Group->getName();
651651
IsComdat = Section->isComdat();

llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx,
3636
// SHF_AARCH64_PURECODE flag set if the "+execute-only" target feature is
3737
// present.
3838
if (TM.getMCSubtargetInfo()->hasFeature(AArch64::FeatureExecuteOnly)) {
39-
auto *Text = cast<MCSectionELF>(TextSection);
39+
auto *Text = static_cast<MCSectionELF *>(TextSection);
4040
Text->setFlags(Text->getFlags() | ELF::SHF_AARCH64_PURECODE);
4141
}
4242
}

llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,8 @@ void AArch64TargetELFStreamer::finish() {
523523
// mark it execute-only if it is empty and there is at least one
524524
// execute-only section in the object.
525525
if (any_of(Asm, [](const MCSection &Sec) {
526-
return cast<MCSectionELF>(Sec).getFlags() & ELF::SHF_AARCH64_PURECODE;
526+
return static_cast<const MCSectionELF &>(Sec).getFlags() &
527+
ELF::SHF_AARCH64_PURECODE;
527528
})) {
528529
auto *Text =
529530
static_cast<MCSectionELF *>(Ctx.getObjectFileInfo()->getTextSection());

llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,8 @@ void ARMTargetELFStreamer::finish() {
11381138
MCContext &Ctx = getContext();
11391139
auto &Asm = getStreamer().getAssembler();
11401140
if (any_of(Asm, [](const MCSection &Sec) {
1141-
return cast<MCSectionELF>(Sec).getFlags() & ELF::SHF_ARM_PURECODE;
1141+
return static_cast<const MCSectionELF &>(Sec).getFlags() &
1142+
ELF::SHF_ARM_PURECODE;
11421143
})) {
11431144
auto *Text =
11441145
static_cast<MCSectionELF *>(Ctx.getObjectFileInfo()->getTextSection());

llvm/lib/Target/AVR/AVRAsmPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ bool AVRAsmPrinter::doFinalization(Module &M) {
260260
continue;
261261
}
262262

263-
auto *Section = cast<MCSectionELF>(TLOF.SectionForGlobal(&GO, TM));
263+
auto *Section = static_cast<MCSectionELF *>(TLOF.SectionForGlobal(&GO, TM));
264264
if (Section->getName().starts_with(".data"))
265265
NeedsCopyData = true;
266266
else if (Section->getName().starts_with(".rodata") && SubTM->hasLPM())

llvm/lib/Target/BPF/BTFDebug.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,10 +1255,8 @@ void BTFDebug::beginFunctionImpl(const MachineFunction *MF) {
12551255
FuncInfo.Label = FuncLabel;
12561256
FuncInfo.TypeId = FuncTypeId;
12571257
if (FuncLabel->isInSection()) {
1258-
MCSection &Section = FuncLabel->getSection();
1259-
const MCSectionELF *SectionELF = dyn_cast<MCSectionELF>(&Section);
1260-
assert(SectionELF && "Null section for Function Label");
1261-
SecNameOff = addString(SectionELF->getName());
1258+
auto &Sec = static_cast<const MCSectionELF &>(FuncLabel->getSection());
1259+
SecNameOff = addString(Sec.getName());
12621260
} else {
12631261
SecNameOff = addString(".text");
12641262
}

llvm/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,8 @@ unsigned BPFELFObjectWriter::getRelocType(const MCFixup &Fixup,
5454
const MCSymbol &Sym = *A;
5555

5656
if (Sym.isDefined()) {
57-
MCSection &Section = Sym.getSection();
58-
const MCSectionELF *SectionELF = dyn_cast<MCSectionELF>(&Section);
59-
assert(SectionELF && "Null section for reloc symbol");
60-
61-
unsigned Flags = SectionELF->getFlags();
57+
auto &Section = static_cast<const MCSectionELF &>(Sym.getSection());
58+
unsigned Flags = Section.getFlags();
6259

6360
if (Sym.isTemporary()) {
6461
// .BTF.ext generates FK_Data_4 relocations for

0 commit comments

Comments
 (0)