Skip to content

wasm32-wasip3 v34-rc1 reactor crashes at startup when a global constructor is present #643

Closed

Description

@MendyBerger

A minimal wasm32-wasip3 C++ component with a global constructor traps as soon as it's instantiated. The same code built for wasm32-wasip2 runs fine.

Reproduction

wit/repro.wit:

package foo:bar;

world my-world {
    export run: func();
}

impl.cpp:

#include <string>
#include <cstdio>
#include "my_world_cpp.h"

// A global object whose constructor uses the stack.
struct Greeter {
    std::string msg;
    Greeter() : msg("ctor ran") { std::fprintf(stderr, "%s\n", msg.c_str()); }
};
static Greeter g;

void exports::my_world::Run() {
    std::fprintf(stderr, "run called\n");
}

Build and run:

wit-bindgen cpp wit --world my-world
$WASI_SDK_PATH/bin/clang++ --target=wasm32-wasip3 -std=c++23 -mexec-model=reactor \
    -fwasm-exceptions -mllvm -wasm-use-legacy-eh=false \
    impl.cpp my_world.cpp my_world_component_type.o -lunwind -o my-world.wasm
wasmtime run -W exceptions=y,component-model-async=y --invoke 'run()' my-world.wasm

Error

error while executing at wasm backtrace:
    0: my-world.wasm!Greeter::Greeter()
    1: my-world.wasm!__cxx_global_var_init
    2: my-world.wasm!_GLOBAL__sub_I_impl.cpp
    3: my-world.wasm!__wasm_call_ctors
    4: my-world.wasm!_initialize
memory fault at wasm address 0xfffffffc in linear memory of size 0x20000
wasm trap: out of bounds memory access

Building the same source for wasm32-wasip2 instead runs fine (ctor ran / run called).

Versions:

  • wasi-sdk: v34.0-rc.1
  • wasmtime: 46.0.1
  • wit-bindgen: 0.59.0

Activity

  1. alexcrichton commented on Jul 20, 2026

    @alexcrichton
    Collaborator

    Thanks! This should be fixed by bytecodealliance/wasm-tools#2574 (and it'll take a moment to percolate that everywhere)

  2. alexcrichton commented on Jul 22, 2026

    @alexcrichton
    Collaborator

    Ok should be fixed in 34.0-rc.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions