Skip to content
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

wasm32-unknown-emscripten programs crash with codegen-units > 1 #43101

Closed
tlively opened this issue Jul 7, 2017 · 8 comments
Closed

wasm32-unknown-emscripten programs crash with codegen-units > 1 #43101

tlively opened this issue Jul 7, 2017 · 8 comments

Comments

@tlively
Copy link
Contributor

tlively commented Jul 7, 2017

When libstd is built with codegen-units > 1, programs built for wasm32-unknown-emscripten can crash.

I tried this code:

hello.rs

fn main() {
    println!("Hello, WebAssembly!");
}
rustc --target wasm32-unknown-emscripten hello.rs
node hello.js

I expected to see this happen:

Hello, WebAssembly!

Instead, this happened:

exception thrown: RuntimeError: invalid function,RuntimeError: invalid function
    at  (<WASM>[804]+7)
    at Object.Module.dynCall_vii (~/tlively/hello.js:5928:92)
    at invoke_vii (~/tlively/hello.js:6022:26)
    at  (<WASM>[550]+121)
    at  (<WASM>[804]+7)
    at Object.Module.dynCall_vii (~/tlively/hello.js:5928:92)
    at invoke_vii (~/tlively/hello.js:6022:26)
    at  (<WASM>[256]+130)
    at  (<WASM>[114]+50)
    at  (<WASM>[50]+7)
failed to asynchronously prepare wasm: RuntimeError: invalid function
(node:151136) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): RuntimeError: invalid function
(node:151136) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

However, compiling libstd with codegen-units = 1 gives the expected behavior.

Meta

rustc:

rustc 1.20.0-dev (3610a70ce 2017-07-05)
binary: rustc
commit-hash: 3610a70ce488953c5b0379fece70f2baad30a825
commit-date: 2017-07-05
host: x86_64-unknown-linux-gnu
release: 1.20.0-dev
LLVM version: 4.0

emcc: 1.37.15 (commit e99b50793a81b97a2559ec93fa49c7a0a8aaa4cc)
node: v8.1.2

config.toml:

[build]
submodules = false
target = ["x86_64-unknown-linux-gnu", "asmjs-unknown-emscripten", "wasm32-unknown-emscripten"]
 
[rust]
codegen-units = 48
debug-assertions = true
 
[llvm]
assertions = true
targets = "X86;JSBackend"
clean-rebuild = true
optimize = false
ccache = true
@tlively
Copy link
Contributor Author

tlively commented Jul 7, 2017

Update: codegen-units = 2 is sufficient to trigger this bug.

@tlively
Copy link
Contributor Author

tlively commented Jul 7, 2017

@kripken The emscripten-visible effect of having multiple codegen units is that the resulting rlib contains one object file for each codegen unit. Do you have a sense for whether this would be a Rust bug or an emscripten bug?

@CryZe
Copy link
Contributor

CryZe commented Jul 7, 2017

Considering there's another breakage caused by codegen-units the issue before this one, I think it may be the same cause: #43095

@kripken
Copy link

kripken commented Jul 7, 2017

Looks like this uses wasm32-unknown-emscripten, does that mean it uses the wasm backend (and not asm.js)?

@CryZe
Copy link
Contributor

CryZe commented Jul 7, 2017

Nah, this right here is the old one that goes through asm.js

@kripken
Copy link

kripken commented Jul 7, 2017

Then the target looks wrong, does changing it to the asm.js target (asmjs-unknown-emscripten) fix things?

@tlively
Copy link
Contributor Author

tlively commented Jul 7, 2017

yikes, my setup was all screwed up and was always using the wasm backend. Using emsdk incoming this works as expected for both wasm32-unknown-emscripten and asmjs-uknown-emscripten.

@tlively tlively closed this as completed Jul 7, 2017
@tlively
Copy link
Contributor Author

tlively commented Jul 7, 2017

This is still an issue when using wasm32-experimental-emscripten. If I don't fix it in the next couple days I'll make a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants