[llvm] [lldb][LoongArch] Fix expression function call failure (PR #136563)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 21 05:07:04 PDT 2025
https://github.com/wangleiat created https://github.com/llvm/llvm-project/pull/136563
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
>From aeb7ab9e2ae8539f9a94057bbfd2a56d043d06a2 Mon Sep 17 00:00:00 2001
From: wanglei <wanglei at loongson.cn>
Date: Mon, 21 Apr 2025 20:06:42 +0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.5-bogner
---
.../ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
index f032d5cb30f23..ad80d1ca6bf40 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
@@ -662,7 +662,16 @@ bool RuntimeDyldELF::resolveLoongArch64ShortBranch(
}
uint64_t Offset = RelI->getOffset();
uint64_t SourceAddress = Sections[SectionID].getLoadAddressWithOffset(Offset);
- if (!isInt<28>(Address + Value.Addend - SourceAddress))
+ // Normal call
+ if (RelI->getType() == ELF::R_LARCH_B26) {
+ if (!isInt<28>(Address + Value.Addend - SourceAddress))
+ return false;
+ resolveRelocation(Sections[SectionID], Offset, Address, RelI->getType(),
+ Value.Addend);
+ return true;
+ }
+ // Medium call: R_LARCH_CALL36
+ if (!isInt<38>(Address + Value.Addend - SourceAddress))
return false;
resolveRelocation(Sections[SectionID], Offset, Address, RelI->getType(),
Value.Addend);
@@ -1743,7 +1752,8 @@ RuntimeDyldELF::processRelocationRef(
processSimpleRelocation(SectionID, Offset, RelType, Value);
}
} else if (Arch == Triple::loongarch64) {
- if (RelType == ELF::R_LARCH_B26 && MemMgr.allowStubAllocation()) {
+ if ((RelType == ELF::R_LARCH_B26 || RelType == ELF::R_LARCH_CALL36) &&
+ MemMgr.allowStubAllocation()) {
resolveLoongArch64Branch(SectionID, Value, RelI, Stubs);
} else if (RelType == ELF::R_LARCH_GOT_PC_HI20 ||
RelType == ELF::R_LARCH_GOT_PC_LO12) {
More information about the llvm-commits
mailing list