@@ -974,6 +974,11 @@ static bool relax(Ctx &ctx, InputSection &sec) {
974974 if (relaxable (relocs, i))
975975 relaxTlsLe (ctx, sec, i, loc, r, remove);
976976 break ;
977+ case R_LARCH_TLS_IE_PC_HI20:
978+ if (relaxable (relocs, i) && r.expr == R_RELAX_TLS_IE_TO_LE &&
979+ isUInt<12 >(r.sym ->getVA (ctx, r.addend )))
980+ remove = 4 ;
981+ break ;
977982 }
978983
979984 // For all anchors whose offsets are <= r.offset, they are preceded by
@@ -1048,7 +1053,7 @@ void LoongArch::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
10481053 secAddr += s->outSecOff ;
10491054 else if (auto *ehIn = dyn_cast<EhInputSection>(&sec))
10501055 secAddr += ehIn->getParent ()->outSecOff ;
1051- bool isExtreme = false ;
1056+ bool isExtreme = false , isRelax = false ;
10521057 const MutableArrayRef<Relocation> relocs = sec.relocs ();
10531058 for (size_t i = 0 , size = relocs.size (); i != size; ++i) {
10541059 Relocation &rel = relocs[i];
@@ -1077,6 +1082,9 @@ void LoongArch::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
10771082 bits);
10781083 relocateNoSym (loc, rel.type , val);
10791084 } else {
1085+ isRelax = relaxable (relocs, i);
1086+ if (isRelax && rel.type == R_LARCH_TLS_IE_PC_HI20 && isUInt<12 >(val))
1087+ continue ;
10801088 tlsIeToLe (loc, rel, val);
10811089 }
10821090 continue ;
0 commit comments