Skip to content

Fix swapped arguments in ThreadNewIndirect trampoline#13054

Open
shumbo wants to merge 2 commits intobytecodealliance:mainfrom
shumbo:fix-thread-new-indirect-arg-swap
Open

Fix swapped arguments in ThreadNewIndirect trampoline#13054
shumbo wants to merge 2 commits intobytecodealliance:mainfrom
shumbo:fix-thread-new-indirect-arg-swap

Conversation

@shumbo
Copy link
Copy Markdown
Contributor

@shumbo shumbo commented Apr 11, 2026

Summary

  • Fix argument ordering bug in the ThreadNewIndirect trampoline in crates/cranelift/src/compiler/component.rs where start_func_table_idx and start_func_ty_idx were passed to the host thread_new_indirect libcall in the wrong order
  • The host function signature expects func_ty_id before func_table_idx, but the trampoline pushed them in the opposite order, causing the runtime to resolve functions from the wrong table when multiple tables are in use
  • Add a regression test with two tables that asserts the correct trap when calling thread.new-indirect targeting an empty table

Details

The bug was invisible in the common single-table case where both indices are 0. With multiple tables, the swapped indices cause the runtime to look up a function in the wrong table instead of trapping.

The fix swaps the two params.push calls to match the expected parameter order in the thread_new_indirect host function signature defined in crates/environ/src/component.rs.

@shumbo shumbo requested review from a team as code owners April 11, 2026 06:41
@shumbo shumbo requested review from alexcrichton and removed request for a team April 11, 2026 06:41
@shumbo shumbo force-pushed the fix-thread-new-indirect-arg-swap branch from 4dedf58 to 6162737 Compare April 11, 2026 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant