WebAssembly / WebAssembly/WASI

Separate initialization and finalization

Open
#441 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

S-inactive
Dominant language
Rust
Stars
5.8k
Forks
333
Avg merge
2d 13h
Merged PRs (30d)
3

Description

Right now, _start initializes global state, calls main(), and then tears down global state.

This is fine for executable modules, but not for modules designed to be used as libraries.

For a library, I would like to initialize global state right after the library is loaded, and then tear down global state right before shutting the library down.

I am proposing separating the initialization part into a separate exported function (call it _init) and, similarly, splitting the finalization into a separate exported function (call it _fini).

Then _start becomes (pseudocode):

void _start() {
    _init();
    // set up arguments for main(), call main()
    _fini();
}

but people who intend to use the module as a library have the option to call _init() and _fini() directly.

Contributor guide

Open the contributing guide

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

Start by locating the current _start implementation and tracing how it initializes global state, calls main(), and tears that state down. Define the exported _init and _fini entry points so library users can call them independently, while _start preserves the existing sequence; done means both executable and library use cases are supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
wasm
Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.