Skip to content

Allow cranelift and satellite crates to be able to build in full no-std mode#13607

Open
stevefan1999-personal wants to merge 2 commits into
bytecodealliance:mainfrom
stevefan1999-personal:feat/cranelift-no-std
Open

Allow cranelift and satellite crates to be able to build in full no-std mode#13607
stevefan1999-personal wants to merge 2 commits into
bytecodealliance:mainfrom
stevefan1999-personal:feat/cranelift-no-std

Conversation

@stevefan1999-personal

@stevefan1999-personal stevefan1999-personal commented Jun 10, 2026

Copy link
Copy Markdown

This PR is the part 1 of the 2 to convert wasmtime into no-std build capable runtime, that makes Cranelift crates to be able to build in fully no-std mode with hopefully minimal code changes, which is needed because https://github.com/wasmi-labs/wasmi lacked so many features I needed.

The first step is to enable Cranelift and its satellite crates to be no-std capable, and since a platform is no longer a guarantee, which means that only Pulley interpreter is available for no-std mode, and thus no need for virtual memory support, so I added a Vec arena backed memory allocator for the "JIT" (but which honestly should be a no-op).

This is also needed because I'm also writing a C compiler, and I don't really want each unit tests to invoke the codegen which sometimes exhitbits strange memory protection error during normal cargo test. My educated guess for that is because of the allocated JIT memory map is so frequent, but the memory protection region has overlapped with ongoing page fault, so the internal virtual memory allocator can't keep up, causing general memory protection error. Although I can sidestep it with cargo nextest which runs each test as an independent process for now, but I'm also curious why that would happen.

I also opted for using libm entirely for the Cranelift interpreter (what's the difference between this and Pulley by the way?), that a deeper research revealed that the fundamental reason for the seemingly faulty fma behavior is due to different ISA platforms implementations, a close analogy for that is the different implementation of long double in x87 and in ARM NEON, which I hope could make things easy to explain. As such, I would suggest just normalize it by using libm anyway.

@stevefan1999-personal stevefan1999-personal requested review from a team as code owners June 10, 2026 08:05
@stevefan1999-personal stevefan1999-personal requested review from alexcrichton and removed request for a team June 10, 2026 08:05
@github-actions github-actions Bot added cranelift Issues related to the Cranelift code generator cranelift:module labels Jun 10, 2026
Comment thread cranelift/jit/Cargo.toml

@bjorn3 bjorn3 Jun 10, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like if you want a no_std JIT, you should make your own cranelift_module::Module implementation instead tailored to the constraints of your OS.

@alexcrichton

Copy link
Copy Markdown
Member

Is your motivation here @stevefan1999-personal tied to using Wasmtime-with-Cranelift-enabled in a no_std environment? Or are you looking to get the entire suite of Cranelift crates separately running in a no_std environment? If the former then many of the changes here won't be necessary, although if the latter then many of these changes will be required. Before going too much further into review though I'd want to confirm this high-level bit.

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

Labels

cranelift:module cranelift Issues related to the Cranelift code generator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants