-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Wasm with lto and use of f32::sin() gets an unknown reference to env
module
#72758
Comments
Pulls in a fix for rust-lang#72758, more details on the linked issue. [Crate changes included here][changes] [changes]: rust-lang/compiler-builtins@0.1.28...0.1.31
For some more background on this issue, this is a standalone reproduction: #[no_mangle]
pub extern "C" fn wasm_sin(key: i32) -> i32 {
(key as f32).sin() as i32
} where the issue can be seen with: $ rustc +stable foo.rs --crate-type cdylib --target wasm32-unknown-unknown -O
$ wasm2wat foo.wasm | rg import
$ rustc +stable foo.rs --crate-type cdylib --target wasm32-unknown-unknown -O -C lto
$ wasm2wat foo.wasm | rg import
$ rustc +beta foo.rs --crate-type cdylib --target wasm32-unknown-unknown -O
$ wasm2wat foo.wasm | rg import
$ rustc +beta foo.rs --crate-type cdylib --target wasm32-unknown-unknown -O -C lto
$ wasm2wat foo.wasm | rg import
(import "env" "_ZN4core9panicking18panic_bounds_check17hadfb911a22557eccE" (func $_ZN4core9panicking18panic_bounds_check17hadfb911a22557eccE (type 0))) Here the bug is that, in beta (and onwards) with LTO turned on there's an unresolved symbol. Bisection pointed out #70846 as the cause of the bug here. The problem appears to be that previously compiler-builtins was optimized enough such that llvm removed all panics and bounds checks, but with a codegen unit reshuffling of compiler-builtins this did not happen and a bounds check was still in there. It's intended that compiler-builtins cannot panic, and we even have a test that this is the case. Unfortunately though WebAssembly wasn't tested on CI which notably activates the libm intrinsics, which is where the panic was coming from here (the sin function). I expanded testing to include wasm in rust-lang/compiler-builtins#360, and the first few commits failed showing lots of references to panics. I fixed the implementation in libm at rust-lang/libm#244. Most of those changes were so in debug mode there weren't panic checks. In release mode there was only one panic check which needed fixing, but fixing them all was needed for compiler-builtins's CI. I've submitted a fix for this in #72759 by updating compiler-builtins. |
This bug was wrongly posted at wasm-bindgen, but it looks like it is a compiler issue.
The following example fails to create a proper module, with either:
(stable rustc 1.43.1 works fine).
Cargo.toml
src/lib.rs
With this command to compile:
produces this error:
Looking at the compiled
wasm
, withwasm-dis
, there is this line that doesn't seem correct.Switching
lto
tofalse
or changing thesin()
toasin()
, for example, make the"env"
disappear.The text was updated successfully, but these errors were encountered: