Skip to content

Fix TLS on wasi, again again - #166367

Closed
maxdexh wants to merge 1 commit into
rust-lang:mainfrom
maxdexh:wasiiiiiiiiiiiiiiiiiiiiiiii
Closed

maxdexh wants to merge 1 commit into
rust-lang:mainfrom
maxdexh:wasiiiiiiiiiiiiiiiiiiiiiiii

Conversation

@maxdexh

@maxdexh maxdexh commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Fixes #166314

This effectively reverts the cfg changes from #163809.
Instead, the issue originally fixed by that PR (#163748) is fixed as originally suggested: By adding back the carve-out for wasip1-threads that was originally removed by accident in the #159733+#160868 combo.

The diff vs the state after #160868 is this change to the guard and key cfgs, respectively:

-            all(target_family = "wasm", not(target_env = "p3")),
+            all(
+                target_family = "wasm",
+                not(all(
+                    target_os = "wasi",
+                    any(target_env = "p3", all(target_env = "p1", target_feature = "atomics")),
+                )),
+            ),
-            all(target_os = "wasi", target_env = "p3"),
+            all(
+                target_os = "wasi",
+                any(target_env = "p3", all(target_env = "p1", target_feature = "atomics")),
+            ),

r? @alexcrichton

@rustbot rustbot added A-thread Area: `std::thread` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 22, 2026
@maxdexh
maxdexh force-pushed the wasiiiiiiiiiiiiiiiiiiiiiiii branch from f773045 to 1a04589 Compare November 22, 2026 19:56
@rust-log-analyzer

This comment has been minimized.

@maxdexh
maxdexh force-pushed the wasiiiiiiiiiiiiiiiiiiiiiiii branch 2 times, most recently from 8124dfc to 148a349 Compare November 22, 2026 22:25
@maxdexh
maxdexh force-pushed the wasiiiiiiiiiiiiiiiiiiiiiiii branch from 148a349 to 3d000b7 Compare November 22, 2026 22:26
@alexcrichton

Copy link
Copy Markdown
Member

I don't think that this is correct, the intention is that wasip1/wasip2/wasip3 all use the same code for TLS, there's nothing special amongst them. Ideally wasip1-threads would too, but I'm not a maintainer for that target so I'm not going to proactively try to unify it.

In the linked issue bjorn3 is correct, the +atomics feature should probably be a target modifier so recompiling your own crates without recompiling the standard library was never supposed to work. If it happened to work then that's just accidentally. I'll caution that in general +atomics is pretty unstable in Rust and does not work well, as you're seeing here.

@maxdexh

maxdexh commented Nov 23, 2026 •

Copy link
Copy Markdown
Member Author

the intention is that wasip1/wasip2/wasip3 all use the same code for TLS, there's nothing special amongst them.

My intention when I wrote #163809 was just to fix the regression, without adding any new ones; apparently we had different intentions then ^^

In the linked issue bjorn3 is correct, the +atomics feature should probably be a target modifier so recompiling your own crates without recompiling the standard library was never supposed to work.

Alright, should we close the issue as intended breakage then?

@maxdexh maxdexh closed this Nov 23, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 23, 2026
@alexcrichton

Copy link
Copy Markdown
Member

Personally, yeah, I think it'd be reasonable to close

@bjorn3

bjorn3 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

I don't think that this is correct, the intention is that wasip1/wasip2/wasip3 all use the same code for TLS

Wouldn't plain statics be more efficient on the targets where there are guaranteed to not be threads? But indeed this PR shouldn't be necessary for correctness with the target modifier in place.

@alexcrichton

Copy link
Copy Markdown
Member

On wasip1/wasip2 LLVM should already handle that, effectively lowering thread_local values to statics. I additionally don't want to impose a large maintenace burden on the standard library for these targets and would prefer to have them all treated mostly uniformly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-thread Area: `std::thread` T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression on wasm32-wasip1 with +atomics target feature when accessing TLS

5 participants