@@ -965,10 +965,16 @@ static bool relax(Ctx &ctx, InputSection &sec) {
965
965
case R_LARCH_GOT_PC_HI20:
966
966
case R_LARCH_TLS_GD_PC_HI20:
967
967
case R_LARCH_TLS_LD_PC_HI20:
968
- case R_LARCH_TLS_DESC_PC_HI20:
969
968
// The overflow check for i+2 will be carried out in isPairRelaxable.
970
- if (r.expr != RE_LOONGARCH_RELAX_TLS_GD_TO_IE_PAGE_PC &&
971
- r.expr != R_RELAX_TLS_GD_TO_LE && isPairRelaxable (relocs, i))
969
+ if (isPairRelaxable (relocs, i))
970
+ relaxPCHi20Lo12 (ctx, sec, i, loc, r, relocs[i + 2 ], remove );
971
+ break ;
972
+ case R_LARCH_TLS_DESC_PC_HI20:
973
+ if (r.expr == RE_LOONGARCH_RELAX_TLS_GD_TO_IE_PAGE_PC ||
974
+ r.expr == R_RELAX_TLS_GD_TO_LE) {
975
+ if (relaxable (relocs, i))
976
+ remove = 4 ;
977
+ } else if (isPairRelaxable (relocs, i))
972
978
relaxPCHi20Lo12 (ctx, sec, i, loc, r, relocs[i + 2 ], remove );
973
979
break ;
974
980
case R_LARCH_CALL36:
@@ -986,6 +992,17 @@ static bool relax(Ctx &ctx, InputSection &sec) {
986
992
isUInt<12 >(r.sym ->getVA (ctx, r.addend )))
987
993
remove = 4 ;
988
994
break ;
995
+ case R_LARCH_TLS_DESC_PC_LO12:
996
+ if (relaxable (relocs, i) &&
997
+ (r.expr == RE_LOONGARCH_RELAX_TLS_GD_TO_IE_PAGE_PC ||
998
+ r.expr == R_RELAX_TLS_GD_TO_LE))
999
+ remove = 4 ;
1000
+ break ;
1001
+ case R_LARCH_TLS_DESC_LD:
1002
+ if (relaxable (relocs, i) && r.expr == R_RELAX_TLS_GD_TO_LE &&
1003
+ isUInt<12 >(r.sym ->getVA (ctx, r.addend )))
1004
+ remove = 4 ;
1005
+ break ;
989
1006
}
990
1007
991
1008
// For all anchors whose offsets are <= r.offset, they are preceded by
@@ -1214,6 +1231,10 @@ void LoongArch::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
1214
1231
bits);
1215
1232
relocateNoSym (loc, rel.type , val);
1216
1233
} else {
1234
+ isRelax = relaxable (relocs, i);
1235
+ if (isRelax && (rel.type == R_LARCH_TLS_DESC_PC_HI20 ||
1236
+ rel.type == R_LARCH_TLS_DESC_PC_LO12))
1237
+ continue ;
1217
1238
tlsdescToIe (loc, rel, val);
1218
1239
}
1219
1240
continue ;
@@ -1230,6 +1251,11 @@ void LoongArch::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
1230
1251
bits);
1231
1252
relocateNoSym (loc, rel.type , val);
1232
1253
} else {
1254
+ isRelax = relaxable (relocs, i);
1255
+ if (isRelax && (rel.type == R_LARCH_TLS_DESC_PC_HI20 ||
1256
+ rel.type == R_LARCH_TLS_DESC_PC_LO12 ||
1257
+ (rel.type == R_LARCH_TLS_DESC_LD && isUInt<12 >(val))))
1258
+ continue ;
1233
1259
tlsdescToLe (loc, rel, val);
1234
1260
}
1235
1261
continue ;
0 commit comments