Skip to content

Commit 43397e5

Browse files
committed
LoongArchMCCodeEmitter: Set PCRel at fixup creation
Avoid reliance on the MCAssembler::evaluateFixup workaround that checks MCFixupKindInfo::FKF_IsPCRel. Additionally, standardize how fixups are appended. This helper will facilitate future fixup data structure optimizations.
1 parent b9257a3 commit 43397e5

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ MCFixupKindInfo LoongArchAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
5757
// LoongArchFixupKinds.h.
5858
//
5959
// {name, offset, bits, flags}
60-
{"fixup_loongarch_b16", 10, 16, MCFixupKindInfo::FKF_IsPCRel},
61-
{"fixup_loongarch_b21", 0, 26, MCFixupKindInfo::FKF_IsPCRel},
62-
{"fixup_loongarch_b26", 0, 26, MCFixupKindInfo::FKF_IsPCRel},
60+
{"fixup_loongarch_b16", 10, 16, 0},
61+
{"fixup_loongarch_b21", 0, 26, 0},
62+
{"fixup_loongarch_b26", 0, 26, 0},
6363
{"fixup_loongarch_abs_hi20", 5, 20, 0},
6464
{"fixup_loongarch_abs_lo12", 10, 12, 0},
6565
{"fixup_loongarch_abs64_lo20", 5, 20, 0},

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ class LoongArchMCCodeEmitter : public MCCodeEmitter {
9797
};
9898
} // end namespace
9999

100+
static void addFixup(SmallVectorImpl<MCFixup> &Fixups, uint32_t Offset,
101+
const MCExpr *Value, uint16_t Kind) {
102+
bool PCRel = false;
103+
switch (Kind) {
104+
case LoongArch::fixup_loongarch_b16:
105+
case LoongArch::fixup_loongarch_b21:
106+
case LoongArch::fixup_loongarch_b26:
107+
PCRel = true;
108+
}
109+
Fixups.push_back(MCFixup::create(Offset, Value, Kind, PCRel));
110+
}
111+
100112
unsigned
101113
LoongArchMCCodeEmitter::getMachineOpValue(const MCInst &MI, const MCOperand &MO,
102114
SmallVectorImpl<MCFixup> &Fixups,
@@ -195,7 +207,7 @@ LoongArchMCCodeEmitter::getExprOpValue(const MCInst &MI, const MCOperand &MO,
195207
assert(FixupKind != LoongArch::fixup_loongarch_invalid &&
196208
"Unhandled expression!");
197209

198-
Fixups.push_back(MCFixup::create(0, Expr, MCFixupKind(FixupKind)));
210+
addFixup(Fixups, 0, Expr, FixupKind);
199211
// If linker relaxation is enabled and supported by this relocation, set
200212
// a bit so that if fixup is unresolved, a R_LARCH_RELAX relocation will be
201213
// appended.
@@ -248,7 +260,7 @@ void LoongArchMCCodeEmitter::expandAddTPRel(const MCInst &MI,
248260
"Expected %le_add_r relocation on TP-relative symbol");
249261

250262
// Emit the correct %le_add_r relocation for the symbol.
251-
Fixups.push_back(MCFixup::create(0, Expr, ELF::R_LARCH_TLS_LE_ADD_R));
263+
addFixup(Fixups, 0, Expr, ELF::R_LARCH_TLS_LE_ADD_R);
252264
if (STI.hasFeature(LoongArch::FeatureRelax))
253265
Fixups.back().setLinkerRelaxable();
254266

0 commit comments

Comments
 (0)