arm64: account for imported functions when encoding relocation islands #2346
+34
−9
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 #2340
Thanks @davidmdm for reporting the issue. Please do confirm if this solves your problem!
Here's a summary for the lazy. On arm64, when we compute the offsets in a trampoline, the following function is given a mapping between all function refs (basically Indexes in the original Wasm file) and offsets (
refToBinaryOffset
).Wasm function indexes account for all functions, including imported functions. However, we do not need to allocate space for such functions in the "trampoline island". In fact, we do not account for them:
however:
if we write out of the expected bounds, we end up overwriting the beginning of the function that follows that island. This causes all kind of wacky behavior, because when you invoke that function, it starts with some jumps to "random" places.
The fix is relatively simple, and it can be rewritten in a few ways. Essentially, we need to account for the imported functions, and ignore those indexes when we write the island.