Description
Whenever I try to compile some specific code for wasm32-unknown-unknown
with enabled overflow-checks
and lto
the compiler inserts a function import into the resulting wasm module that looks like this:
(import "env" "_ZN4core9panicking5panic17h80a3410ec4f43255E" (func $_ZN4core9panicking5panic17h80a3410ec4f43255E (type 0))
These are the complete contents of the lib.rs
:
#![no_std]
#[panic_handler]
fn my_panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}
#[no_mangle]
pub fn multer(a: i128, b: i128) -> i128 {
// trigger usage of the __multi3 compiler intrinsic which seems to be necessary
// in order to reproduce the bug
a * b
}
What seems to trigger the bug are the following conditions:
- The
--target
must bewasm32-unknown-unknown
overflow-checks = true
lto = true
- Recompile core libs with cargo xbuild or the std aware cargo
- The call of the panic function originates in some compiler extrinsic
The minimal reproducer repo contains the exact command line that reproduces the bug.
I expected to see this happen:
The resulting wasm module does not import any function from the environment.
Instead, this happened:
The resulting wasm module imports the previously mentioned panic function from the environment.
Meta
rustc +nightly --version --verbose
:
rustc 1.49.0-nightly (ffa2e7ae8 2020-10-24)
binary: rustc
commit-hash: ffa2e7ae8fbf9badc035740db949b9dae271c29f
commit-date: 2020-10-24
host: x86_64-apple-darwin
release: 1.49.0-nightly
LLVM version: 11.0