Skip to content

Commit 91edbe2

Browse files
authored
[lldb][LoongArch] Fix expression function call failure
After upgrading the default code model from small to medium on LoongArch, function calls using expression may fail. This is because the function call instruction has changed from `bl` to `pcalau18i + jirl`, but `RuntimeDyld` does not handle out-of-range jumps for this instruction sequence. This patch fixes: #136561 Reviewed By: SixWeining Pull Request: #136563
1 parent d0cd6f3 commit 91edbe2

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,18 @@ bool RuntimeDyldELF::resolveLoongArch64ShortBranch(
662662
}
663663
uint64_t Offset = RelI->getOffset();
664664
uint64_t SourceAddress = Sections[SectionID].getLoadAddressWithOffset(Offset);
665-
if (!isInt<28>(Address + Value.Addend - SourceAddress))
665+
uint64_t Delta = Address + Value.Addend - SourceAddress;
666+
// Normal call
667+
if (RelI->getType() == ELF::R_LARCH_B26) {
668+
if (!isInt<28>(Delta))
669+
return false;
670+
resolveRelocation(Sections[SectionID], Offset, Address, RelI->getType(),
671+
Value.Addend);
672+
return true;
673+
}
674+
// Medium call: R_LARCH_CALL36
675+
// Range: [-128G - 0x20000, +128G - 0x20000)
676+
if (((int64_t)Delta + 0x20000) != llvm::SignExtend64(Delta + 0x20000, 38))
666677
return false;
667678
resolveRelocation(Sections[SectionID], Offset, Address, RelI->getType(),
668679
Value.Addend);
@@ -1743,7 +1754,8 @@ RuntimeDyldELF::processRelocationRef(
17431754
processSimpleRelocation(SectionID, Offset, RelType, Value);
17441755
}
17451756
} else if (Arch == Triple::loongarch64) {
1746-
if (RelType == ELF::R_LARCH_B26 && MemMgr.allowStubAllocation()) {
1757+
if ((RelType == ELF::R_LARCH_B26 || RelType == ELF::R_LARCH_CALL36) &&
1758+
MemMgr.allowStubAllocation()) {
17471759
resolveLoongArch64Branch(SectionID, Value, RelI, Stubs);
17481760
} else if (RelType == ELF::R_LARCH_GOT_PC_HI20 ||
17491761
RelType == ELF::R_LARCH_GOT_PC_LO12) {

0 commit comments

Comments
 (0)