Skip to content
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

Minimal wasm with certain system library methods #6569

Closed
chrjohnson opened this issue May 22, 2018 · 4 comments
Closed

Minimal wasm with certain system library methods #6569

chrjohnson opened this issue May 22, 2018 · 4 comments
Labels

Comments

@chrjohnson
Copy link

chrjohnson commented May 22, 2018

I would like to have Emscripten build a wasm file with just my functions plus just the standard library methods that I ask for (malloc, free). It’s alright if it builds a JS file but I would like to be able to ignore that file and handle all the javascript myself like in the MDN articles like this: https://developer.mozilla.org/en-US/docs/WebAssembly/Loading_and_running

SIDE_MODULE almost meets my needs. it’s almost just my methods (other than things like__post_instantiate, runPostSets, some globals, etc) and there is no js file created. I can do the javascript myself but I can’t seem to find a way to get it to include things like malloc.

SIDE_MODULE is for use with MAIN_MODULE and the main module is the one expected to have the system libraries so this makes sense not being able to include them in the side_module build.

I’ve tried using ONLY_MY_CODE with -O1 and that gets me even closer than SIDE_MODULE does because it doesn’t have the methods like __post_instantiate and runPostSets but I still can’t seem to get it to include portions of the standard library like malloc.

Is there a flag that I’m missing or is it simply not possible to have just my methods in the wasm, no js file (or at least one that I can ignore), and just specific standard library methods like malloc and free?

@kripken
Copy link
Member

kripken commented May 22, 2018

You can include malloc in SIDE_MODULE by including it manually: add dlmalloc.c (under the system/ dir) to the list of files you are compiling. Then malloc is just more code that you are compiling, no different from the code you wrote yourself.

Another option is to rely on metadce to remove the runtime, see https://github.com/kripken/emscripten/wiki/WebAssembly-Standalone#let-the-optimizer-remove-the-runtime . Whether that does what you want or not depends on the input files and whether the system libraries you link to require JS or not. But it would include malloc for you automatically (unless it can see malloc is never used anywhere, and it optimizes it out).

@chrjohnson
Copy link
Author

Looking at the .wast file and including dlmalloc.c gives the exports for _free and _malloc (exactly what I'm looking for)

It expects imports for ___errno_location and _sbrk. I'm not sure what to set for these. Am I missing a file perhaps?

@kripken
Copy link
Member

kripken commented Jan 28, 2019

Those arrive from JS library support, I belive, see library.js. They are not included in a side module though, since we don't link in system libraries there.

@stale
Copy link

stale bot commented Jan 28, 2020

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.

@stale stale bot added the wontfix label Jan 28, 2020
@stale stale bot closed this as completed Feb 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants