@@ -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) {
@@ -491,9 +475,16 @@ bool LoongArchAsmBackend::addReloc(const MCFragment &F, const MCFixup &Fixup,
491475 return false ;
492476 }
493477
494- IsResolved = Fallback ();
495478 // If linker relaxation is enabled and supported by the current relocation,
496- // append a RELAX relocation.
479+ // generate a relocation and then append a RELAX.
480+ if (Fixup.isLinkerRelaxable ())
481+ IsResolved = false ;
482+ if (IsResolved && Fixup.isPCRel ())
483+ IsResolved = isPCRelFixupResolved (Target.getAddSym (), F);
484+
485+ if (!IsResolved)
486+ Asm->getWriter ().recordRelocation (F, Fixup, Target, FixedValue);
487+
497488 if (Fixup.isLinkerRelaxable ()) {
498489 auto FA = MCFixup::create (Fixup.getOffset (), nullptr , ELF::R_LARCH_RELAX);
499490 Asm->getWriter ().recordRelocation (F, FA, MCValue::get (nullptr ),
0 commit comments