Skip to content

How to include Module._malloc and Module._free with the latest update? #12644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
josh83abc opened this issue Oct 29, 2020 · 5 comments
Closed

Comments

@josh83abc
Copy link

Hello guys,

I just upgraded to the latest version of emscripten and I can't make my project to work anymore. I didn't do any change, I just needed to recompile. 2 months ago it worked fine.

It looks like the new version doesn't include Module._malloc et Module._free anymore >Stop including malloc/free by default #12213

So now I got the error : Module._malloc is not a function

And by comparing with my old working compiled project, I can see that these lines are missing in the generated JS :
Object.getOwnPropertyDescriptor(a.ready,"_malloc") ...
Object.getOwnPropertyDescriptor(a.ready,"_free") ...

I tried to add the malloc and free manually : emcc .... -s EXPORTED_FUNCTIONS="['_malloc', '_free']"

But now I get this error : RuntimeError: abort(Assertion failed: exported native function malloc not found)

How to include Module._malloc and Module._free with the latest emscripten update?

Thanks for your help, I lost 3 hours on this :/

@sbc100
Copy link
Collaborator

sbc100 commented Oct 29, 2020

-s EXPORTED_FUNCTIONS="['_malloc', '_free']" should absolutely work.

For example can you run emcc tests/hello_world.c -s EXPORTED_FUNCTIONS="['_main', '_malloc', '_free']". This works fine for me.

Oh.. I see this is a runtime error which means as far as the compiler is concerned the functions do exist... but they are somehow not found in the wasm module at runtime.. could the wasm module being loaded be out-of-date?

Can you see using wasm-objdump if malloc is actually exported by the final module that you are shipping?

@josh83abc
Copy link
Author

Ok I just got the idea to clear the cache (emcc --clear-cache) and I recompiled everything, with -s EXPORTED_FUNCTIONS="['_main', '_malloc', '_free']", and it works! I don't know what happened, I am pretty sure my previous wasm module was the most recent one. Anyway, always good to clear the cache :)
Thanks for the super fast reply!

@sbc100 sbc100 closed this as completed Oct 29, 2020
@sbc100
Copy link
Collaborator

sbc100 commented Oct 29, 2020

Actaully .. the cache should always be cleared when you update between emscripten versions so what you describe should not be possible. Just FYI in case this comes up again it might be a sign of a different issue with stale cache.

@josh83abc
Copy link
Author

When I clear the cache, emscripten generates a few files (liba...), but don't use to happen when I update to a new emscripten versions... Anyway, better to clear the clear twice to be sure ;) (I am using emscripten on linux)

@sbc100
Copy link
Collaborator

sbc100 commented Oct 30, 2020

When you install new emsdk versions that cache is completely erased and replaced with a new set of pre-built libraries that ship with the emsdk (so that users don't all need to build libc the first time they do anything).

(BTW are you using the normal cache location of emsdk/upstream/emscripten/cache?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants