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

Unable to create wasm32-wasi staticlib without libc #102255

Closed
anuraaga opened this issue Sep 25, 2022 · 1 comment
Closed

Unable to create wasm32-wasi staticlib without libc #102255

anuraaga opened this issue Sep 25, 2022 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@anuraaga
Copy link

I am trying to build rust code as a library to link into a WebAssembly program. The linking happens completely outside the context of Rust using LLVM's wasm-ld.

The project is at https://github.com/anuraaga/coraza-wasm-filter

git clone https://github.com/anuraaga/coraza-wasm-filter
docker build -t buildtools-aho-corasick buildtools/aho-corasick
docker run -it --rm buildtools-aho-corasick ash
ar t target/wasm32-wasi/release/libaho_corasick.a

(The code including the patch applied by the Dockerfile is at https://github.com/anuraaga/aho-corasick/tree/wasi-build)

I expected to see this happen: libc is not included in the archive

Instead, this happened: libc is included in the archive

Either with or without crt-static, libc is included. When I try to actually link into the WebAssembly program, symbols like malloc cause duplicate symbol errors.

#72274 seems to be related - given the checkboxes, my understanding is rust was already fixed to not bundle in libc for static archives to allow linking the library with libc later. Should it be enough to set RUSTFLAGS "-C target-feature=-crt-static" to get a static library without libc?

Meta

rustc --version --verbose:

rustc 1.64.0 (a55dd71d5 2022-09-19)
binary: rustc
commit-hash: a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52
commit-date: 2022-09-19
host: aarch64-unknown-linux-musl
release: 1.64.0
LLVM version: 14.0.6
@anuraaga anuraaga added the C-bug Category: This is a bug. label Sep 25, 2022
@anuraaga
Copy link
Author

After looking closer at the symbols, I realized the libc I was seeing is the rust libc crate, not libc itself. The duplicate symbols were triggered by adding the rust library but were not actually because of it, so no problem. Sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

1 participant