summaryrefslogtreecommitdiff
path: root/yjit/src
diff options
context:
space:
mode:
authorAlan Wu <[email protected]>2024-04-22 11:16:46 -0400
committerGitHub <[email protected]>2024-04-22 11:16:46 -0400
commit1bb7638e7a864db9b635c5d41f18653e8451dbc7 (patch)
treeaf4691ec83a265ee1aee689a082e305ccc20b44c /yjit/src
parentaa5b53d232c36d9b0c73336fc112d8fb20145d18 (diff)
YJIT: Fix shrinking block with assumption too much (#10585)
* YJIT: Fix shrinking block with assumption too much Under the very specific circumstances, discovered by a test case in `ruby/spec`, an `expandarray` block can contain just a branch and carry a method lookup assumption. Previously, when we regenerated the branch, we allowed it to shrink to empty, since we put the code at the jump target immediately after it. That was incorrect and caused a crash while the block is invalidated, since that left no room to patch in an exit. When regenerating a branch that makes up a block entirely, and the block could be invalidated, we need to ensure there is room for invalidation. When there is code before the branch, they should act as padding, so we don't need to worry about those cases. * skip on RJIT
Diffstat (limited to 'yjit/src')
-rw-r--r--yjit/src/core.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/yjit/src/core.rs b/yjit/src/core.rs
index fb7d52cc5d..4152eab02c 100644
--- a/yjit/src/core.rs
+++ b/yjit/src/core.rs
@@ -2643,6 +2643,12 @@ fn regenerate_branch(cb: &mut CodeBlock, branch: &Branch) {
branch.get_target_address(1).map(|addr| Target::CodePtr(addr)),
);
+ // If the entire block is the branch and the block could be invalidated,
+ // we need to pad to ensure there is room for invalidation patching.
+ if branch.start_addr == block.start_addr && branch_terminates_block && block.entry_exit.is_some() {
+ asm.pad_inval_patch();
+ }
+
// Rewrite the branch
let old_write_pos = cb.get_write_pos();
let old_dropped_bytes = cb.has_dropped_bytes();