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

Validation of internal globals in const expressions is inconsistent between interpreter and spec #1522

Closed
binji opened this issue Aug 18, 2022 · 10 comments · Fixed by #1525
Closed

Comments

@binji
Copy link
Member

binji commented Aug 18, 2022

The following WebAssembly module is invalid in the reference interpreter:

(memory 1)
(global i32 (i32.const 0)
(data (global.get 0) "")

This was originally disallowed in #383. However, the test added in that PR was commented out.

However, the spec currently explicitly mentions that global initializers can only reference imported globals, but does not mention anything about the same for data and element segments. Module validation also seems to use C instead of C' when validating data/element segments too, indicating that they can access both internal and imported globals.

@rossberg
Copy link
Member

Indeed. Please see #1525 for a fix.

@binji
Copy link
Member Author

binji commented Aug 23, 2022

Interesting, I would have assumed the spec should be changed, not the interpreter! I guess I should mention that AFAIK all browser engines currently treat using an internal global in a segment initializer as an error. But I suppose it's safe to extend the functionality.

@rossberg
Copy link
Member

I see! I wasn't aware that browsers agree with the interpreter instead of the spec. I'm also totally fine changing the spec. Since that's just codifying reality then it would be the simpler change. I'll prepare an alternative PR.

@binji
Copy link
Member Author

binji commented Aug 23, 2022

I just tested Chrome, Safari, Firefox and they all seem to agree. Here's the test I was using segment-init-global.zip. It might be worthwhile to see what the other engines do in this case, since I seem to remember @Cyborus04 (who originally discovered this issue) mentioning a few that had a different result.

@Cyborus04
Copy link

Hi! My testing showed that wasm3 and wasmtime agree with the spec, while wasmer agrees with the tests

@rossberg
Copy link
Member

Thanks @Cyborus04. That makes the issue somewhat less clear-cut. Though arguably, there is a clear majority of implementations agreeing with the tests, so I would still tend towards tweaking the spec. Do you agree?

@binji
Copy link
Member Author

binji commented Aug 24, 2022

Yeah, I think it makes sense to update the spec. I suppose it's worth notifying those two projects too. I've opened new bugs on those projects to track.

@Cyborus04
Copy link

I would still tend towards tweaking the spec. Do you agree?

Coming from the very strong backwards compatibility guarantees of Rust, my instinct says to go for the less restrictive option of aligning with the spec. I don't feel too strongly either way, though, and would not consider my thoughts an "expert opinion" by any stretch of the imagination.

@rossberg
Copy link
Member

Well, in fact, the backwards compatibility requirements for Wasm are even stronger than Rust's. But in this case, even the test suite said otherwise, so one could argue that the spec merely has a typo for saying something else.

In any case, I put it on the agenda for the next meeting.

@Cyborus04
Copy link

Cyborus04 commented Aug 25, 2022

Oh, are they? Interesting. I guess then, it's a question of which one is prescriptive and which is descriptive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants