WebAssembly / WebAssembly/wasi-sdk

`wasm32-wasip3` with `flto` traps

Open
#657 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
CMake
Stars
1.6k
Forks
237
Avg merge
18h 26m
Merged PRs (30d)
5

Description

Combining wasm32-wasip3 with flto causes a traps.

Given this simple code:

#include <stdio.h>
int main(int argc, char **argv) {
    printf("hello world\n");
    return 0;
}

Compiled with

$WASI_SDK_PATH/bin/clang --target=wasm32-wasip3 -flto main.c -o out.wasm

And run with wasmtime:

wasmtime run out.wasm

Gives the following crash:

Error: failed to run main module `out.wasm`

Caused by:
    0: error while executing at wasm backtrace:
    0:    0xe3c - out.wasm!main
    1:    0xfdd - out.wasm!__main_void
    2:    0xdd0 - out.wasm!_start
    3:  0x6963c - <unknown>!<wasm function 15>
note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable may show more debugging information
    1: memory fault at wasm address 0xfffffffc in linear memory of size 0x20000
    2: wasm trap: out of bounds memory access

When removing -flto or changing to wasm32-wasip2 the resulting wasm binary runs just fine.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the shown clang command and wasmtime invocation, then compare it with the non-LTO and wasm32-wasip2 builds. Trace the generated out.wasm execution around main and the reported out-of-bounds access; done means the wasm32-wasip3 build with -flto runs without trapping.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, wasm
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.