Skip to content

Commit 3f7cf33

Browse files
committed
[lld][LoongArch] Adjust RelExpr after relaxation is applied
1 parent c40c931 commit 3f7cf33

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

lld/ELF/Arch/LoongArch.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ void LoongArch::finalizeRelax(int passes) const {
945945
continue;
946946

947947
// Copy from last location to the current relocated location.
948-
const Relocation &r = rels[i];
948+
Relocation &r = rels[i];
949949
uint64_t size = r.offset - offset;
950950
memcpy(p, old.data() + offset, size);
951951
p += size;
@@ -959,6 +959,8 @@ void LoongArch::finalizeRelax(int passes) const {
959959
case R_LARCH_PCREL20_S2:
960960
skip = 4;
961961
write32le(p, aux.writes[writesIdx++]);
962+
// RelExpr is needed for relocating.
963+
r.expr = r.sym->hasFlag(NEEDS_PLT) ? R_PLT_PC : R_PC;
962964
break;
963965
default:
964966
llvm_unreachable("unsupported type");

lld/ELF/InputSection.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -737,17 +737,6 @@ uint64_t InputSectionBase::getRelocTargetVA(Ctx &ctx, const Relocation &r,
737737
int64_t a = r.addend;
738738
switch (r.expr) {
739739
case R_ABS:
740-
// pcalau12i,addi.[wd] => pcaddi
741-
// With relaxation applied, the relocation type of the third
742-
// reloc entry which corresponds to the addi.[wd] insn is converted
743-
// from R_LARCH_PCALA_LO12 to R_LARCH_PCREL20_S2.
744-
if (r.type == R_LARCH_PCREL20_S2) {
745-
if (r.sym->hasFlag(NEEDS_PLT))
746-
return r.sym->getPltVA(ctx) + a - p;
747-
else
748-
return r.sym->getVA(a) - p;
749-
}
750-
[[fallthrough]];
751740
case R_DTPREL:
752741
case R_RELAX_TLS_LD_TO_LE_ABS:
753742
case R_RELAX_GOT_PC_NOPIC:

0 commit comments

Comments
 (0)