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