Skip to content

Commit 9d85e62

Browse files
committed
Support relaxation during TLSDESC GD/LD to IE/LE conversion.
Complement https://. When relaxation enable, remove redundant NOPs.
1 parent baee006 commit 9d85e62

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

lld/ELF/Arch/LoongArch.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -966,10 +966,16 @@ static bool relax(Ctx &ctx, InputSection &sec) {
966966
case R_LARCH_GOT_PC_HI20:
967967
case R_LARCH_TLS_GD_PC_HI20:
968968
case R_LARCH_TLS_LD_PC_HI20:
969-
case R_LARCH_TLS_DESC_PC_HI20:
970969
// 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))
973979
relaxPCHi20Lo12(ctx, sec, i, loc, r, relocs[i + 2], remove);
974980
break;
975981
case R_LARCH_CALL36:
@@ -987,6 +993,17 @@ static bool relax(Ctx &ctx, InputSection &sec) {
987993
isUInt<12>(r.sym->getVA(ctx, r.addend)))
988994
remove = 4;
989995
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;
9901007
}
9911008

9921009
// 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 {
12151232
bits);
12161233
relocateNoSym(loc, rel.type, val);
12171234
} 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;
12181239
tlsdescToIe(loc, rel, val);
12191240
}
12201241
continue;
@@ -1231,6 +1252,11 @@ void LoongArch::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
12311252
bits);
12321253
relocateNoSym(loc, rel.type, val);
12331254
} 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;
12341260
tlsdescToLe(loc, rel, val);
12351261
}
12361262
continue;

0 commit comments

Comments
 (0)