You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So, one thing to be aware of: the stack pointer address should actually be zero (LLVM places it at the start of linear memory when compiling to Wasm).
Because there are no data segments, the global table is being placed at the start of the linear memory (address zero), and stack_pointer appears to be the first global in the table.
The actual bug though, I think, is that we're not reserving the first 64k page for the stack. LLVM does this when compiling to memory, but it doesn't look like that is coming through when translating to the IR (i.e. I'd expect a data segment for the stack, but we may have to always assume the first 64k is reserved.
Oh, you're right! The memory address can and should be zero. I just messed up the global var value with its address.
So the problem I'm experiencing (assert_i32 failing) is that at this zero address 1048576 value is expected to be stored (initial global variable value, see Wasm above), which is not the case. The loaded value is zero, so the next 0 - 16 ops produces the unexpected value (instead of 1048576 - 16 = 1048560).
You mentioned that you are working on rodata init, so you might already know about this issue.
greenhat
changed the title
Loading global variable uses incorrect address (zero)
Loading global variable returns incorrect (zero) value
Jul 19, 2024
This seems to be fixed as of #278, at least I have specifically exercised tests which contain uses of the __stack_pointer global that are working and verified manually that they are at the correct address, and that loads/stores to that global load the expected value, so I'm closing this for now.
Discovered in
get_inputs
test.Loading
__stack_pointer
in MASM loads incorrect(zero instead of 1048576) value in MASM.Wasm:
HIR:
MASM:
The text was updated successfully, but these errors were encountered: