https://github.com/Jade-Marker updated 
https://github.com/llvm/llvm-project/pull/152942

>From 0f460186012b377067d9e6ac58a2446453f5817b Mon Sep 17 00:00:00 2001
From: Jade Marker <[email protected]>
Date: Sun, 10 Aug 2025 22:47:14 +0100
Subject: [PATCH 1/3] Update libunwind::Registers_mips_o32::jumpto to allow for
 load delay

Fix #152922
---
 libunwind/src/UnwindRegistersRestore.S | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/libunwind/src/UnwindRegistersRestore.S 
b/libunwind/src/UnwindRegistersRestore.S
index 5e199188945df..346d1d5fb5d8f 100644
--- a/libunwind/src/UnwindRegistersRestore.S
+++ b/libunwind/src/UnwindRegistersRestore.S
@@ -1044,9 +1044,10 @@ 
DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind18Registers_mips_o326jumptoEv)
   lw    $27, (4 * 27)($4)
   lw    $28, (4 * 28)($4)
   lw    $29, (4 * 29)($4)
-  lw    $30, (4 * 30)($4)
   // load new pc into ra
   lw    $31, (4 * 32)($4)
+  //allow for load delay, so that ra address is new value when jumping
+  lw    $30, (4 * 30)($4)
   // jump to ra, load a0 in the delay slot
   jr    $31
   lw    $4, (4 * 4)($4)
@@ -1082,11 +1083,13 @@ 
DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind21Registers_mips_newabi6jumptoEv)
   ld    $2, (8 * 2)($4)
   ld    $3, (8 * 3)($4)
   // skip a0 for now
-  .irp 
i,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30
+  .irp i,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29
     ld $\i, (8 * \i)($4)
   .endr
   // load new pc into ra
-  ld    $31, (8 * 32)($4)
+  lw    $31, (4 * 32)($4)
+  //allow for load delay, so that ra address is new value when jumping
+  lw    $30, (4 * 30)($4)
   // jump to ra, load a0 in the delay slot
   jr    $31
   ld    $4, (8 * 4)($4)

>From 9c089f5f227c1fb40486613d77a7b89b89038874 Mon Sep 17 00:00:00 2001
From: Jade Marker <[email protected]>
Date: Sun, 10 Aug 2025 22:54:02 +0100
Subject: [PATCH 2/3] Update UnwindRegistersRestore.S

Previously, I accidently put lw instead of ld on the mips64 code. Fixed now
---
 libunwind/src/UnwindRegistersRestore.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libunwind/src/UnwindRegistersRestore.S 
b/libunwind/src/UnwindRegistersRestore.S
index 346d1d5fb5d8f..2b1593b16754e 100644
--- a/libunwind/src/UnwindRegistersRestore.S
+++ b/libunwind/src/UnwindRegistersRestore.S
@@ -1087,9 +1087,9 @@ 
DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind21Registers_mips_newabi6jumptoEv)
     ld $\i, (8 * \i)($4)
   .endr
   // load new pc into ra
-  lw    $31, (4 * 32)($4)
+  ld    $31, (4 * 32)($4)
   //allow for load delay, so that ra address is new value when jumping
-  lw    $30, (4 * 30)($4)
+  ld    $30, (4 * 30)($4)
   // jump to ra, load a0 in the delay slot
   jr    $31
   ld    $4, (8 * 4)($4)

>From 8273a07fae8e0708b853f7efe1d22a2daa1913bc Mon Sep 17 00:00:00 2001
From: Jade Marker <[email protected]>
Date: Wed, 24 Sep 2025 04:24:49 +0100
Subject: [PATCH 3/3] Suggested changes

---
 libunwind/src/UnwindRegistersRestore.S | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libunwind/src/UnwindRegistersRestore.S 
b/libunwind/src/UnwindRegistersRestore.S
index 2b1593b16754e..1bcd205be260d 100644
--- a/libunwind/src/UnwindRegistersRestore.S
+++ b/libunwind/src/UnwindRegistersRestore.S
@@ -1046,7 +1046,7 @@ 
DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind18Registers_mips_o326jumptoEv)
   lw    $29, (4 * 29)($4)
   // load new pc into ra
   lw    $31, (4 * 32)($4)
-  //allow for load delay, so that ra address is new value when jumping
+  // MIPS 1 has load delay slot. Ensure lw $31 and jr are separated by an 
instruction.
   lw    $30, (4 * 30)($4)
   // jump to ra, load a0 in the delay slot
   jr    $31
@@ -1087,9 +1087,9 @@ 
DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind21Registers_mips_newabi6jumptoEv)
     ld $\i, (8 * \i)($4)
   .endr
   // load new pc into ra
-  ld    $31, (4 * 32)($4)
-  //allow for load delay, so that ra address is new value when jumping
-  ld    $30, (4 * 30)($4)
+  ld    $31, (8 * 32)($4)
+  // MIPS 1 has load delay slot. Ensure lw $31 and jr are separated by an 
instruction.
+  ld    $30, (8 * 30)($4)
   // jump to ra, load a0 in the delay slot
   jr    $31
   ld    $4, (8 * 4)($4)

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to