]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: save/restore g unconditionally on darwin/arm64
authorCherry Zhang <cherryyz@google.com>
Sat, 24 Oct 2020 20:29:26 +0000 (16:29 -0400)
committerCherry Zhang <cherryyz@google.com>
Wed, 28 Oct 2020 13:46:11 +0000 (13:46 +0000)
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>
src/runtime/asm_arm64.s
src/runtime/sys_darwin_arm64.s
src/runtime/tls_arm64.s

index 6257c1a183c066096096bed86f728d0b2438d6fb..a09172f0c964dc3d2d52e068aaf67bfdd8b39931 100644 (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.
index 31b997df135f71ac5a9972c99c4d3ebb7c8a7994..fd713b7902f7d65347a7255aabc70d08e36f47c6 100644 (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)
 
index 7846fac6c5cf837d10996812cd1e94041e3c3ab7..701abae105de302a119e38eff361205685523be5 100644 (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