-
Notifications
You must be signed in to change notification settings - Fork 147
disasm: fix incorrect stack depth for end/discard #52
base: master
Are you sure you want to change the base?
Conversation
End/Discard ops were being misencoded with incorrect stack depths which caused stack underflows that manifested as slice index out of bounds runtime panics.
@bkeroackdsc thanks for taking a stab at it! I must admit, I am also a bit lagging with the complete understanding of this piece of code. |
Sorry for not replying, as I've been a little busy with classes. I'll try my best to address this issue in the coming weeks. If you take a look at the comment above your change, the reason why we subtract 0 is to get the parent block of the target branch, which is what we want to unwind to. |
ping @vibhavp ? |
@sbinet and @vibhavp any update on this? I am trying to run a function in a wasm file that looks like this in wat:
The disassemble code tries to do an OpDiscard at the end with a stack of length 0 and gets a "slice bounds out of range", but making the change in this pull request fixed it for me. |
Does the PR still break the tests Sebastian was talking about? |
Yes it looks like it still fails some of the
I haven't has a chance yet to dig into why it fails these tests or what a true solution to this should be. |
After further investigation I found that the problem was in my FunctionIndexSpace for 2 native functions that I added. I was using the wrong signature ParamTypes (ValueTypeI64 instead of ValueTypeI32) compared to what the reflected function was expecting. Once I made the fix everything appears to be working as expected without including this pull request. Also using the provided wagon-test.wasm I was able to execute the exported function with no problem: @bkeroackdsc If this is still giving you an error could you provide some of the test code you are using? Otherwise, do you think this pull request be closed? |
End/Discard ops were being misencoded with incorrect stack depths which caused stack underflows that manifested as
vm.ctx.stack
slice index out of bounds runtime panics.Test case wasm (execute the exported function
_ZN4enol4InitEv
)I'm not 100% familiar with the code in question, so please check if this is the correct fix but my test code runs correctly with this change applied.
This change is