Make stack size configurable
TorstenStueber opened this issue ยท 3 comments
๐ก Feature description
Currently the stack-size for local variables of the generated wasm code is preconfigured to be 1048576 bytes. It is easy to reach this limit, e.g., the following program:
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn start() {
let _x = Box::new([[0; 87382]; 2]);
}
will require a stack of size of 1048584 โ 8 bytes larger than the configured size. The generated wasm code will then try to access negative addresses in the linear memory and will throw an error RuntimeError: "index out of bounds"
.
I tried all kinds of options to configure the stack size, but to no avail. For exampe I used the .cargo/config
file to change the stack size:
[target.wasm32-unknown-unknown]
rustflags = [
"-C", "link-args=-z stack-size=1500000",
]
However, the generated wasm code will always use a stack size of 1048576 bytes and will throw an error.
Unfortunately the Rust compiler doesn't currently have a great default way to change the stack size right now. The stack size is configured by the linker currently (LLD), and what you've passed here is basically what you would otherwise need to do to change it, but it's a bug in the Rust compiler that it's not working.
I think I've fixed this at rust-lang/rust#57337
@TorstenStueber could you let us know if you've seen the fix improve this behavior? any sort of update would be great :) thanks!
I can confirm that is works now using the above setting in .cargo/config
. Good job! ๐
@ashleygwilliams feel free to close this issue if there is nothing to add from your side.