Skip to content

Failed to compile code targetting wasm32-wasip2 with +atomics,+bulk-memory,+mutable-globals enabled #140971

Open
@aryan9600

Description

@aryan9600

I created a new minimal rust library with crate-type set to cdylib.

pub extern "C" fn add(left: u64, right: u64) -> u64 {
    left + right
}

Compiling this against the wasm32-unknown-unknown target works okay:

❯ RUSTFLAGS='-C target-feature=+atomics,+bulk-memory,+mutable-globals' cargo +nightly build --target wasm32-unknown-unknown -Z build-std=std,panic_abort
   Compiling compiler_builtins v0.1.158
   Compiling core v0.0.0 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core)
   Compiling libc v0.2.172
   Compiling object v0.36.7
   Compiling std v0.0.0 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std)
   Compiling rustc-std-workspace-core v1.99.0 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/rustc-s
td-workspace-core)
   Compiling alloc v0.0.0 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc)
   Compiling cfg-if v1.0.0
   Compiling adler2 v2.0.0
   Compiling memchr v2.7.4
   Compiling rustc-demangle v0.1.24
   Compiling unwind v0.0.0 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/unwind)
   Compiling dlmalloc v0.2.8
   Compiling rustc-std-workspace-alloc v1.99.0 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/rustc-
std-workspace-alloc)
   Compiling panic_abort v0.0.0 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/panic_abort)
   Compiling panic_unwind v0.0.0 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/panic_unwind)
   Compiling gimli v0.31.1
   Compiling hashbrown v0.15.3
   Compiling miniz_oxide v0.8.8
   Compiling std_detect v0.1.5 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/stdarch/crates/std_det
ect)
   Compiling addr2line v0.24.2
   Compiling rustc-std-workspace-std v1.99.0 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/rustc-st
d-workspace-std)
   Compiling rustc-literal-escaper v0.0.2
   Compiling proc_macro v0.0.0 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/proc_macro)
   Compiling wasm-ex v0.1.0 (/Users/sanskarjaiswal/Development/wasm-ex)
warning: unstable feature specified for `-Ctarget-feature`: `atomics`
  |
  = note: this feature is not stably supported; its behavior can change in the future

warning: `wasm-ex` (lib) generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 7.05s

Compiling this against the wasm32-wasip2 target fails:

❯ RUSTFLAGS='-C target-feature=+atomics,+bulk-memory,+mutable-globals' cargo +nightly build --target wasm32-wasip2 -Z build-std=std,panic_abort
   Compiling compiler_builtins v0.1.158
   Compiling core v0.0.0 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core)
   Compiling libc v0.2.172
   Compiling object v0.36.7
   Compiling std v0.0.0 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std)
   Compiling rustc-std-workspace-core v1.99.0 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/rustc-s
td-workspace-core)
   Compiling alloc v0.0.0 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc)
   Compiling cfg-if v1.0.0
   Compiling memchr v2.7.4
   Compiling adler2 v2.0.0
   Compiling rustc-demangle v0.1.24
   Compiling unwind v0.0.0 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/unwind)
   Compiling rustc-std-workspace-alloc v1.99.0 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/rustc-
std-workspace-alloc)
   Compiling panic_unwind v0.0.0 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/panic_unwind)
   Compiling panic_abort v0.0.0 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/panic_abort)
   Compiling gimli v0.31.1
   Compiling std_detect v0.1.5 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/stdarch/crates/std_det
ect)
   Compiling miniz_oxide v0.8.8
   Compiling wasi v0.11.0+wasi-snapshot-preview1
   Compiling hashbrown v0.15.3
   Compiling addr2line v0.24.2
   Compiling rustc-std-workspace-std v1.99.0 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/rustc-st
d-workspace-std)
   Compiling rustc-literal-escaper v0.0.2
   Compiling proc_macro v0.0.0 (/Users/sanskarjaiswal/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/proc_macro)
   Compiling wasm-ex v0.1.0 (/Users/sanskarjaiswal/Development/wasm-ex)
warning: unstable feature specified for `-Ctarget-feature`: `atomics`
  |
  = note: this feature is not stably supported; its behavior can change in the future

error: linking with `wasm-component-ld` failed: exit status: 1
  |
  = note:  "wasm-component-ld" "-flavor" "wasm" "--shared-memory" "--max-memory=1073741824" "--import-memory" "--export" "cabi_realloc" "-z" "stack-size=
