compiler/runtime: add llgo:tls and llgo:gls variable storage#2076
Closed
cpunion wants to merge 2 commits into
Closed
compiler/runtime: add llgo:tls and llgo:gls variable storage#2076cpunion wants to merge 2 commits into
cpunion wants to merge 2 commits into
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Collaborator
Author
|
Closing this draft because the implementation branch must live in the contributor fork. The local work is retained and a replacement draft PR will be opened from cpunion/llgo after local CI and coverage verification. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
PR #2074 consolidates per-goroutine runtime state behind
getg, butgetgstill uses the generic pthread-key TLS handle. That path performspthread_getspecificon access and allocates a separate slot on first use. LLGo also has no first-class package-variable model for thread-owned versus goroutine-owned state.Without this PR, runtime code must keep hand-written TLS handles, dynamic local initializers cannot follow package initialization semantics, pointer-bearing native TLS has no compiler-managed GC lifetime, and cross-package/cache builds cannot preserve locality metadata.
Proposal
The proposal is tracked in #2077. It adds:
//llgo:tls//llgo:glsgTLS and GLS intentionally remain distinct in compiler and cache metadata even though the current one-pthread-per-goroutine runtime lowers both to native TLS.
currentGis TLS because it bootstraps future GLS lookup.Implementation
go:linkname, LLGo type/locality, and export comment parsing behind one directive parser. The normal build scans each package object once during preload; the direct compiler entry point only performs the fallback scan when needed.init, including variables whose names sort afterinit, so initial-thread side effects cannot run twice.nogcbuilds use a no-op registration function.getgfromtls.Alloc[g]to//llgo:tls var currentG g. Unsupported cross/embedded targets report a compile-time diagnostic.Verification
All local commands used
GOMAXPROCS=2,GOMEMLIMIT=2GiB, and-p=1.go test -timeout=45m ./...passed, includingcl,internal/build,internal/cabi,ssa,test/go, GOROOT, and std wrapper tests.cl95.0%,internal/build71.0%,ssa87.9%.tlsglsacceptance test covers cross-package TLS/GLS access, independent main/two-goroutine values, dynamic and recursive initialization, panic poisoning, a late-sorted initializer, GC pointer survival, and thread-exit cleanup.-tags=nogc.tlsgls/state; the second build reportsCACHE HITand produces identical output. The main package remains a cache miss by existing policy.getgresolves native TLV addresses and checks the local guard; its hot path has nopthread_getspecificand no heap-backed TLS slot.Stack
This draft is stacked on #2074 (
codex/runtime-g-state). The base branch inxgo-devmirrors the current #2074 head and will be replaced withmainafter #2074 merges. Darwin and Linux CI must both pass before it is ready for review.