WebAssembly / WebAssembly/tool-conventions

Supporting custom `global` directives

Open
#61 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
372
Forks
75
PR merge metrics
No merged PRs in 30d

Description

I've been doing some toying around with seeing what the wasm threads proposal would look like for Rust recently, and along the way I think that one feature that'd be great to support is the ability to define custom global directives in one way or another.

AFAIK a global basically acts like a "thread local", being tied to a particular instance instead of a global WebAssembly.Module. This works great, for example, for the stack pointer that LLVM uses (which is stored in a global).

Some other uses of global, though, could be something like:

  • Storing an address for thread-local storage values. For example whenever a thread starts it could store the top of the stack into a global which is then used to store auxiliary information like the thread ID, thread-local-store values, etc.
  • Storing the ID of a thread, making it very cheap to access.
  • Any other form of thread local value (so long as it fits in i32)

Currently LLVM doesn't have support for creating custom global items, nor does I believe LLD support linking custom object files which use items like a custom global. What would be the best convention for tools like LLVM and/or LLD to support something like this?

  • Should support for thread locals be added to LLVM and be implemented with global?
  • Could a custom hand-written *.wat file be compiled/assembled and linked with LLD? (this means access can't be inlined but it can at least be written!)
  • Should LLVM support a direct API (maybe with metadata?) for defining global directives?

I'm curious if others have thoughts on this!

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

Start by reviewing the WebAssembly threads proposal context and the issue's questions about LLVM, LLD, and hand-written .wat files. A completed contribution would establish and document a convention for defining and linking custom WebAssembly globals, including how thread-local values are represented and accessed.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, wasm
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
22/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.