Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: always set up TLS on all G-register architectures? #35853

cherrymui opened this issue Nov 26, 2019 · 2 comments

runtime: always set up TLS on all G-register architectures? #35853

cherrymui opened this issue Nov 26, 2019 · 2 comments


Copy link

@cherrymui cherrymui commented Nov 26, 2019

Currently, on G-register architectures (i.e. all non-x86), we set up TLS only when cgo is used, by libc. The reason is probably that the G register is reserved in Go code and so it should always be valid. However, there are more and more cases where we call external functions even in a non-cgo program, for example, VDSO, and libc calls on darwin. These external functions could potentially clobbers the G register temporarily. If a signal is received during the execution of an external function, we cannot directly use the G register's content as the G. This has caused a number of problems. Currently we play various tricks and workarounds. See e.g. #32912, #34391, #35800.

Maybe we should consider initializing TLS ourselves in non-cgo programs, and always save/restore G in TLS across external calls? This way, we unify the cgo and non-cgo code paths, and can remove various workarounds and maybe potential problems.

@cherrymui cherrymui added this to the Go1.15 milestone Nov 26, 2019
Copy link

@gopherbot gopherbot commented Nov 27, 2019

Change mentions this issue: runtime: always set up TLS storage for darwin/arm64

Copy link

@odeke-em odeke-em commented May 31, 2020

We didn't cover ground for Go1.15, and Elias ran out of time in CL 209197, thus I shall move this issue to Go1.16.

@odeke-em odeke-em modified the milestones: Go1.15, Go1.16 May 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.