Repository navigation
Closed as not planned
Closed as not planned
Copy link
Labels
A-linkersArea: linkers... you gotta love linkersA-lldArea: Linkage issues specific to rust-lldA-target-featureArea: Enabling/disabling target features like AVX, Neon, etc.C-bugCategory: This is a bug.O-wasiOperating system: Wasi, Webassembly System InterfaceP-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
Description
Code
I tried this code:
/// hashset.rs
use std::collections::HashSet;
fn main() {
let mut seen = HashSet::new();
assert!(seen.insert(1_u32));
println!("ok");
}rustc --target wasm32-wasip1 -C target-feature=+atomics -C debuginfo=1 -o hashset.wasm hashset.rs && wasmtime hashset.wasmI expected to see this happen: It should compile and run fine, printing ok.
Instead, this happened: It compiled, but wasmtime failed with the following error:
Error: failed to run main module `hashset.wasm`
Caused by:
0: failed to invoke command default
1: error while executing at wasm backtrace:
0: 0x2925 - hashset.wasm!<std[7c0a0f0b853524cc]::hash::random::RandomState>::new::KEYS::{K#0}::{closure#1}
1: 0x48c1 - hashset.wasm!<<std[7c0a0f0b853524cc]::hash::random::RandomState>::new::KEYS::{K#0}::{closure#1} as core[f19747029855e5e6]::ops::function::FnOnce<(core[f19747029855e5e6]::option::Option<&mut core[f19747029855e5e6]::option::Option<core[f19747029855e5e6]::cell::Cell<(u64, u64)>>>,)>>::call_once
2: 0x809 - hashset.wasm!<std[7c0a0f0b853524cc]::thread::local::LocalKey<core[f19747029855e5e6]::cell::Cell<(u64, u64)>>>::try_with::<<std[7c0a0f0b853524cc]::hash::random::RandomState>::new::{closure#0}, std[7c0a0f0b853524cc]::hash::random::RandomState>
3: 0x799 - hashset.wasm!<std[7c0a0f0b853524cc]::thread::local::LocalKey<core[f19747029855e5e6]::cell::Cell<(u64, u64)>>>::with::<<std[7c0a0f0b853524cc]::hash::random::RandomState>::new::{closure#0}, std[7c0a0f0b853524cc]::hash::random::RandomState>
4: 0x2bcf - hashset.wasm!<std[7c0a0f0b853524cc]::collections::hash::set::HashSet<u32>>::new
5: 0x2b2f - hashset.wasm!hashset[ef672965bf494934]::main
6: 0x239b - hashset.wasm!<fn() as core[f19747029855e5e6]::ops::function::FnOnce<()>>::call_once
7: 0x236f - hashset.wasm!std[7c0a0f0b853524cc]::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>
8: 0x28e1 - hashset.wasm!std[7c0a0f0b853524cc]::rt::lang_start::<()>::{closure#0}
9: 0x6cfc - hashset.wasm!std[7c0a0f0b853524cc]::rt::lang_start_internal
10: 0x2135 - hashset.wasm!std[7c0a0f0b853524cc]::rt::lang_start::<()>
11: 0x48f0 - hashset.wasm!__main_void
12: 0x42e - hashset.wasm!_start
note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable may show more debugging information
2: memory fault at wasm address 0x2048e0 in linear memory of size 0x110000
3: wasm trap: out of bounds memory access
Version it worked on
It most recently worked on: Rust 1.99.1 + wasmtime-cli 51.0.0
Version with regression
wasmtime-cli 51.0.0 + rustc --version --verbose:
rustc 1.100.0 (0ef1bc386 2026-11-09)
binary: rustc
commit-hash: 0ef1bc386059596dada8fb65b50425aab2ea637a
commit-date: 2026-11-09
host: x86_64-unknown-linux-gnu
release: 1.100.0
LLVM version: 23.1.5
wasmtime-cli 51.0.0 + rustc --version --verbose:
rustc 1.102.0-nightly (6905905bb 2026-11-19)
binary: rustc
commit-hash: 6905905bb7727fd0f9223f5fdc9ad4e62236d5a2
commit-date: 2026-11-19
host: x86_64-unknown-linux-gnu
release: 1.102.0-nightly
LLVM version: 23.1.6
Metadata
Metadata
Assignees
Labels
A-linkersArea: linkers... you gotta love linkersA-lldArea: Linkage issues specific to rust-lldA-target-featureArea: Enabling/disabling target features like AVX, Neon, etc.C-bugCategory: This is a bug.O-wasiOperating system: Wasi, Webassembly System InterfaceP-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
Activity
ngg commentedon Nov 21, 2026
The
wasm32-wasip1target switched its TLS implementation in #163809, that caused this regression.I think the actual bug is in the LLD linker, I'm opening an issue for them as well, along with a potential fix PR.
maxdexh commentedon Nov 21, 2026
cc @alexcrichton (target maintainer)
(and cc myself as the author of the regressing PR ^^)
I'm not sure what is going on here, I cannot reproduce this manually with a thread local outside of
HashSet?8 remaining items
maxdexh commentedon Nov 21, 2026
Problem also exists on wasip2, but interestingly, not on wasip3? Did the target feature become a default there or something?
bjorn3 commentedon Nov 21, 2026
The reason we allow enabling/disabling the atomics target feature at all is for wasm32-unknown-unknown which doesn't have a corresponding multi-threaded target at all. If you want multi-threaded wasm32-unknown-unknown you have to use
RUSTFLAGS="-Ctarget-feature=+atomics" cargo build -Zbuild-std --target wasm32-unknown-unknown.maxdexh commentedon Nov 21, 2026
FWIW the reason was another regression where thread locals didn't get dropped anymore ^^
also using that implementation was already the plan from another pr, which got partially reverted for wasi due to a bug in the sdk; that partial revert essentially just got reverted with an sdk bump
bjorn3 commentedon Nov 21, 2026
Wasip3 uses cooperative multitasking, so it doesn't actually need atomics. A mutex just does a regular check of the lock flag and if it is already locked, it preempts to allow another thread to run. And for tls it doesn't use the regular tool convention for tls accesses, but rather inserts calls to something defined by wasi-libc as part of the cooperative multitasking implementation I believe.
bjorn3 commentedon Nov 21, 2026
Avoiding the no-thread implementation on wasm32-wasip1-threads makes sense. I just don't understand why it is avoided on all wasi targets now, not just those that support threads.
maxdexh commentedon Nov 21, 2026
I guess that sounds reasonable. We can partial-revert the revert from #163809 to unrevert the partial revert of #159733 from #160868.
More comprehensibly, bring back wasip1 and wasip2 to the state before #159733, while leaving wasip1-threads and wasip3 as they are?
@rustbot claim
rustbot commentedon Nov 22, 2026
Assigning P-medium (discussion on Zulip)
maxdexh commentedon Nov 23, 2026
Per discussion with @alexcrichton, closing this as intended breakage (or rather, as "was never supposed to work").
We should make
target-feature=+atomica target modifier so that rebuiling std becomes required.