[llvm] [lldb][LoongArch] Fix expression function call failure (PR #136563)

via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 21 20:22:46 PDT 2025


https://github.com/wangleiat updated https://github.com/llvm/llvm-project/pull/136563

>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 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=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) {

>From e40baf4d1577e8dcc69790b03074bf6523f74260 Mon Sep 17 00:00:00 2001
From: wanglei <wanglei at loongson.cn>
Date: Tue, 22 Apr 2025 11:22:37 +0800
Subject: [PATCH 2/2] Address SixWeining's comments

Created using spr 1.3.5-bogner
---
 llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
index ad80d1ca6bf40..cca99591c8c45 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
@@ -662,16 +662,18 @@ bool RuntimeDyldELF::resolveLoongArch64ShortBranch(
   }
   uint64_t Offset = RelI->getOffset();
   uint64_t SourceAddress = Sections[SectionID].getLoadAddressWithOffset(Offset);
+  uint64_t Delta = Address + Value.Addend - SourceAddress;
   // Normal call
   if (RelI->getType() == ELF::R_LARCH_B26) {
-    if (!isInt<28>(Address + Value.Addend - SourceAddress))
+    if (!isInt<28>(Delta))
       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))
+  // Range: [-128G - 0x20000, +128G - 0x20000)
+  if (((int64_t)Delta + 0x20000) != llvm::SignExtend64(Delta + 0x20000, 38))
     return false;
   resolveRelocation(Sections[SectionID], Offset, Address, RelI->getType(),
                     Value.Addend);



More information about the llvm-commits mailing list