-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Cannot use 0 as an address in wasm in with opt-level >= 1 #57897
Comments
Oh my, 0 pointer not being a null strikes! |
|
Ha, I really should read the documentation when using It’s completely fair to not allow address |
@surma hmm... the function has |
Even if it was, it would only be checking for alignment, not for a non-zero value, wouldn’t it? |
@surma yeah my bad; we should perhaps add |
The pre-built binaries distributed through rustup are built without debug assertions, so neither the existing alignment check nor a new (debug-assertion-only) null check would actually reach most users. |
So what changes would need to be made to make this program crash in debug mode, and not only in release mode? |
Invocation of undefined behaviour yields undefined results, so we cannot and will not guarantee crash, crash-free or matching behaviour at any of the optimisation levels. I’m sympathetic to the observation that I do not see how this issue is actionable in any way as is. |
I am not expecting I do feel like it would be reasonable to add some debug-only code that guarantees a crash in debug mode, but that code would get stripped in release mode. Or is that not possible? In release mode I am of course 100% okay with undefined behavior being exactly that, undefined. |
@surma Another option is to try out the |
It's not impossible, but it is pretty hard. The problem is that the stdlib -- at present -- is always optimized. We've talked for a long time about having the ability to rebuild the stdlib with different options, or at least shipping a "debug version", in part so that we can add assertions like this, but it's not something we have the capacity to do right now. So, that would imply that we'd have to add the assertion also in optimized mode, which we don't really want to do. |
Ah understood. Fair enough. Thanks for clarifying. |
Also see #53871 |
I'm going to close this because this is something we're pretty unlikely to ever support in wasm. |
I want to use Rust to work on the raw chunk of memory that WebAssembly creates for me. Consider the following rust code:
Compile with
And load with this HTML file:
This will work fine (i.e. no errors).
If you add
-C opt-level=1
(or2
or3
) to therustc
invocation, the wasm module will fail withunreachable
.If you change the rust code as following
the code will work again.
I think if I can use
0
as an address in a debug build I should also be able to do it in release mode 😄cc @ashleygwilliams
The text was updated successfully, but these errors were encountered: