-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
My working project for several years (port of RPython for WASM) cannot run anymore in latest emscripten, please tell me what have been changed in the last couple of emscripten versions #19457
Comments
If code was replaced by a trap, then my first guess is that a clang update added new optimizations that found undefined behavior somewhere in that code (or the new optimizations could have a bug, in theory).
Unfortunately there is a truly massive amount of changes in the 3.0.1-3.1.39 range (Dec 2021-May2023). But there is a good way to narrow this down, which is to bisect: https://emscripten.org/docs/contributing/developers_guide.html#bisecting Bisection even on such a large range takes a small number of steps (logarithmic). So once you get set up for bisection as described there, it tends to not take too long. Probably less than an hour on a reasonable network connection. |
Another option is to look for undefined behavior directly: https://emscripten.org/docs/debugging/Sanitizers.html |
I think bisecting is the way to go, but it will take sometime. Regarding the undefined behaviour, would the UBSan and ASan find the problem when the whole function block is replaced with |
It might, yes. An entire block of code being turned into an unreachable is a common outcome from optimizing undefined behavior. |
So UBSan or ASan will show an error when compiling? Or the other way around, on runtime? |
When trying UBSan with WASM mode (non-wasm2js) it worked, and printed this error on runtime:
I'm totally happy with this as my program finally work even though there are integer overflow errors, but how to run this on wasm2js? This error is showing when compiling with wasm2js:
|
I desperately needed wasm2js because default wasm backend Memory object cannot be shrinked unless re-initialized. See this. |
Can undefined behavior trap instruction be turned off temporarily? Is there a flag for that? |
It seems that if I turn off the error on emcc.py and polyfill customSections badly like:
Maybe the offset converter will still do weird behavior but the most important thing the program worked and I can debug it, can I make a PR to turn off the wasm2js error? |
That error is for the sanitizers. It's possible sanitizers don't work with wasm2js atm. But since you only need them for debugging, you can debug without wasm2js. I'm not sure it makes sense to remove that error, as it would make stack traces wrong and confusing. But perhaps the error message could be improved. |
Not entirely removing it, but only just turning it off with special flag or environment variable. Currently what I'm doing is telling the user to do WASM=1 instead or patching emcc.py directly . |
What if we instead error on when |
Or do you really want to support sanitizers (albeit without any real stack traces) with |
Did these errors allow you track down and fix the original "unreachable" issue? |
It is yeah, and the fix is simple, it's weird that RPython original developers is using this undefined behavior although it may have something to do with gcc as their default backend (clang is only on macos). |
Don't do this, I am currently using this loophole |
But just to be clear you found and fixed you issue for this particular case? .. you aren't using Or are you just saying that it would be good to have support in case you need to performs the same debugging on a different issue later? |
I think we can instead downgrade this to a warning. e.g. "warning: santizer support in wasm2js is limited" |
The latter is correct. I can't use -fsanitize-trap=... (the default) because from what I observe on different deployments 99% of them fail with And about wasm2js my project is more inclined to it because it supports shrinking memory. Pure wasm on the other hand only support zero'ing it and impossible to shrink the length. 90% of my users deployment is running on wasm2js and changing it to pure wasm will making those small serverless functions reach max heap of the node process. |
I'm not sure I fully understand exactly what you are you proposing proposing, but you should know that |
I know that it doesn't stop undefined behaviour, but I bet you that UBSan runtime is much lighter than Asyncify. It is also the reason why we are more inclined to wasm2js, our software is designed to fallback to initial memory (that's why we need for the memory to shrink) after polluting it to run some operations. So the memory usage AFAIK will still be low. |
Downgrading that error to a warning makes sense, but it would require some work as without that error it will error later on, see #14630 |
*the previous behavior |
Thats odd.. emscripten/wasm doesn't support |
Please include the following in your bug report:
Version of emscripten/emsdk:
Please include the output
emcc -v
hereUnworking version:
Working version:
This is the version that is known to work now (I installed an old version from homebrew), I remember supporting multiple versions of emscripten that still uses EXTRA_EXPORTED_RUNTIME_METHODS instead of EXPORTED_RUNTIME_METHODS so this bug is about regression.
Failing command line in full:
The initial compilation worked successfully, only some of the program's feature is emitting
unreachable
keyword of wasm or abort randomly.Full link command and output with
-v
appended:Not sure how to get this, RPython is using Makefile for the compilation and what my fork does is changing the CC and some other flags
Description
Please ask for more details by replying/asking about specific topic about my fork of the project or how RPython works, I will only describe this problem briefly because I'm currently on some deadline. I even decided to use a better alternative for this deadline and my report of this bug is just purely for historical and technical reasons. If this problem did not even get resolved in a couple of months, maybe I will kill my project for good.
So in the version 3.1.39 both default wasm backend and wasm2js backend emitted unreachable code. I will show the wasm2js version for easier syntax highlighting:
And wasm2js_trap is basically
unreachable
:So this function is called when the dict (RPython's dict) is grown when there is a new entry (key-value pair), weirdly the previous function that handle the key reindexing and other things worked as usual, the only weird thing is that
unreachable
statement is emitted every corner on the generated code. After several hours of wasting my time I installed an old version of emscripten that still worked on Monterey and voila. It worked flawlessly. And here's the generated dict_grow function:Just as the founding fathers (of RPython obviously) intended. This is exactly what the C code generated. And ignore the v** in the middle of function name, that's the RPython typer in action.
The text was updated successfully, but these errors were encountered: