Description
With the current nightly builds (1.24.0-nightly (73bca2b 2017-11-28)), some (I assume most) programs are unrunnable on wasm32-unknown-unknown (tested in Firefox 56.0) unless compiled with optimization flags. The condition appears somewhere between where the start function and main is called in this example, but I've also tested overriding the start function to a no-op, and then the most simple functions (just returning an integer) worked, but anything that called another function didn't.
Steps to reproduce:
#[no_mangle]
pub extern "C" fn pub_function(x: i32) -> i32 { 2 * x }
pub fn main() {}
as demo.rs; compile with rustc +nightly --target wasm32-unknown-unknown -O demo.rs
and serve together with this index.html:
<script>
fetch("demo.wasm").then(response =>
response.arrayBuffer()
).then(bytes =>
WebAssembly.instantiate(bytes, {})
).then(results =>
console.log(results.instance.exports.pub_function(42))
);
</script>
… and the console will print 84
. Leave out the -O
, and instead, the console will give RuntimeError: index out of bounds
, with a stack trace 7 deep into the start function at a i32.store offset=4
instruction.