Skip to content

[Mips] Fixed libunwind::Registers_mips_o32::jumpto to allow for load delay #152942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Jade-Marker
Copy link

Fix #152922

Note: I'm unsure if this is necessary on mips64, I've added it for good measure though

Previously, I accidently put lw instead of ld on the mips64 code. Fixed now
@Jade-Marker Jade-Marker requested a review from a team as a code owner August 10, 2025 21:54
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Aug 10, 2025

@llvm/pr-subscribers-libunwind

Author: Jade Marker (Jade-Marker)

Changes

Fix #152922

Note: I'm unsure if this is necessary on mips64, I've added it for good measure though


Full diff: https://github.com/llvm/llvm-project/pull/152942.diff

1 Files Affected:

  • (modified) libunwind/src/UnwindRegistersRestore.S (+6-3)
diff --git a/libunwind/src/UnwindRegistersRestore.S b/libunwind/src/UnwindRegistersRestore.S
index 5e199188945df..2b1593b16754e 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)
+  ld    $31, (4 * 32)($4)
+  //allow for load delay, so that ra address is new value when jumping
+  ld    $30, (4 * 30)($4)
   // jump to ra, load a0 in the delay slot
   jr    $31
   ld    $4, (8 * 4)($4)

@brad0
Copy link
Contributor

brad0 commented Aug 11, 2025

cc @yingopq @wzssyqa @MaskRay

Copy link

⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo.
Please turn off Keep my email addresses private setting in your account.
See LLVM Developer Policy and LLVM Discourse for more information.

Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this for PlayStation (MIPS 1)? Have you tested this patch?
I see that https://reviews.llvm.org/D122427 (2022) added some load delay slot support.

// load new pc into ra
lw $31, (4 * 32)($4)
//allow for load delay, so that ra address is new value when jumping
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest:

// MIPS 1 has load delay slot. Ensure lw $31 and jr are separated by an instruction.

@Jade-Marker
Copy link
Author

It is for the PS1, yes. I haven't tried that patch, however looking over it it doesn't seem to edit the libunwind function in UnwindRegistersRestore.S. Is the assembly in this file handled via code generation? Or is the code gen mentioned in that patch unrelated to libunwind?

Copy link
Author

@Jade-Marker Jade-Marker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new comment is much clearer than what I originally wrote!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

libunwind::Registers_mips_o32::jumpto returns to the wrong address
4 participants