The documentation offers two options: let optimizer strip unnecessary code and then replace the .js glue with your own, or use SIDE_MODULE
flag.
Both options result in a memory
import (instead of export), and in the case of SIDE_MODULE
a ton of extra imports/exports are also defined.
Compare it to a clean output provided by Webassembly Studio:
(module
(type $t0 (func))
(type $t1 (func (result i32)))
(func $__wasm_call_ctors (type $t0))
(func $main (export "main") (type $t1) (result i32)
i32.const 42)
(table $T0 1 1 anyfunc)
(memory $memory (export "memory") 2)
(global $g0 (mut i32) (i32.const 66560))
(global $__heap_base (export "__heap_base") i32 (i32.const 66560))
(global $__data_end (export "__data_end") i32 (i32.const 1024)))
Here, the memory is exported, and __heap_base
is provided, making it easy to write our own allocator. Emscripten output does not export any such values, so we can't know where to start memory allocation.
Is it possible to get similar output with emcc
?
Update: it seems that static/stack sizes are determined internally by emcc, and the only way to retrieve them would be by parsing the generated .js file. Side modules are a different beast and I should probably avoid them if I don't actually need relocatable modules.