Skip to content

Unable to create wasm32-wasi staticlib without libc #102255

Closed
@anuraaga

Description

@anuraaga

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions