WASM force stack slots for allocas

As far as I can tell llvm webassembly has two stacks; one is on the javascript wasm stack and cannot be walked; the other one is in memory before or after the datasegment and can be walked.

I'm using the BoehmGC; which btw works really well except that it cannot scan the wasm stack in any way that I can find thus causing it to free things on the javascript/wasm stack.

Is there a good solution for this, or otherwise a way to force some allocas to stay alloca through the optimizer? Preferably without changing llvm itself of course.

I know about the wasm gc prpoosal, The wasm gc proposal is still in flux, moves slowly and I can respect that; I however I am looking for a solution that works in the shorter term.


Carlo Kok

Hi Carlo,

There’s no scalable way to do this that I know of. Disabling mem2reg might do the trick, but I don’t know how to do that without changing LLVM source. Another workaround might be to mark the relevant locals volatile in your source, but doing that for your entire code base is probably not practical. On the WebAssembly level, we have discussed adding the ability to do stack scanning in the past, but if we add that, it won’t be any time soon.



Would a GC strategy with gc roots not do it?

I’m not sure what you mean. In general, making sure the on-stack roots are spilled to memory whenever the GC runs would solve your problem, but I’m not sure what mechanism you have in mind for that.