Skip to content

WASI: make initial linear memory and stack size target-configurable #2262

Description

@cpunion

Problem

At current main (60c30f2ff), the WASI toolchain unconditionally adds:

-Wl,--initial-memory=67108864
-z stack-size=10485760

internal/crosscompile/crosscompile_test.go also freezes the 64 MiB value. This applies even though targets/wasip1.json declares a much smaller default-stack-size and even when the generated program does not need a large host stack.

This makes a minimal WASI command reserve 1,024 WebAssembly pages (64 MiB) at instantiation, hides the resource benefit of stackless/embedded runtimes, and gives target authors no supported way to select an appropriate memory budget.

Small reproducer

Build any successful WASI command and inspect its memory section:

llgo build -target=wasip1 -o hello.wasm ./hello.go
wasm-objdump -x hello.wasm | grep -A2 '^Memory'

The result contains:

Memory[1]:
 - memory[0] pages: initial=1024

The fixed values come directly from internal/crosscompile/crosscompile.go rather than the resolved target profile.

Suggested direction

  • Add target/profile fields for initial (and optionally maximum) linear memory.
  • Use the resolved target stack-size policy instead of the unconditional 10 MiB linker stack.
  • Keep conservative defaults for the direct GOOS=wasip1 GOARCH=wasm path, but allow named targets to override them.
  • Add a linker-flag unit test plus a tiny module layout test proving the configured page count.

This is independent of the coroutine implementation; it is in the shared main-branch WASI toolchain.

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