HEAP* not accessible anymore through Module object

694 views
Skip to first unread message

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

unread,
Feb 16, 2021, 4:20:53 AM2/16/21
to emscripte...@googlegroups.com
Hi. I faced issue that my js code stop working from 2.0.10. It uses Module.HEAP* variables to access wasm memory. However from 2.0.10 Module does not contains this variables anymore. Is it expected behavior, how I can reexport them?

Floh

unread,
Feb 16, 2021, 12:06:38 PM2/16/21
to emscripten-discuss
Just a wild guess: maybe the name has been mangled by the minification pass, while in previous emscripten versions it might have been "protected" from minification?

I've seen similar problem in the past where Module.func_name() stopped working in newer emscripten versions (especially with stuff like ccall

FWIW I'm using HEAP* as global variable (not Module.HEAP*) and that still seems to work, for instance:

Cheers,
-Floh.

Alon Zakai

unread,
Feb 16, 2021, 12:26:33 PM2/16/21
to emscripte...@googlegroups.com
Hmm, the HEAP* views are always exported,


I verified manually that that works in a hello world at all optimization levels.

Do you have a testcase showing the issue?

On Tue, Feb 16, 2021 at 1:20 AM Александр Гурьянов <caii...@gmail.com> wrote:
Hi. I faced issue that my js code stop working from 2.0.10. It uses Module.HEAP* variables to access wasm memory. However from 2.0.10 Module does not contains this variables anymore. Is it expected behavior, how I can reexport them?

--
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%3DVFe05FCEJ%2BW0umu52uE62f9JtykGL-z98Eqd37hYtA%2BmQ%40mail.gmail.com.

Alon Zakai

unread,
Feb 16, 2021, 12:27:03 PM2/16/21
to emscripte...@googlegroups.com
(I think this is separate from minification. We minify wasm imports and exports, but the HEAP* views are handled entirely in JS.)

--
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.

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

unread,
Feb 16, 2021, 8:51:08 PM2/16/21
to emscripte...@googlegroups.com
I think I was unclear, I mean that I trying to access HEAP variables from outside of Module.
Anyway I have a test case. It instantiate simple wasm module and print all Module keys that started from HEAP.
It prints them both from inside Module and from outside. "inside" case works all times, but "outside" case works only until 2.0.10.
Need to run `./test.sh`

https://drive.google.com/file/d/1Yudusi2wQsWqG4ItAaFEx4hsAbY92WLe/view?usp=sharing

Output for 2.0.9:
```
+ rm -rf ./build
+ mkdir ./build
+ em++ v1.cpp -s INVOKE_RUN=0 -s WASM=1 -s MODULARIZE=1 -s SAFE_HEAP=0 -s ASSERTIONS=1 -s 'EXPORTED_FUNCTIONS=["_main","_malloc","_free"]' -O0 --emit-symbol-map -o build/v1.js
+ node v1-test.js
== FROM OUTSIDE ==
HEAP8
HEAP16
HEAP32
HEAPU8
HEAPU16
HEAPU32
HEAPF32
HEAPF64
== FROM INSIDE ==
HEAP8
HEAP16
HEAP32
HEAPU8
HEAPU16
HEAPU32
HEAPF32
HEAPF64
```

Output for 2.0.10+:
```
+ rm -rf ./build
+ mkdir ./build
+ em++ v1.cpp -s INVOKE_RUN=0 -s WASM=1 -s MODULARIZE=1 -s SAFE_HEAP=0 -s ASSERTIONS=1 -s 'EXPORTED_FUNCTIONS=["_main","_malloc","_free"]' -O0 --emit-symbol-map -o build/v1.js
+ node v1-test.js
== FROM OUTSIDE ==
== FROM INSIDE ==
HEAP8
HEAP16
HEAP32
HEAPU8
HEAPU16
HEAPU32
HEAPF32
HEAPF64
```

ср, 17 февр. 2021 г. в 00:27, Alon Zakai <alon...@gmail.com>:

Alon Zakai

unread,
Feb 17, 2021, 3:07:50 PM2/17/21
to emscripte...@googlegroups.com
I'm not sure what's going on here. Perhaps it's due to using MODULARIZE + a custom instantiateWasm. Is that needed? Removing it may fix things. I think that may be related because in Modularize mode you should do something like

Module().then(..)

and you get the actual Module object, with .HEAP8 etc. on it, in the Promise. But in your custom instantiateWasm I'm not sure where that  would happen.

If that's not it, a simple way to find out specifically where this regressed is to bisect on tot builds, https://emscripten.org/docs/contributing/developers_guide.html#bisecting



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

unread,
Feb 17, 2021, 9:52:22 PM2/17/21
to emscripte...@googlegroups.com
I used suggested -s IMPORTED_MEMORY=1 and it works fine now.

I need custom wasm instantiate function, because I need to inject some environment that used at runtime initialization step. It's important to get reference to HEAP before any wasm code is begin executing. Because of this Module().then() can't work for me.

чт, 18 февр. 2021 г. в 03:07, Alon Zakai <alon...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages