@@ -143,8 +143,6 @@ static void fixupLeb128(MCContext &Ctx, const MCFixup &Fixup, uint8_t *Data,
143143void LoongArchAsmBackend::applyFixup (const MCFragment &F, const MCFixup &Fixup,
144144 const MCValue &Target, uint8_t *Data,
145145 uint64_t Value, bool IsResolved) {
146- if (IsResolved && shouldForceRelocation (Fixup, Target))
147- IsResolved = false ;
148146 IsResolved = addReloc (F, Fixup, Target, Value, IsResolved);
149147 if (!Value)
150148 return ; // Doesn't change encoding.
@@ -176,20 +174,6 @@ void LoongArchAsmBackend::applyFixup(const MCFragment &F, const MCFixup &Fixup,
176174 }
177175}
178176
179- bool LoongArchAsmBackend::shouldForceRelocation (const MCFixup &Fixup,
180- const MCValue &Target) {
181- switch (Fixup.getKind ()) {
182- default :
183- return STI.hasFeature (LoongArch::FeatureRelax);
184- case FK_Data_1:
185- case FK_Data_2:
186- case FK_Data_4:
187- case FK_Data_8:
188- case FK_Data_leb128:
189- return !Target.isAbsolute ();
190- }
191- }
192-
193177static inline std::pair<MCFixupKind, MCFixupKind>
194178getRelocPairForSize (unsigned Size) {
195179 switch (Size) {
@@ -484,9 +468,16 @@ bool LoongArchAsmBackend::addReloc(const MCFragment &F, const MCFixup &Fixup,
484468 return false ;
485469 }
486470
487- IsResolved = Fallback ();
488471 // If linker relaxation is enabled and supported by the current relocation,
489- // append a RELAX relocation.
472+ // generate a relocation and then append a RELAX.
473+ if (Fixup.isLinkerRelaxable ())
474+ IsResolved = false ;
475+ if (IsResolved && Fixup.isPCRel ())
476+ IsResolved = isPCRelFixupResolved (Target.getAddSym (), F);
477+
478+ if (!IsResolved)
479+ Asm->getWriter ().recordRelocation (F, Fixup, Target, FixedValue);
480+
490481 if (Fixup.isLinkerRelaxable ()) {
491482 auto FA = MCFixup::create (Fixup.getOffset (), nullptr , ELF::R_LARCH_RELAX);
492483 Asm->getWriter ().recordRelocation (F, FA, MCValue::get (nullptr ),
0 commit comments