Stream: git-wasmtime

Topic: wasmtime / PR #15344 Cranelift: add an option to keep con...


view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 09:21):

ilyas-mallah opened PR #15344 from ilyas-mallah:separate-constant-pool to bytecodealliance:main:

Part of #9402. With the new separate_constant_pool setting on (it's off by default), Cranelift returns each function's constants as a separate blob with relocations. Wasmtime puts them in a .wasmtime.constants section between the page-aligned text and .eh_frame, as alexcrichton suggested. It's enabled with -C cranelift-separate_constant_pool=true.

On AArch64 a constant load becomes an adrp into a fresh vreg and a load from it, as cfallin outlined, with a relocation for each.

riscv64, s390x and Pulley return an error with the setting on, as do cranelift-jit and cranelift-object for a function with constants. Winch ignores it.

With the setting forced on locally, the wast suite and tests/all pass on x86-64, and the wast suite passes on AArch64 under qemu. I haven't run it on AArch64 hardware, macOS or Windows. With it off, .text matches main for the 28 Sightglass modules below. Most of the size change is page padding of the text.

Total .cwasm bytes, 28 Sightglass modules setting off setting on change
x86_64 Linux 14,229,528 14,219,568 -0.070%
AArch64 Linux 18,525,504 18,461,288 -0.347%
AArch64 macOS 14,265,664 14,266,984 +0.009%

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 09:21):

ilyas-mallah removed the review request for wasmtime-compiler-reviewers from PR #15344.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 09:21):

ilyas-mallah requested fitzgen for a review on PR #15344.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 09:21):

ilyas-mallah requested wasmtime-compiler-reviewers for a review on PR #15344.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 09:21):

ilyas-mallah requested wasmtime-compiler-s390x-reviewers for a review on PR #15344.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 09:21):

ilyas-mallah requested wasmtime-core-reviewers for a review on PR #15344.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 11:44):

github-actions[bot] added the label cranelift:area:machinst on PR #15344.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 11:44):

github-actions[bot] added the label cranelift:area:x64 on PR #15344.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 11:44):

github-actions[bot] added the label cranelift:area:aarch64 on PR #15344.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 11:44):

github-actions[bot] added the label cranelift:module on PR #15344.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 11:44):

github-actions[bot] added the label cranelift:meta on PR #15344.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 11:44):

github-actions[bot] added the label wasmtime:api on PR #15344.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 11:44):

github-actions[bot] added the label cranelift on PR #15344.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 19:01):

:memo: fitzgen submitted PR review:

Overall seems reasonable to me, but I'm not super familiar with the details of the relocs involved. That's worth a separate once over from @cfallin or @alexcrichton

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 19:01):

:speech_balloon: fitzgen created PR review comment:

Why is this PR changing the alignment of unwind info?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 19:01):

:speech_balloon: fitzgen created PR review comment:

This test doesn't really seem like it is carrying its weight.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 20:12):

ilyas-mallah updated PR #15344.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 20:52):

:memo: ilyas-mallah submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 20:52):

:speech_balloon: ilyas-mallah created PR review comment:

With the setting on, .eh_frame follows the constants section instead of the page padding of .text, so it no longer starts on a page boundary and the old assert would fire. The constants section is padded to 16 bytes, so .eh_frame still starts 8 byte aligned, and I relaxed the assert to that. Nothing depends on the page here, since publish makes the whole image read-only and only the text range executable. With the setting off the layout is unchanged.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 19 2026 at 16:47):

cfallin commented on PR #15344:

Thanks for working this out!

That said, I'm not wild about the changes to MachBuffer. We've tried to keep it as minimal as possible, and the "separate constant pool" feels like a glued-on duplication of some kinds of logic (e.g. fixups) and also does not update the informal-proof comments. We should try to avoid making changes to MachBuffer if possible.

Maybe instead we can have a separate buffer just for constants (perhaps another MachBuffer) and then emit into that as well as part of the MachInst emit plumbing?

