-
-
Notifications
You must be signed in to change notification settings - Fork 104
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
The force-enabling of SIMD128 feature can lead to unloadable WASMs in some browsers #144
Comments
Is it possible to reproduce this using
So I tried getting rid of enabling SIMD:
But that still works fine. Then I tried forcefully disabling
But that works too. So try as I might, I can't make the current code fail. I note that SIMD isn't actually force enabled on wasm32. It is specifically only used when the memchr/src/arch/wasm32/simd128/memchr.rs Lines 71 to 81 in cedf318
Now, there are functions defined with From what I can gather, the problem here is that something is choking on the function definition itself in the wasm binary. So I suppose your commentary about dead code elimination makes sense... Since wasm32's |
Thank you very much for looking into this!
I do not know, I have a giant (14 MB) wasm file to be used on the web. It is easy to validate with
Yes, that is the problem. On Safari iOS (test with version 15.5, from late 2021/early 2022, so not terribly old), the resulting WASM fails to load because the browser attempts to validate it and it finds instructions it doesn't know (the SIMD ones present in the functions that are never called), so the validation and therefore the loading fail.
In general it should be, but unfortunately with validating browsers, it is not.
That would solve the problem at the moment with browsers.
I agree, but I would argue that the short term problem is way more critical. I guess we could switch back to a less brutal approach if/when there is a runtime detection mechanism widely available in browsers? |
The current way of doing feature detection with WASM on browsers is to try to load a small WASM with the specific feature and see whether it fails. See for example this library from Google. |
cc @alexcrichton Do you have any opinions here? I'm tempted to just gate the wasm32 SIMD optimizations under |
(apologies if I'm repeating anything already said here I'm only responding to @BurntSushi's latest comment) I would agree with your conclusion, gating everything behind |
All righty, done deal. I'll get a patch up for this soonish. |
Thank you both of you for your quick reaction and your attention! |
Any update on the patch? |
It turns out that providing routines with `#[target_feature(enable = "simd128")]` on `wasm32` can fail in some older browsers. The specific problem is not totally clear to me, but it is straight-forward enough to fix (I hope) by just requiring that `simd128` be enabled at compile time in order to include the `wasm32` SIMD modules in this crate. This would not be a great solution if WASM supported runtime CPU feature detection. And the status quo is that `simd128` has to be enabled at compile time anyway for the SIMD code to take effect. So this shouldn't cause any regressions and is likely something we can do long term as well. We can re-evaluate once and if WASM gets support for runtime CPU feature detection. We also add a CI test for `wasm32` *without* the `simd128` target feature enabled. Fixes #144
It turns out that providing routines with `#[target_feature(enable = "simd128")]` on `wasm32` can fail in some older browsers. The specific problem is not totally clear to me, but it is straight-forward enough to fix (I hope) by just requiring that `simd128` be enabled at compile time in order to include the `wasm32` SIMD modules in this crate. This would not be a great solution if WASM supported runtime CPU feature detection. And the status quo is that `simd128` has to be enabled at compile time anyway for the SIMD code to take effect. So this shouldn't cause any regressions and is likely something we can do long term as well. We can re-evaluate once and if WASM gets support for runtime CPU feature detection. We also add a CI test for `wasm32` *without* the `simd128` target feature enabled. Fixes #144
This should hopefully be fixed in |
In several cases, memchr force-enables the SIMD feature on wasm32 (for example here). This has been an issue for me because, in a fairly large project where memchr is used indirectly by several packages (nom, nom_locate, pulldown-cmark and regex), the code with SIMD gets pulled in and the resulting WASM fails to load on some slightly-older browsers such as Safari iOS 15, with an error looking like:
An example of code pulled in (as shown by
wasm-decompile
) is:In release mode the code has so far been optimized out but in dev mode it is still in, although I did not specify
target-feature=+simd128
in myRUSTFLAGS
, so it is a problem to test/debug with older Safari. I'm also worried whether in some cases such code might find its way to the release mode as well.A possible work-around would be to add more aggressive dead code elimination in dev mode but I did not find how to do that.
The text was updated successfully, but these errors were encountered: