Description
Background: One of the tasks for WebAssembly/binaryen#3043 is to stop the special handling of sbrk (DYNAMICTOP_PTR
, emscripten_get_sbrk_ptr
, etc.) which requires a bunch of work after link. To replace all that, we should implement sbrk 100% in wasm. I have a prototype mostly working in a branch, but have hit the following problem.
The problem: sbrk(0)
at program start should return the initial location of the program break, that is, the top of used memory by malloc. In emscripten we have first static allocations, then the stack, and then that region. sbrk.c
needs to initialize itself to that value.
It seems there isn't a good way for this atm? stack_ops.s calls out to emscripten_stack_get_base
in JS to do it, where we have STACK_BASE
. In general though if would be smaller and better to avoid JS for this. And to embed it in the wasm manually (which we do for emscripten_get_sbrk_ptr
) requires work after link which is what I'm trying to remove.
This seems like the kind of thing a special intrinsic could do, but it would need to be implemented by the linker (are there such things?)