Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pointers to static data are sometimes passed incorrectly with the singlepass compiler #2721

Closed
nagisa opened this issue Dec 13, 2021 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@nagisa
Copy link
Contributor

nagisa commented Dec 13, 2021

Describe the bug

When building machine code for a wasm function which calls a host function and passes in a pointer to a 'static string, the offset to the string data is passed through incorrectly (0 is passed).

Steps to reproduce

make test-compilers at master...nagisa:test-for-argpassing

Expected behavior

The pointer argument received by the host function banana should be an offset to the first byte of UTF-8 encoding of the string "bananapeach" within the memory.

The behaviour should be consistent between backends.

Actual behavior

Test when run with the singlepass backend passes through an offset 0 (even though the wasm code itself has a proper offset encoded within it!)

Additional information

This is a regression introduced by 8f855cf.

@nagisa nagisa added the bug Something isn't working label Dec 13, 2021
@nagisa nagisa changed the title Pointers to static variables are sometimes passed incorrectly with the singlepass compiler Pointers to static data are sometimes passed incorrectly with the singlepass compiler Dec 13, 2021
@ptitSeb ptitSeb mentioned this issue Dec 14, 2021
@ptitSeb
Copy link
Contributor

ptitSeb commented Dec 14, 2021

Ok, I have found the issue and commited a fix. i also added your test coase to regression suite: #2723 if that's ok with you.

nagisa added a commit to nagisa/wasmer that referenced this issue Dec 14, 2021
The wasm snippet in the test corresponds to roughly:

```rust
let name = "bananapeach";
banana(a, b, c, name.len() as _, name.as_ptr() as _, f, g, h);
```

however sometime between 2.0 and 2.1 the name pointer is no longer being
passed through as an argument. Instead a 0 gets passed in.

To make things weirder, if `name.as_ptr()` is passed through multiple
times, the second time the pointer will get passed correctly.
bors bot added a commit that referenced this issue Dec 14, 2021
2723: fix #2721, also adding the test in the regression test suite r=ptitSeb a=ptitSeb

# Description
Fix for #2721, regression introduce with Windows backend for Singlepass.


Co-authored-by: ptitSeb <[email protected]>
@bors bors bot closed this as completed in 3dda0d4 Dec 14, 2021
bors bot added a commit that referenced this issue Dec 14, 2021
2725: Regression test for #2721 r=syrusakbary a=nagisa

The wasm snippet in the test corresponds to roughly:

```rust
let name = "bananapeach";
banana(a, b, c, name.len() as _, name.as_ptr() as _, f, g, h);
```

however sometime between 2.0 and 2.1 the name pointer is no longer being
passed through as an argument. Instead a 0 gets passed in.

To make things weirder, if `name.as_ptr()` is passed through multiple
times, the second time the pointer will get passed correctly.

The fix for this issue is in #2723.

Co-authored-by: Simonas Kazlauskas <[email protected]>
Co-authored-by: Syrus Akbary <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants