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

RuntimeError: unreachable when calling imported function in standalone mode #12322

Closed
vedantroy opened this issue Sep 24, 2020 · 1 comment
Closed

Comments

@vedantroy
Copy link

When importing a JS function from C & calling it in standalone mode, I get an unreachable error (WASM execution hit an "unreachable" statement).

Here's the reproduction:

void import_from_js();

int main() {
    import_from_js();
    return 0;
}
(async () => {
    const { instance } = await WebAssembly.instantiateStreaming(fetch("./sample.wasm"), {
        env: {
            import_from_js: () => {
                console.log("Hello World!")
            }
        },
        wasi_snapshot_preview1: {
            proc_exit: (code) => {
                console.log(code)
            }
        }
    })
    await instance.exports._start()
})()

The command: emcc sample.c -o sample.wasm -s ERROR_ON_UNDEFINED_SYMBOLS=0.

Emscripten version: emcc (Emscripten gcc/clang-like replacement) 2.0.4 (3047b77)

@sbc100
Copy link
Collaborator

sbc100 commented Sep 24, 2020

I think we figured this out on discord. proc_exit is supposed to never return. You need to throw or exit the process or something like that.

I think llvm inserts and unreachable instruction after a call to any C/C++ function marked noreturn which __wasi_proc_exit is:

_Noreturn void __wasi_proc_exit(

codefromthecrypt pushed a commit to tetratelabs/wazero that referenced this issue Jul 5, 2022
This changes the AssemblyScript abort handler and WASI proc_exit
implementation to panic the caller which eventually invoked close.

This ensures no code executes afterwards, For example, LLVM inserts
unreachable instructions after calls to exit.

See emscripten-core/emscripten#12322
See #601

Signed-off-by: Adrian Cole <adrian@tetrate.io>
codefromthecrypt pushed a commit to tetratelabs/wazero that referenced this issue Jul 6, 2022
This changes the AssemblyScript abort handler and WASI proc_exit
implementation to panic the caller which eventually invoked close.

This ensures no code executes afterwards, For example, LLVM inserts
unreachable instructions after calls to exit.

See emscripten-core/emscripten#12322
See #601

Signed-off-by: Adrian Cole <adrian@tetrate.io>
codefromthecrypt pushed a commit to tetratelabs/wazero that referenced this issue Jul 6, 2022
This changes the AssemblyScript abort handler and WASI proc_exit
implementation to panic the caller which eventually invoked close.

This ensures no code executes afterwards, For example, LLVM inserts
unreachable instructions after calls to exit.

See emscripten-core/emscripten#12322
See #601

Signed-off-by: Adrian Cole <adrian@tetrate.io>
codefromthecrypt added a commit to tetratelabs/wazero that referenced this issue Jul 6, 2022
This changes the AssemblyScript abort handler and WASI proc_exit
implementation to panic the caller which eventually invoked close.

This ensures no code executes afterwards, For example, LLVM inserts
unreachable instructions after calls to exit.

See emscripten-core/emscripten#12322
See #601

Signed-off-by: Adrian Cole <adrian@tetrate.io>
codefromthecrypt added a commit to tetratelabs/wabin that referenced this issue Aug 30, 2022
This changes the AssemblyScript abort handler and WASI proc_exit
implementation to panic the caller which eventually invoked close.

This ensures no code executes afterwards, For example, LLVM inserts
unreachable instructions after calls to exit.

See emscripten-core/emscripten#12322
See #601

Signed-off-by: Adrian Cole <adrian@tetrate.io>
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

2 participants