1048576" "--stack-first" "--allow-undefined" "--no-demangle" "<2 object files omitted>" "/Users/sanskarjaiswal/Development/wasm-ex/target/wasm32-wasip2/d
ebug/deps/{libstd-e6974f8339de980a.rlib,libpanic_abort-ef7c973c0f49a7b3.rlib,libwasi-d76f2b70906af1dc.rlib,librustc_demangle-a2b444bfd261b1c6.rlib,libstd
_detect-24d3b7f99da05399.rlib,libhashbrown-555fa83f2da96374.rlib,librustc_std_workspace_alloc-418c90a8abd2c0b2.rlib,libminiz_oxide-f1056162f1d389fb.rlib,
libadler2-bfe5e6d99ec23333.rlib,libunwind-4e1cf59691c85b76.rlib,libcfg_if-6422f5890fdf1c76.rlib,liblibc-460067f0d0fac4f8.rlib}.rlib" "-l" "c" "/Users/san
skarjaiswal/Development/wasm-ex/target/wasm32-wasip2/debug/deps/{liballoc-7516e5ef0d2d3fa4.rlib,librustc_std_workspace_core-b2e3c419616fe115.rlib,libcore
-c67d6fd40cbf0c22.rlib,libcompiler_builtins-c030ab949e2d2444.rlib}.rlib" "-L" "<sysroot>/lib/rustlib/wasm32-wasip2/lib/self-contained" "-o" "/Users/sansk
arjaiswal/Development/wasm-ex/target/wasm32-wasip2/debug/deps/wasm_ex.wasm" "--gc-sections" "--no-entry" "-O0"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: rust-lld: error: --shared-memory is disallowed by dlmalloc.o because it was not compiled with 'atomics' or 'bulk-memory' features.
          rust-lld: error: /Users/sanskarjaiswal/Development/wasm-ex/target/wasm32-wasip2/debug/deps/libstd-e6974f8339de980a.rlib(std-e6974f8339de980a.st
d.4ded6a7c9b80894f-cgu.09.rcgu.o): relocation R_WASM_MEMORY_ADDR_TLS_SLEB cannot be used against non-TLS symbol `errno`
          rust-lld: error: /Users/sanskarjaiswal/Development/wasm-ex/target/wasm32-wasip2/debug/deps/libstd-e6974f8339de980a.rlib(std-e6974f8339de980a.st
d.4ded6a7c9b80894f-cgu.09.rcgu.o): relocation R_WASM_MEMORY_ADDR_TLS_SLEB cannot be used against `errno` in non-TLS section: .bss
          rust-lld: error: /Users/sanskarjaiswal/Development/wasm-ex/target/wasm32-wasip2/debug/deps/libstd-e6974f8339de980a.rlib(std-e6974f8339de980a.st
d.4ded6a7c9b80894f-cgu.09.rcgu.o): relocation R_WASM_MEMORY_ADDR_TLS_SLEB cannot be used against non-TLS symbol `errno`
          rust-lld: error: /Users/sanskarjaiswal/Development/wasm-ex/target/wasm32-wasip2/debug/deps/libstd-e6974f8339de980a.rlib(std-e6974f8339de980a.st
d.4ded6a7c9b80894f-cgu.09.rcgu.o): relocation R_WASM_MEMORY_ADDR_TLS_SLEB cannot be used against `errno` in non-TLS section: .bss
          error: failed to invoke LLD: exit status: 1

the error message is complaining about dlmalloc.o not being compiled with the atomics and bulk-memory features for some reason.
interestingly, we see that for the wasm32-unknown-unknown target, the compiler pulls dlmalloc. but for the wasm32-wasip2 target, dlmalloc is not being pulled and yet the compiler complains about dlmalloc.

Meta

rustc --version --verbose:

❯ rustc --version --verbose
rustc 1.89.0-nightly (ce7e97f73 2025-05-11)
binary: rustc
commit-hash: ce7e97f7371af47e0786f74aa169f6ac9473ff4e
commit-date: 2025-05-11
host: aarch64-apple-darwin
release: 1.89.0-nightly
LLVM version: 20.1.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionCategory: Discussion or questions that doesn't represent real issues.O-wasm32-wasip2Target: wasm32-wasip2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions