runtime: save/restore g unconditionally on darwin/arm64

Now that we always have TLS set up, we can always save the G
register, regardless of whether cgo is used. This makes pure Go
programs signal-safe.

Updates #38485.

Change-Id: Icbc69acf0e2a5652fbcbbd074258a1a5efe87f1a
Reviewed-on: https://go-review.googlesource.com/c/go/+/265119
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Joel Sing <joel@sing.id.au>
This commit is contained in:
Cherry Zhang 2020-10-24 16:29:26 -04:00
parent 72dec90bfd
commit a0a44397e9
3 changed files with 6 additions and 7 deletions

View File

@ -977,10 +977,7 @@ TEXT ·cgocallback(SB),NOSPLIT,$24-24
NO_LOCAL_POINTERS
// Load g from thread-local storage.
MOVB runtime·iscgo(SB), R3
CBZ R3, nocgo
BL runtime·load_g(SB)
nocgo:
// If g is nil, Go did not create the current thread.
// Call needm to obtain one for temporary use.

View File

@ -197,9 +197,6 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$192
// this might be called in external code context,
// where g is not set.
MOVB runtime·iscgo(SB), R0
CMP $0, R0
BEQ 2(PC)
BL runtime·load_g(SB)
#ifdef GOOS_ios
@ -381,7 +378,8 @@ TEXT runtime·mstart_stub(SB),NOSPLIT,$160
FMOVD F14, 144(RSP)
FMOVD F15, 152(RSP)
MOVD m_g0(R0), g
MOVD m_g0(R0), g
BL ·save_g(SB)
BL runtime·mstart(SB)

View File

@ -9,8 +9,10 @@
#include "tls_arm64.h"
TEXT runtime·load_g(SB),NOSPLIT,$0
#ifndef TLS_darwin
MOVB runtime·iscgo(SB), R0
CBZ R0, nocgo
#endif
MRS_TPIDR_R0
#ifdef TLS_darwin
@ -25,8 +27,10 @@ nocgo:
RET
TEXT runtime·save_g(SB),NOSPLIT,$0
#ifndef TLS_darwin
MOVB runtime·iscgo(SB), R0
CBZ R0, nocgo
#endif
MRS_TPIDR_R0
#ifdef TLS_darwin