Closed ghost closed 2 years ago
Oh, this only seems to be a problem with newer versions of emscripten. Trying out an old version of emscripten like 2.0.3, there's no need for -sDYNCALLS=1, and there's no complications in calling free()
According to their changelog at https://emscripten.org/docs/introducing_emscripten/release_notes.html#changelog:
malloc
and free
by default. If you need access to them from
JS, you must export them manually using
-s EXPORTED_FUNCTIONS=['_malloc', ..]
.-O1
. This makes -O1
builds a little
larger but they compile a lot faster, which makes more sense in a "compromise"
build (in between -O0
and higher optimization levels suitable for release
builds). (#12178)ERROR_ON_WASM_CHANGES_AFTER_LINK
option that errors if we need to do
any work in wasm-emscripten-finalize
or wasm-opt
after linking. This
can verify the link is maximally fast and also does no DWARF rewriting.
(#12173)huh, actually looks like linking works up to emscripten 2.0.9
There should be no need for DYNCALLS=1
as it enables a legacy API with functions like dynCall_vi
, it is not necessary for the dynCall
function:
2.0.13: 01/19/2021
------------------
- Add back support for calling the legacy dynCall_sig() API to invoke function
pointers to wasm functions from JavaScript. Pass -s DYNCALLS=1
to include that functionality in the build. This fixes a regression that
started in Aug 31st 2020 (Emscripten 2.0.2)
There is a confusion between EXPORTED_FUNCTIONS
and EXPORTED_RUNTIME_METHODS
: EXPORTED_FUNCTIONS
makes functions accessible from the compiled C/C++ code (otherwise they might be removed to make the build smaller), and EXPORTED_RUNTIME_METHODS
exposes runtime functions to JavaScript code.
Here _free
ends up optimized out so you need to add it to EXPORTED_FUNCTIONS
: -s EXPORTED_FUNCTIONS=["_free"]
-s EXPORTED_FUNCTIONS=["_free"]
seems to have done the trick, thanks!
I still will get an ReferenceError: dynCall is not defined
if I try to compile it without the -sDYNCALLS=1
flag
The dynCall issue should be fixed by https://github.com/paullouisageneau/datachannel-wasm/pull/39
So I managed to get dynCall by linking with
-sEXPORTED_RUNTIME_METHODS=["dynCall"] -sDYNCALLS=1
, but now I'm getting this error about not having free(). I've tried doing-sEXPORTED_RUNTIME_METHODS=["dynCall","_free"]
when I link but It doesn't appear to do anythingSpecifically i'm looking at the free() calls from handleCandidate and handeDescription