codegen: safety fallback + entry-slice boundary fix for truncated functions (#86)#109
Closed
jlsandri wants to merge 1 commit intoran-j:mainfrom
Closed
codegen: safety fallback + entry-slice boundary fix for truncated functions (#86)#109jlsandri wants to merge 1 commit intoran-j:mainfrom
jlsandri wants to merge 1 commit intoran-j:mainfrom
Conversation
…y fix Two fixes for functions that end without jr $ra (issue ran-j#86): 1. code_generator.cpp: Emit implicit `ctx->pc = GPR_U32(ctx, 31); return;` at end of every generated function. For correct functions this is unreachable dead code. For functions with wrong TOML/CSV boundaries, it returns via $ra instead of leaving ctx->pc in a bad state that cascades returns up the entire call chain. 2. ps2_recompiler.cpp: When reslicing entry functions, skip boundary starts that fall inside the containing parent function. Ghidra sub-functions (sub_xxx) inside a parent were creating false boundaries that truncated sibling entry slices before their jr $ra.
fcc74e6 to
2584583
Compare
Author
|
Closing as part of a batch cleanup after #107 landed. The runtime ecosystem refactor in #107 substantially reworked the files this PR touched, and I would like to re-audit the underlying fix against the new code structure before putting it back in front of you. If the fix is still needed after that re-audit, I will re-open as a focused PR rebased onto current main. Thanks for your patience. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #86. Two small, independent fixes for functions whose last instruction is not
jr \$ra— either because the source really lacks a tail return, or because the imported function boundary is wrong and the realjr \$ralives past the reported end.Fix 1 — Implicit safety fallback at function end (
code_generator.cpp)Emit an implicit
at the end of every generated function body.
jr \$raalready returned).\$rainstead of leavingctx->pcat whatever value the last fall-through instruction set, which previously caused cascading wrong returns up the call chain.Fix 2 — Skip boundary starts inside a containing parent (
ps2_recompiler.cpp)When reslicing entry functions, skip any boundary start that falls inside the range of the containing parent function.
Ghidra-style
sub_xxxchildren inside a parent were creating "boundary" entries that truncated sibling entry slices before theirjr \$ra, producing half-functions that would fall off the end at runtime.Scope
ps2xRecomp/src/lib/code_generator.cpp: +6 / -0ps2xRecomp/src/lib/ps2_recompiler.cpp: +13 / -1