From a0a44397e91055cb92d5a69e3851d628a7227971 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Sat, 24 Oct 2020 16:29:26 -0400 Subject: [PATCH] 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 Run-TryBot: Cherry Zhang TryBot-Result: Go Bot Reviewed-by: Austin Clements Reviewed-by: Joel Sing --- src/runtime/asm_arm64.s | 3 --- src/runtime/sys_darwin_arm64.s | 6 ++---- src/runtime/tls_arm64.s | 4 ++++ 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/runtime/asm_arm64.s b/src/runtime/asm_arm64.s index 6257c1a183..a09172f0c9 100644 --- a/src/runtime/asm_arm64.s +++ b/src/runtime/asm_arm64.s @@ -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. diff --git a/src/runtime/sys_darwin_arm64.s b/src/runtime/sys_darwin_arm64.s index 31b997df13..fd713b7902 100644 --- a/src/runtime/sys_darwin_arm64.s +++ b/src/runtime/sys_darwin_arm64.s @@ -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) diff --git a/src/runtime/tls_arm64.s b/src/runtime/tls_arm64.s index 7846fac6c5..701abae105 100644 --- a/src/runtime/tls_arm64.s +++ b/src/runtime/tls_arm64.s @@ -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 -- 2.48.1