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.
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
-nostdlib
and iwasm+builtin-libc. please refer to https://github.com/bytecodealliance/wasm-micro-runtime/blob/9ed26404d5f0f5b76c803228d58ad0fd5ac64248/doc/build_wasm_app.md#2-how-to-reduce-the-footprint.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?
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.
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
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?
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/dylinkThanks 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
Last updated: Nov 26 2024 at 00:12 UTC