`wasm32-wasip3` with `flto` traps

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

Nobody has claimed this yet.

Assessment

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

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.

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.

Dominant language
CMake
Stars
1.7k
Forks
242
Avg merge
7h 43m
Merged PRs (30d)
2

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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.

More from WebAssembly/wasi-sdk

All issues in WebAssembly/wasi-sdk

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.