Repository navigation
wasm: a load or a store through a function's address, left by speculative direct calls, is dropped - #814
Merged
Conversation
…tive direct calls, is dropped SpeculativeDirectCallPass tests a function value against every function of its type and inlines each under its test. In a test the program never passes (IntIter's loop asking "is it foo3's `next`?"), the optimizer, knowing the pointer is the function, turned what the inlined body reads through its `this` into a read of the function's own address. Natively that is a read nobody makes; on wasm, where code is not in the linear memory, it is a relocation the linker cannot resolve - wasm-ld: "invalid data relocation" for a generator's `next` (seen on wasm64, and possible on wasm32). After the optimization pipeline, for wasm, such a load gives poison and such a store is dropped: either is undefined anyway. 00generator3, 01iterator and 00owned_generator_locals now run on wasm64. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes wasm-ld's "invalid data relocation" error for a generator's
nexton wasm64. It only appeared in optimized builds (--opt).What went wrong
SpeculativeDirectCallPasschecks a function pointer against every function of the same type, and inlines each one behind its own check.IntIteralso gets a check forfoo3'snext. That check never succeeds at run time.foo3'snext. So what the inlined body reads throughthisbecomes a read of the function's own address:load ptr, ptr @...next.The fix (
transform.cpp,WasmFunctionDataAccessPass)poison, and such a store is dropped. Either access is undefined anyway.changeToUnreachablewould also be correct, but it crashed the compiler on 00owned_generator_locals, so the pass usespoisoninstead.Tests
wasm_skips.txt. They now run on wasm64.🤖 Generated with Claude Code