Skip to content

Commit 922dde3

Browse files
committed
MCAssembler: Simplify fixup handling
1 parent c9babbc commit 922dde3

File tree

2 files changed

+14
-64
lines changed

2 files changed

+14
-64
lines changed

llvm/lib/MC/MCAssembler.cpp

Lines changed: 14 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -873,69 +873,20 @@ void MCAssembler::layout() {
873873
// Evaluate and apply the fixups, generating relocation entries as necessary.
874874
for (MCSection &Sec : *this) {
875875
for (MCFragment &Frag : Sec) {
876-
MutableArrayRef<MCFixup> Fixups;
877-
MutableArrayRef<char> Contents;
878-
879-
// Process MCAlignFragment and MCEncodedFragmentWithFixups here.
880-
switch (Frag.getKind()) {
881-
default:
882-
continue;
883-
case MCFragment::FT_Align: {
884-
MCAlignFragment &AF = cast<MCAlignFragment>(Frag);
885-
// Insert fixup type for code alignment if the target define
886-
// shouldInsertFixupForCodeAlign target hook.
887-
if (Sec.useCodeAlign() && AF.hasEmitNops())
888-
getBackend().shouldInsertFixupForCodeAlign(*this, AF);
889-
continue;
890-
}
891-
case MCFragment::FT_Data: {
892-
MCDataFragment &DF = cast<MCDataFragment>(Frag);
893-
Fixups = DF.getFixups();
894-
Contents = DF.getContents();
895-
break;
896-
}
897-
case MCFragment::FT_Relaxable: {
898-
MCRelaxableFragment &RF = cast<MCRelaxableFragment>(Frag);
899-
Fixups = RF.getFixups();
900-
Contents = RF.getContents();
901-
break;
902-
}
903-
case MCFragment::FT_CVDefRange: {
904-
MCCVDefRangeFragment &CF = cast<MCCVDefRangeFragment>(Frag);
905-
Fixups = CF.getFixups();
906-
Contents = CF.getContents();
907-
break;
908-
}
909-
case MCFragment::FT_Dwarf: {
910-
MCDwarfLineAddrFragment &DF = cast<MCDwarfLineAddrFragment>(Frag);
911-
Fixups = DF.getFixups();
912-
Contents = DF.getContents();
913-
break;
914-
}
915-
case MCFragment::FT_DwarfFrame: {
916-
MCDwarfCallFrameFragment &DF = cast<MCDwarfCallFrameFragment>(Frag);
917-
Fixups = DF.getFixups();
918-
Contents = DF.getContents();
919-
break;
920-
}
921-
case MCFragment::FT_LEB: {
922-
auto &LF = cast<MCLEBFragment>(Frag);
923-
Fixups = LF.getFixups();
924-
Contents = LF.getContents();
925-
break;
926-
}
927-
case MCFragment::FT_PseudoProbe: {
928-
MCPseudoProbeAddrFragment &PF = cast<MCPseudoProbeAddrFragment>(Frag);
929-
Fixups = PF.getFixups();
930-
Contents = PF.getContents();
931-
break;
932-
}
933-
}
934-
for (const MCFixup &Fixup : Fixups) {
935-
uint64_t FixedValue;
936-
MCValue Target;
937-
evaluateFixup(Frag, Fixup, Target, FixedValue,
938-
/*RecordReloc=*/true, Contents);
876+
// Process fragments with fixups here.
877+
if (auto *F = dyn_cast<MCEncodedFragment>(&Frag)) {
878+
auto Contents = F->getContents();
879+
for (const MCFixup &Fixup : F->getFixups()) {
880+
uint64_t FixedValue;
881+
MCValue Target;
882+
evaluateFixup(Frag, Fixup, Target, FixedValue,
883+
/*RecordReloc=*/true, Contents);
884+
}
885+
} else if (auto *AF = dyn_cast<MCAlignFragment>(&Frag)) {
886+
// For RISC-V linker relaxation, an alignment relocation might be
887+
// needed.
888+
if (AF->hasEmitNops())
889+
getBackend().shouldInsertFixupForCodeAlign(*this, *AF);
939890
}
940891
}
941892
}

llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,6 @@ bool RISCVAsmBackend::shouldInsertFixupForCodeAlign(MCAssembler &Asm,
885885

886886
MCContext &Ctx = getContext();
887887
const MCExpr *Dummy = MCConstantExpr::create(0, Ctx);
888-
// Create fixup_riscv_align fixup.
889888
MCFixup Fixup = MCFixup::create(0, Dummy, ELF::R_RISCV_ALIGN, SMLoc());
890889

891890
uint64_t FixedValue = 0;

0 commit comments

Comments
 (0)