2.0.3 getMemory is undefined

105 views
Skip to first unread message

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

unread,
Sep 13, 2020, 11:04:40 PM9/13/20
to emscripte...@googlegroups.com
Hi. Just updated emscripten to 2.0.3, everything builds fine but now I
have error on module instantiation:

ReferenceError: getMemory is not defined

I checked the generated code of Module, and it have:

Module["getMemory"] = getMemory;

but getMemory itself never defined, for example in previous version it was:

function getMemory(size) {
if (!runtimeInitialized) return dynamicAlloc(size);
return _malloc(size)
}
Also dynamicAlloc is not there.

There are some new compiler flags?
Thanks

Sam Clegg

unread,
Sep 13, 2020, 11:16:22 PM9/13/20
to emscripte...@googlegroups.com
These functions were removed since we managed to remove all our allocations that occurred before startup.

This is/was an important thing for us to do as it allows wasm-ld (the static linker) to fully determine memory layout and specifically heap location without the need for post-link modifications to the wasm binary.

You should be able simply call `_malloc` instead, or move your allocation in a C/C++ global?   These are the two approaches that we used to remove all or our internal usage of dynamicAlloc.

cheers,
sam

--
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%3DVG-dBKPFWGowBuV7Ah%3DA1TLR1koBPBmJhNAY3cd4TcM0Q%40mail.gmail.com.

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

unread,
Sep 13, 2020, 11:24:19 PM9/13/20
to emscripte...@googlegroups.com
Sorry I don't understand what I should do. This error happens on a
regular codebase without something special (just libzip and extraction
code). I use emsdk, emcmake, cmake and make to compile it. I don't
call getMemory or dynamicAlloc from my side, I mean how can I call
them before instantiation is finished? There is some pattern in C/C++
code that results in this behaviour?

P. S. 2.0.2 works fine.

пн, 14 сент. 2020 г. в 10:16, '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-1kXWHTVq4XCSzpJMvFhjEae45j3sG7JvM%2BBbUCQtUBA%40mail.gmail.com.

Sam Clegg

unread,
Sep 14, 2020, 10:53:27 AM9/14/20
to emscripte...@googlegroups.com
Can you give steps to reproduce?   Perhaps you can open an issue in the bug tracker?

Can you tell which JS function is referencing `getMemory`?    It should be removed from the codebase (except if `-s MAIN_MODULE`  is used).

cheers,
sam


Alon Zakai

unread,
Sep 14, 2020, 11:05:54 AM9/14/20
to emscripte...@googlegroups.com
You can add this:

function getMemory() {
  abort(new Error().stack);
}

and then when it is called it will halt with a stack trace. That can help figure out what is calling it. (Make sure to build with --profiling so the stack trace is clear.)


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

unread,
Sep 14, 2020, 9:19:14 PM9/14/20
to emscripte...@googlegroups.com
Okay) This is very stupid, I created test case and was so close to
create issue, but I found a reason.
It's because I have this:
-s EXTRA_EXPORTED_RUNTIME_METHODS=\"['getMemory', ...
Actually it's never used and when I removed it all tests were passed.

Thanks!

пн, 14 сент. 2020 г. в 22:05, Alon Zakai <alon...@gmail.com>:
> To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAEX4NpT636rWjiPVqRFEe5punQHS_fieKYZsN_7bGE7yFr7wXQ%40mail.gmail.com.

Sam Clegg

unread,
Sep 14, 2020, 9:21:52 PM9/14/20
to emscripte...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages