Stream: wamr

Topic: Reducing WASM module sizes (libc options)


view this post on Zulip Stephen Berard (Oct 16 2023 at 15:04):

Hello. I'm looking for ways to reduce the size of my WASM executables (C with clang). I know that I can use the built-in libc and I've successfully reduced my hello world app to about 300 bytes (using -nostdlib). If I don't use that option, it ballons to 36k. I assume that it's because it's linking in libc into my WASM executable. What I'm wondering if there is a way to compile w/o libc and then reference the libc separately and share it for all of the WASM modules I run. That way my WASM executables are as small as possible.

view this post on Zulip lum1n0us (Oct 17 2023 at 02:12):

Yes you are right. clang packs libc content(as wasi-libc) into the generation and causes the size gap between w/ and w/o--nostdlib.

There are a few ways to reduce

WebAssembly Registry (Warg). Contribute to bytecodealliance/registry development by creating an account on GitHub.

view this post on Zulip Stephen Berard (Oct 17 2023 at 13:03):

Thanks for the response. That is was I suspected. Another question, is there any way to provide libc via the ---native-lib command line option?

view this post on Zulip lum1n0us (Oct 18 2023 at 00:02):

It might be a good idea. But I've never tried it before. guess it needs to disable all built-ins(WAMR_BUILD_LIBC_XXX) first. Please let us know the experiment result.

view this post on Zulip YAMAMOTO Takashi (Oct 20 2023 at 06:54):

What I'm wondering if there is a way to compile w/o libc and then reference the libc separately and share it for all of the WASM modules I run

recent wasi-libc has a way to build as a shared library.
WAMR has an abandoned branch for the approach. https://github.com/bytecodealliance/wasm-micro-runtime/commits/dev/dylink

WebAssembly Micro Runtime (WAMR). Contribute to bytecodealliance/wasm-micro-runtime development by creating an account on GitHub.

view this post on Zulip Stephen Berard (Nov 06 2023 at 15:35):

YAMAMOTO Takashi said:

recent wasi-libc has a way to build as a shared library.
WAMR has an abandoned branch for the approach. https://github.com/bytecodealliance/wasm-micro-runtime/commits/dev/dylink

Thanks for this. Is there a reason why this was abandoned? Was it because warg/WASI-preview 2 are addressing the underlying need in a different manner?

view this post on Zulip YAMAMOTO Takashi (Nov 08 2023 at 10:59):

Stephen Berard said:

YAMAMOTO Takashi said:

recent wasi-libc has a way to build as a shared library.
WAMR has an abandoned branch for the approach. https://github.com/bytecodealliance/wasm-micro-runtime/commits/dev/dylink

Thanks for this. Is there a reason why this was abandoned? Was it because warg/WASI-preview 2 are addressing the underlying need in a different manner?

i don't know why it has been stalled.
here's the associated issue: https://github.com/bytecodealliance/wasm-micro-runtime/issues/1026

Hi, I commited an experimental shared-everything multi module linking feature recently at dev/link, which based on dynamic linking conventiion. But because the convention was updated during develop...

Last updated: Nov 26 2024 at 00:12 UTC