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

wasm automatically links and re-exports all of libc #7133

Closed
fengb opened this issue Nov 16, 2020 · 6 comments · Fixed by #10517
Closed

wasm automatically links and re-exports all of libc #7133

fengb opened this issue Nov 16, 2020 · 6 comments · Fixed by #10517
Labels
arch-wasm 32-bit and 64-bit WebAssembly
Milestone

Comments

@fengb
Copy link
Contributor

fengb commented Nov 16, 2020

$ zig build-lib empty.zig -OReleaseSmall -target wasm32-freestanding

$ ls -l empty.*
-rwxr-xr-x  1 fengb  staff  48776 Nov 16 12:06 empty.wasm
-rw-r--r--  1 fengb  staff      0 Nov 16 12:06 empty.zig

$ twiggy top empty.wasm 
 Shallow Bytes │ Shallow % │ Item
───────────────┼───────────┼────────────────────────────────────────────────
          4255 ┊     8.72% ┊ data[0]
          2851 ┊     5.85% ┊ "function names" subsection
          1884 ┊     3.86% ┊ __divtf3
          1477 ┊     3.03% ┊ compiler_rt.addXf3.addXf3.27
          1384 ┊     2.84% ┊ __multf3
           941 ┊     1.93% ┊ __divdf3
           879 ┊     1.80% ┊ compiler_rt.udivmod.udivmod.64
           864 ┊     1.77% ┊ fma
           803 ┊     1.65% ┊ __muldf3
           778 ┊     1.60% ┊ compiler_rt.addXf3.addXf3.26
           767 ┊     1.57% ┊ __udivmoddi4
           675 ┊     1.38% ┊ __divsf3
           639 ┊     1.31% ┊ compiler_rt.addXf3.addXf3
           592 ┊     1.21% ┊ __mulsf3
           551 ┊     1.13% ┊ sqrt
           519 ┊     1.06% ┊ fmod
           512 ┊     1.05% ┊ expf
[...]
@fengb
Copy link
Contributor Author

fengb commented Nov 16, 2020

I think we need to apply this to the new stage2 code: #2369

@LemonBoy
Copy link
Contributor

#2910 ?

@fengb
Copy link
Contributor Author

fengb commented Nov 16, 2020

Alternatively, would it make sense to enable build-exe for wasm32-freestanding? It doesn't work right now because it expects main.

@andrewrk andrewrk added the arch-wasm 32-bit and 64-bit WebAssembly label Nov 16, 2020
@andrewrk andrewrk added this to the 0.8.0 milestone Nov 16, 2020
@andrewrk
Copy link
Member

Alternatively, would it make sense to enable build-exe for wasm32-freestanding? It doesn't work right now because it expects main.

Let's explore this- without diving back into wasm stuff I recall that I was trying to avoid adding the logic from #2369 because it would require maintaining more in-memory data with regards to incremental compilation.

@zigazeljko
Copy link
Contributor

There is an easier way. From LLD documentation:

When building an executable, only the entry point (_start) and symbols with the WASM_SYMBOL_EXPORTED flag are exported by default. In LLVM the WASM_SYMBOL_EXPORTED flag is set by the wasm-export-name attribute which in turn can be set using __attribute__((export_name)) clang attribute.

In practice, we would need to add this attribute to all exported functions, except when compiling libc and other internal libraries.

@matthewp
Copy link

Can someone provide a breakdown of what needs to be done to fix this issue? I'd possibly like to contribute here. Context is I'm writing a compiler, currently in C but would prefer it be with Zig, and wasm is my core target. This is a blocker because file size is extremely important in the browser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm 32-bit and 64-bit WebAssembly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants