Skip to content

fix(wasi): use mock TLS for all non-threaded WASI targets - #378

Draft
aryansk wants to merge 2 commits into
apple:release/1.8.xfrom
aryansk:codex/swift-system-370-wasi-pthread-gate
Draft

fix(wasi): use mock TLS for all non-threaded WASI targets#378
aryansk wants to merge 2 commits into
apple:release/1.8.xfrom
aryansk:codex/swift-system-370-wasi-pthread-gate

Conversation

@aryansk

@aryansk aryansk commented Aug 11, 2026

Copy link
Copy Markdown

Summary

Gates mock TLS on WASI solely on !_runtime(_multithreaded) rather than swift(<6.1) || !_runtime. On Swift 6.1+ standard WASI toolchains the old gate falls into the #else branch, which assumes POSIX pthread_key_t / pthread_* . Standard WASI libc does not expose those symbols for the non-threaded target, producing scope-resolution failures:

Sources/System/Internals/Exports.swift:221:14: cannot find 'pthread_key_create' in scope
Sources/System/Internals/Exports.swift:233:14: cannot find 'pthread_setspecific' in scope

With the fix, non-threaded WASI always uses the mock _PlatformTLSKey/dictionary store and pthread paths are reserved for threaded WASI, regardless of Swift version.

Issue

Fixes #370[WASI] Compilation failure on Swift 6.1+ due to missing pthread symbols.

Validation

  • git diff --check passes
  • Two-line change in Exports.swift (typealias and makeTLSKey)

glessard and others added 2 commits August 6, 2026 09:52
The gate os(WASI) && (swift(<6.1) || !_runtime) incorrectly falls
through to pthread APIs on Swift 6.1+ non-threaded WASI, where
pthread_* is not in scope. Guard solely on !_runtime.

Fixes apple#370
@glessard

Copy link
Copy Markdown
Contributor

@aryansk Could you retarget this PR to the release/1.8.x branch? This is clearly a bug fix.

@aryansk
aryansk changed the base branch from main to release/1.8.x August 12, 2026 05:27
@aryansk

aryansk commented Aug 12, 2026

Copy link
Copy Markdown
Author

Done — I retargeted this PR to release/1.8.x; it remains Draft while the branch-specific checks run.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[WASI] Compilation failure on Swift 6.1+ due to missing pthread symbols in WASI toolchains

2 participants