Ok, as far as I can work out emscripten runtime memory (ie: 'memory 0') is
laid out like this: App fixed sized static data (ie: BSS/DATA) ->
Emscripten Stack (not wasm control flow stack) -> Heap memory. Is this
correct?

Top of stack/start of heap memory is defined by the globals __stack_pointer
and __heap_base, so if I want to add my own fixed size static data I should
start at offset __stack_pointer - STACK_SIZE, and increase the globals
__heap_base and __stack_pointer by the size of my own static data.

Should this work? Is there any way to determine STACK_SIZE directly from
the wasm module?

Bye!
Mark



On Wed, Jun 28, 2023 at 3:19 PM Mark Sibly <marksi...@gmail.com> wrote:

> Hi,
>
> I'm writing a simple wasm compiler for a version of BASIC, and am planning
> to link the output with an emscripten coded 'runtime' wasm module.
>
> I tried to do this once before by adding support for the custom lld
> sections earlier, but it turned into a bit of an ordeal (it was over half
> the code!) so I gave up. The new plan is to link with an emscripten runtime
> at the 'final module' level.This involves loading the emscripten runtime
> wasm module, and than appending my compiler output to this to create a new
> standalone module. The main idea here is that I wont have to mess with the
> emscripten stuff much - I can just add my functions to the end of the
> functions table etc.
>
> The first problem I've encountered though is how to append static/global
> data. My code will need to use memory offsets past the end of whatever the
> emscripten runtime needs (and before dynamic memory which I guess comes
> from the same pool?) and the only way I can think of to do this is to add
> pages to the 'memory' import, but the resolution of that would be 64K which
> isn't bad I guess but seems excessive.
>
> Is there any way to be able to tell from looking at a wasm module what the
> 'highest' memory address it uses is? I remember C used to have data_start
> and data_end (or similar) globals and was hoping emscripten might export
> something similar but it doesn't seem to.
>
> Bye!
> Mark
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "emscripten-discuss" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/emscripten-discuss/Esy2xhLbEFg/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> emscripten-discuss+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/emscripten-discuss/4062abb6-e1cb-44b3-887a-333ceb8ed808n%40googlegroups.com
> <https://groups.google.com/d/msgid/emscripten-discuss/4062abb6-e1cb-44b3-887a-333ceb8ed808n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to emscripten-discuss+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/CAK32ozg_E2hR_ZJsSQBHZ%3Dh5yidabQgkybBjc68Y2K-S5%3DooXQ%40mail.gmail.com.

Reply via email to