We already have mechanisms for separate function bodies to have mutually-referring relocations that are resolved by the text-section builder; we could use the same mechanisms to resolve the relocs from the function-body buffers to the constant-pool buffer. That feels more in line with the current design, and less invasive / simplifies things overall.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 19 2026 at 17:20):

ilyas-mallah commented on PR #15344:

Thanks for pointing at how calls between function bodies get resolved. You're right about the duplicated fixups and the missing proof comments, and constants as their own bodies fits the existing design better. I'll rework it that way, with each reference a relocation that the text section builder resolves like a call.

One correction on the second MachBuffer: MachInstEmit::emit and x64's AsmCodeSink only receive one &mut MachBuffer. Emit can't reach another without changing that signature or threading state through each backend. Constants also have no labels, fixups or islands, so a second buffer would hold only bytes. Since resolve_reloc has no usable addend, each constant becomes its own labelled body.

Would it be acceptable for MachBuffer to keep a small table of constant references (offset, reloc kind, addend, constant) next to relocs and traps? It would have no fixup or island logic, and the proof comments stay as they are. The alternative is per-backend emit state. That leaves MachBuffer alone but means plumbing it through each x64 and aarch64 emit site. I'd lean toward the table, but I'll do it your way.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 19 2026 at 17:58):

cfallin commented on PR #15344:

One correction on the second MachBuffer: MachInstEmit::emit and x64's AsmCodeSink only receive one &mut MachBuffer. Emit can't reach another without changing that signature or threading state through each backend.

Yes, exactly, that's my suggestion: let's thread through another buffer (or an API wrapped around another buffer) to emit constants. In essence think of each MachBuffer as corresponding to one linker section; we now want to emit code+data into two different sections, so we need two of them.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 19 2026 at 18:09):

ilyas-mallah commented on PR #15344:

Yes, exactly, that's my suggestion: let's thread through another buffer (or an API wrapped around another buffer) to emit constants. In essence think of each MachBuffer as corresponding to one linker section; we now want to emit code+data into two different sections, so we need two of them.

Ah, yeah I didn't consider that. In that case, I'd carry it in each backend's EmitState, which every emit already receives, so the signature stays. EmitState must be Clone and Debug and MachBuffer isn't, so the state holds a small recorder and VCode::emit builds the real second MachBuffer at the end. MachBuffer itself isn't edited, and code references are relocations the text builder resolves like calls between bodies.

Does that match what you meant, or should I just change the emit signature to pass the buffer explicitly? Because from what I saw changing the signature would touch a few hundred call sites.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 19 2026 at 18:16):

cfallin commented on PR #15344:

Let's not put the MachBuffer in EmitState: we don't want to make it clone because it could become large. Instead let's add the second &mut MachBuffer to the signature for emit. Or alternately, perhaps wrap up the two buffers and the fixup state between them in some sort of struct MachBuffers<'a> { pub text: &'a mut MachBuffer, pub rodata: &'a mut MachBuffer, ... } with a method to associate a label in rodata with a relocation in text somehow.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 19 2026 at 18:24):

ilyas-mallah commented on PR #15344:

Let's not put the MachBuffer in EmitState: we don't want to _make_ it clone because it could become large. Instead let's add the second &mut MachBuffer to the signature for emit. Or alternately, perhaps wrap up the two buffers and the fixup state between them in some sort of struct MachBuffers<'a> { pub text: &'a mut MachBuffer, pub rodata: &'a mut MachBuffer, ... } with a method to associate a label in rodata with a relocation in text somehow.

Sounds good, then I'll go with the MachBuffers idea, so the emit calls stay as they are, since only the type of sink would change. Does it work if the rodata buffer is only there when the setting is on, and Winch could just pass the text?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 19 2026 at 18:31):

cfallin commented on PR #15344:

Ah, yes, maybe we keep the MachBuffer borrows private, make the rodata field an Option<&'a mut MachBuffer>, and then have methods on the wrapper to emit constants (which either uses the existing constant-pool feature in the text buffer or emits into rodata).


Last updated: Nov 19 2026 at 20:05 UTC