Memory is not large enough for static data

39 views
Skip to first unread message

Александр Гурьянов

unread,
Jul 2, 2019, 11:02:52 PM7/2/19
to emscripte...@googlegroups.com
Hi. I am trying to set TOTAL_MEMORY to 32mb, but compiler told me:

shared:ERROR: Memory is not large enough for static data (30099056)
plus the stack (5242880), please increase TOTAL_MEMORY (33554432) to
at least 35342960

Is there any way to find what and where this data located?

Thanks

Sam Clegg

unread,
Jul 3, 2019, 12:56:46 PM7/3/19
to emscripte...@googlegroups.com
What exactly are you asking for? Do you want to find our what
constructs in your source are generating 30099056 bytes of static
data? There is a tool called twiggy that might help:
https://github.com/rustwasm/twiggy. It mostly focuses on code size
and I'm not sure data symbols are accessible, but it might be of some
help. You can also inspect you object files with wasm-objdump or try
passing `-Wl,--verbose` at link time and the linker reports some data
layout information.

If you want to reduce your overall memory you could reduce your stack
size by setting, e.g `-s TOTAL_STACK=1M`. Most programs don't need
5Mb of stack.

>
> Thanks
>
> --
> 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-disc...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAKOm%3DVHzwER66gCjAVPpccE%2Bu%3DaFMk6J65zGa46_cdpvqpLfSQ%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Александр Гурьянов

unread,
Jul 4, 2019, 12:35:43 AM7/4/19
to emscripte...@googlegroups.com
> Do you want to find our what constructs in your source are generating 30099056 bytes of static data?
Yes basically it's my question.

I dig more, and now it seems even more strange for me. Compiler ask me
to set TOTAL_MEMORY min to ~30Mb. I used bloaty/twiggy(thanks, great
tool!) to show data secion of generated wasm:
bloaty:
VM SIZE FILE SIZE
-------------- --------------
NAN% 0 Code 1.76Mi 86.7%
NAN% 0 Data 266Ki 12.8%
NAN% 0 Element 4.84Ki 0.2%
NAN% 0 Function 3.63Ki 0.2%
NAN% 0 Import 1.08Ki 0.1%
NAN% 0 Type 446 0.0%
NAN% 0 Export 172 0.0%
NAN% 0 Global 21 0.0%
NAN% 0 [WASM Header] 8 0.0%
100.0% 0 TOTAL 2.03Mi 100.0%

So data is ~266Kb

Next I switched to emmaloc, to find firstRegion location(firstRegion
is begining of heap in emmalloc). It's possible to find it with
this hack: printf("firstRegion: %d\n", (size_t) sbrk(0) - mallinfo().arena);

firstRegion: 36476272

So heap started at ~34Mb, how I can understand which data is placed in
0..34Mb section?

> You can also inspect you object files with wasm-objdump or try
passing `-Wl,--verbose` at link time and the linker reports some data
layout information.

-Wl,--verbose on link step ended with warning that --verbose is unknown flag.

ср, 3 июл. 2019 г. в 23:56, 'Sam Clegg' via emscripten-discuss
<emscripte...@googlegroups.com>:
> To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAL_va2_Tp9wVL0%3D8ei6Ena9byg7%3Dpi_%3DVMsPkF_kTm6oiChkSA%40mail.gmail.com.

Floh

unread,
Jul 5, 2019, 6:56:59 AM7/5/19
to emscripten-discuss
The displayed FILE SIZE in the right column is the size in the binary file (exe or WASM). The size in memory would be on the left (where all those NANs are, I guess that's a bug in that specific tool).

For instance, if you have a 32 MB *non-initialized* global array (which would be zero-initialized at start), it would show up as just a few bytes on the right.

I guess that NAN bug is WASM specific. If you can compile the same code to the native architecture, at least bloaty should show the expected memory-size in the left column.
> > To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAKOm%3DVHzwER66gCjAVPpccE%2Bu%3DaFMk6J65zGa46_cdpvqpLfSQ%40mail.gmail.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> 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+unsub...@googlegroups.com.

Floh

unread,
Jul 5, 2019, 7:02:11 AM7/5/19
to emscripten-discuss
PS: to see the size of specific symbols (functions and global data), instead of just segments, you need to tell bloaty through a command line option to use a different "data source", e.g. "-d symbols".

For instance running bloaty on itself in macOS yields this:

Screen Shot 2019-07-05 at 1.03.46 PM.png

Александр Гурьянов

unread,
Jul 7, 2019, 11:12:32 PM7/7/19
to emscripte...@googlegroups.com
Yeah, thanks nice tip. In native build I see that I have two big zero initialized arrays.

пт, 5 июл. 2019 г. в 18:02, Floh <flo...@gmail.com>:
--
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-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/15d66fe8-9767-46af-88cb-448d50cf60fa%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages