]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: save/restore callee saved registers in arm64's sigtramp
authorBen Shi <powerman1st@163.com>
Wed, 15 May 2019 02:12:10 +0000 (02:12 +0000)
committerCherry Zhang <cherryyz@google.com>
Mon, 3 Jun 2019 19:02:11 +0000 (19:02 +0000)
ARM64's R19-R29 and F8-F15 are callee saved registers, which
should be saved in the beginning of sigtramp, and restored at
the end.

fixes #31827

Change-Id: I622e03f1a13fec969d3a11b6a303a8a492e02bcd
Reviewed-on: https://go-review.googlesource.com/c/go/+/177045
Run-TryBot: Ben Shi <powerman1st@163.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
misc/cgo/testsanitizers/tsan_test.go
src/runtime/sys_darwin_arm64.s
src/runtime/sys_linux_arm64.s
src/runtime/sys_netbsd_arm64.s
src/runtime/sys_openbsd_arm64.s

index 1d769a98b6e26c7c50473ad8373da45db92d22b5..ec4e0033fb43a4bef1c8f39782e9d8397739325e 100644 (file)
@@ -5,15 +5,11 @@
 package sanitizers_test
 
 import (
-       "runtime"
        "strings"
        "testing"
 )
 
 func TestTSAN(t *testing.T) {
-       if runtime.GOARCH == "arm64" {
-               t.Skip("skipping test; see https://golang.org/issue/25682")
-       }
        t.Parallel()
        requireOvercommit(t)
        config := configure("thread")
index fa6157eba906ddaacb6f9a716f41f45aa8fac57c..79dd009f6fd11abdc26421c7d0a9e586e2b0c2b3 100644 (file)
@@ -41,7 +41,7 @@ TEXT runtime·read_trampoline(SB),NOSPLIT,$0
        MOVD    8(R0), R1       // arg 2 buf
        MOVW    16(R0), R2      // arg 3 count
        MOVW    0(R0), R0       // arg 1 fd
-       BL libc_read(SB)
+       BL      libc_read(SB)
        RET
 
 TEXT runtime·exit_trampoline(SB),NOSPLIT|NOFRAME,$0
@@ -72,7 +72,7 @@ TEXT runtime·mmap_trampoline(SB),NOSPLIT,$0
        MOVD    $-1, R2
        CMP     R0, R2
        BNE     ok
-       BL libc_error(SB)
+       BL      libc_error(SB)
        MOVW    (R0), R1
        MOVD    $0, R0
 ok:
@@ -84,8 +84,8 @@ TEXT runtime·munmap_trampoline(SB),NOSPLIT,$0
        MOVD    8(R0), R1       // arg 2 len
        MOVD    0(R0), R0       // arg 1 addr
        BL      libc_munmap(SB)
-       CMP $0, R0
-       BEQ 2(PC)
+       CMP     $0, R0
+       BEQ     2(PC)
        BL      notok<>(SB)
        RET
 
@@ -145,22 +145,28 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
        BL      (R11)
        RET
 
-TEXT runtime·sigtramp(SB),NOSPLIT,$0
-       // Reserve space for callee-save registers and arguments.
-       SUB     $(8*16), RSP
-
-       // Save callee-save registers.
-       MOVD    R19, (8*4)(RSP)
-       MOVD    R20, (8*5)(RSP)
-       MOVD    R21, (8*6)(RSP)
-       MOVD    R22, (8*7)(RSP)
-       MOVD    R23, (8*8)(RSP)
-       MOVD    R24, (8*9)(RSP)
-       MOVD    R25, (8*10)(RSP)
-       MOVD    R26, (8*11)(RSP)
-       MOVD    R27, (8*12)(RSP)
-       MOVD    g, (8*13)(RSP)
-       MOVD    R29, (8*14)(RSP)
+TEXT runtime·sigtramp(SB),NOSPLIT,$192
+       // Save callee-save registers in the case of signal forwarding.
+       // Please refer to https://golang.org/issue/31827 .
+       MOVD    R19, 8*4(RSP)
+       MOVD    R20, 8*5(RSP)
+       MOVD    R21, 8*6(RSP)
+       MOVD    R22, 8*7(RSP)
+       MOVD    R23, 8*8(RSP)
+       MOVD    R24, 8*9(RSP)
+       MOVD    R25, 8*10(RSP)
+       MOVD    R26, 8*11(RSP)
+       MOVD    R27, 8*12(RSP)
+       MOVD    g, 8*13(RSP)
+       MOVD    R29, 8*14(RSP)
+       FMOVD   F8, 8*15(RSP)
+       FMOVD   F9, 8*16(RSP)
+       FMOVD   F10, 8*17(RSP)
+       FMOVD   F11, 8*18(RSP)
+       FMOVD   F12, 8*19(RSP)
+       FMOVD   F13, 8*20(RSP)
+       FMOVD   F14, 8*21(RSP)
+       FMOVD   F15, 8*22(RSP)
 
        // Save arguments.
        MOVW    R0, (8*1)(RSP)  // sig
@@ -174,9 +180,9 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$0
        BEQ     2(PC)
        BL      runtime·load_g(SB)
 
-       MOVD RSP, R6
-       CMP      $0, g
-       BEQ      nog
+       MOVD    RSP, R6
+       CMP     $0, g
+       BEQ     nog
        // iOS always use the main stack to run the signal handler.
        // We need to switch to gsignal ourselves.
        MOVD    g_m(g), R11
@@ -221,8 +227,14 @@ nog:
        MOVD    (8*12)(RSP), R27
        MOVD    (8*13)(RSP), g
        MOVD    (8*14)(RSP), R29
-
-       ADD $(8*16), RSP
+       FMOVD   (8*15)(RSP), F8
+       FMOVD   (8*16)(RSP), F9
+       FMOVD   (8*17)(RSP), F10
+       FMOVD   (8*18)(RSP), F11
+       FMOVD   (8*19)(RSP), F12
+       FMOVD   (8*20)(RSP), F13
+       FMOVD   (8*21)(RSP), F14
+       FMOVD   (8*22)(RSP), F15
 
        RET
 
@@ -234,7 +246,7 @@ TEXT runtime·sigprocmask_trampoline(SB),NOSPLIT,$0
        MOVD    16(R0), R2      // arg 3 old
        MOVW    0(R0), R0       // arg 1 how
        BL      libc_pthread_sigmask(SB)
-       CMP $0, R0
+       CMP     $0, R0
        BEQ     2(PC)
        BL      notok<>(SB)
        RET
@@ -279,7 +291,7 @@ TEXT runtime·kevent_trampoline(SB),NOSPLIT,$0
        MOVD    $-1, R2
        CMP     R0, R2
        BNE     ok
-       BL libc_error(SB)
+       BL      libc_error(SB)
        MOVW    (R0), R0        // errno
        NEG     R0, R0  // caller wants it as a negative error code
 ok:
@@ -308,60 +320,60 @@ TEXT runtime·sigaltstack_trampoline(SB),NOSPLIT,$0
 // mstart_stub is the first function executed on a new thread started by pthread_create.
 // It just does some low-level setup and then calls mstart.
 // Note: called with the C calling convention.
-TEXT runtime·mstart_stub(SB),NOSPLIT,$0
+TEXT runtime·mstart_stub(SB),NOSPLIT,$160
        // R0 points to the m.
        // We are already on m's g0 stack.
 
        // Save callee-save registers.
-       SUB $144, RSP
-       MOVD R19, 0(RSP)
-       MOVD R20, 8(RSP)
-       MOVD R21, 16(RSP)
-       MOVD R22, 24(RSP)
-       MOVD R23, 32(RSP)
-       MOVD R24, 40(RSP)
-       MOVD R25, 48(RSP)
-       MOVD R26, 56(RSP)
-       MOVD R27, 64(RSP)
-       MOVD g, 72(RSP)
-       FMOVD F8, 80(RSP)
-       FMOVD F9, 88(RSP)
-       FMOVD F10, 96(RSP)
-       FMOVD F11, 104(RSP)
-       FMOVD F12, 112(RSP)
-       FMOVD F13, 120(RSP)
-       FMOVD F14, 128(RSP)
-       FMOVD F15, 136(RSP)
+       MOVD    R19, 8(RSP)
+       MOVD    R20, 16(RSP)
+       MOVD    R21, 24(RSP)
+       MOVD    R22, 32(RSP)
+       MOVD    R23, 40(RSP)
+       MOVD    R24, 48(RSP)
+       MOVD    R25, 56(RSP)
+       MOVD    R26, 64(RSP)
+       MOVD    R27, 72(RSP)
+       MOVD    g, 80(RSP)
+       MOVD    R29, 88(RSP)
+       FMOVD   F8, 96(RSP)
+       FMOVD   F9, 104(RSP)
+       FMOVD   F10, 112(RSP)
+       FMOVD   F11, 120(RSP)
+       FMOVD   F12, 128(RSP)
+       FMOVD   F13, 136(RSP)
+       FMOVD   F14, 144(RSP)
+       FMOVD   F15, 152(RSP)
 
        MOVD    m_g0(R0), g
 
-       BL runtime·mstart(SB)
+       BL      runtime·mstart(SB)
 
        // Restore callee-save registers.
-       MOVD 0(RSP), R19
-       MOVD 8(RSP), R20
-       MOVD 16(RSP), R21
-       MOVD 24(RSP), R22
-       MOVD 32(RSP), R23
-       MOVD 40(RSP), R24
-       MOVD 48(RSP), R25
-       MOVD 56(RSP), R26
-       MOVD 64(RSP), R27
-       MOVD 72(RSP), g
-       FMOVD 80(RSP), F8
-       FMOVD 88(RSP), F9
-       FMOVD 96(RSP), F10
-       FMOVD 104(RSP), F11
-       FMOVD 112(RSP), F12
-       FMOVD 120(RSP), F13
-       FMOVD 128(RSP), F14
-       FMOVD 136(RSP), F15
-       ADD $144, RSP
+       MOVD    8(RSP), R19
+       MOVD    16(RSP), R20
+       MOVD    24(RSP), R21
+       MOVD    32(RSP), R22
+       MOVD    40(RSP), R23
+       MOVD    48(RSP), R24
+       MOVD    56(RSP), R25
+       MOVD    64(RSP), R26
+       MOVD    72(RSP), R27
+       MOVD    80(RSP), g
+       MOVD    88(RSP), R29
+       FMOVD   96(RSP), F8
+       FMOVD   104(RSP), F9
+       FMOVD   112(RSP), F10
+       FMOVD   120(RSP), F11
+       FMOVD   128(RSP), F12
+       FMOVD   136(RSP), F13
+       FMOVD   144(RSP), F14
+       FMOVD   152(RSP), F15
 
        // Go is all done with this OS thread.
        // Tell pthread everything is ok (we never join with this thread, so
        // the value here doesn't really matter).
-       MOVD $0, R0
+       MOVD    $0, R0
 
        RET
 
index 321d74254c6e58f206412d972553223f0688add8..2835b6ca1cb2346c9aac22f39a4b6bd9ee06e608 100644 (file)
@@ -316,7 +316,29 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
        BL      (R11)
        RET
 
-TEXT runtime·sigtramp(SB),NOSPLIT,$24
+TEXT runtime·sigtramp(SB),NOSPLIT,$192
+       // Save callee-save registers in the case of signal forwarding.
+       // Please refer to https://golang.org/issue/31827 .
+       MOVD    R19, 8*4(RSP)
+       MOVD    R20, 8*5(RSP)
+       MOVD    R21, 8*6(RSP)
+       MOVD    R22, 8*7(RSP)
+       MOVD    R23, 8*8(RSP)
+       MOVD    R24, 8*9(RSP)
+       MOVD    R25, 8*10(RSP)
+       MOVD    R26, 8*11(RSP)
+       MOVD    R27, 8*12(RSP)
+       MOVD    g, 8*13(RSP)
+       MOVD    R29, 8*14(RSP)
+       FMOVD   F8, 8*15(RSP)
+       FMOVD   F9, 8*16(RSP)
+       FMOVD   F10, 8*17(RSP)
+       FMOVD   F11, 8*18(RSP)
+       FMOVD   F12, 8*19(RSP)
+       FMOVD   F13, 8*20(RSP)
+       FMOVD   F14, 8*21(RSP)
+       FMOVD   F15, 8*22(RSP)
+
        // this might be called in external code context,
        // where g is not set.
        // first save R0, because runtime·load_g will clobber it
@@ -330,6 +352,28 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$24
        MOVD    R2, 24(RSP)
        MOVD    $runtime·sigtrampgo(SB), R0
        BL      (R0)
+
+       // Restore callee-save registers.
+       MOVD    8*4(RSP), R19
+       MOVD    8*5(RSP), R20
+       MOVD    8*6(RSP), R21
+       MOVD    8*7(RSP), R22
+       MOVD    8*8(RSP), R23
+       MOVD    8*9(RSP), R24
+       MOVD    8*10(RSP), R25
+       MOVD    8*11(RSP), R26
+       MOVD    8*12(RSP), R27
+       MOVD    8*13(RSP), g
+       MOVD    8*14(RSP), R29
+       FMOVD   8*15(RSP), F8
+       FMOVD   8*16(RSP), F9
+       FMOVD   8*17(RSP), F10
+       FMOVD   8*18(RSP), F11
+       FMOVD   8*19(RSP), F12
+       FMOVD   8*20(RSP), F13
+       FMOVD   8*21(RSP), F14
+       FMOVD   8*22(RSP), F15
+
        RET
 
 TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0
index fb5589addfc3795f031e020b796224325dfd39f0..57ded53858612845f8c751146c7aa2e63b76bf83 100644 (file)
@@ -276,7 +276,29 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
        BL      (R11)
        RET
 
-TEXT runtime·sigtramp(SB),NOSPLIT,$24
+TEXT runtime·sigtramp(SB),NOSPLIT,$192
+       // Save callee-save registers in the case of signal forwarding.
+       // Please refer to https://golang.org/issue/31827 .
+       MOVD    R19, 8*4(RSP)
+       MOVD    R20, 8*5(RSP)
+       MOVD    R21, 8*6(RSP)
+       MOVD    R22, 8*7(RSP)
+       MOVD    R23, 8*8(RSP)
+       MOVD    R24, 8*9(RSP)
+       MOVD    R25, 8*10(RSP)
+       MOVD    R26, 8*11(RSP)
+       MOVD    R27, 8*12(RSP)
+       MOVD    g, 8*13(RSP)
+       MOVD    R29, 8*14(RSP)
+       FMOVD   F8, 8*15(RSP)
+       FMOVD   F9, 8*16(RSP)
+       FMOVD   F10, 8*17(RSP)
+       FMOVD   F11, 8*18(RSP)
+       FMOVD   F12, 8*19(RSP)
+       FMOVD   F13, 8*20(RSP)
+       FMOVD   F14, 8*21(RSP)
+       FMOVD   F15, 8*22(RSP)
+
        // this might be called in external code context,
        // where g is not set.
        // first save R0, because runtime·load_g will clobber it
@@ -290,6 +312,28 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$24
        MOVD    R1, 16(RSP)
        MOVD    R2, 24(RSP)
        BL      runtime·sigtrampgo(SB)
+
+       // Restore callee-save registers.
+       MOVD    8*4(RSP), R19
+       MOVD    8*5(RSP), R20
+       MOVD    8*6(RSP), R21
+       MOVD    8*7(RSP), R22
+       MOVD    8*8(RSP), R23
+       MOVD    8*9(RSP), R24
+       MOVD    8*10(RSP), R25
+       MOVD    8*11(RSP), R26
+       MOVD    8*12(RSP), R27
+       MOVD    8*13(RSP), g
+       MOVD    8*14(RSP), R29
+       FMOVD   8*15(RSP), F8
+       FMOVD   8*16(RSP), F9
+       FMOVD   8*17(RSP), F10
+       FMOVD   8*18(RSP), F11
+       FMOVD   8*19(RSP), F12
+       FMOVD   8*20(RSP), F13
+       FMOVD   8*21(RSP), F14
+       FMOVD   8*22(RSP), F15
+
        RET
 
 TEXT runtime·mmap(SB),NOSPLIT,$0
index 8d0f4de689bd3ac9782360b2128439e3e58628aa..52bed4bd8bcca91fcd500a8bf23019b057ab5ca6 100644 (file)
@@ -219,7 +219,29 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
        BL      (R11)                   // Alignment for ELF ABI?
        RET
 
-TEXT runtime·sigtramp(SB),NOSPLIT,$32
+TEXT runtime·sigtramp(SB),NOSPLIT,$192
+       // Save callee-save registers in the case of signal forwarding.
+       // Please refer to https://golang.org/issue/31827 .
+       MOVD    R19, 8*4(RSP)
+       MOVD    R20, 8*5(RSP)
+       MOVD    R21, 8*6(RSP)
+       MOVD    R22, 8*7(RSP)
+       MOVD    R23, 8*8(RSP)
+       MOVD    R24, 8*9(RSP)
+       MOVD    R25, 8*10(RSP)
+       MOVD    R26, 8*11(RSP)
+       MOVD    R27, 8*12(RSP)
+       MOVD    g, 8*13(RSP)
+       MOVD    R29, 8*14(RSP)
+       FMOVD   F8, 8*15(RSP)
+       FMOVD   F9, 8*16(RSP)
+       FMOVD   F10, 8*17(RSP)
+       FMOVD   F11, 8*18(RSP)
+       FMOVD   F12, 8*19(RSP)
+       FMOVD   F13, 8*20(RSP)
+       FMOVD   F14, 8*21(RSP)
+       FMOVD   F15, 8*22(RSP)
+
        // If called from an external code context, g will not be set.
        // Save R0, since runtime·load_g will clobber it.
        MOVW    R0, 8(RSP)              // signum
@@ -231,6 +253,28 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$32
        MOVD    R1, 16(RSP)
        MOVD    R2, 24(RSP)
        BL      runtime·sigtrampgo(SB)
+
+       // Restore callee-save registers.
+       MOVD    8*4(RSP), R19
+       MOVD    8*5(RSP), R20
+       MOVD    8*6(RSP), R21
+       MOVD    8*7(RSP), R22
+       MOVD    8*8(RSP), R23
+       MOVD    8*9(RSP), R24
+       MOVD    8*10(RSP), R25
+       MOVD    8*11(RSP), R26
+       MOVD    8*12(RSP), R27
+       MOVD    8*13(RSP), g
+       MOVD    8*14(RSP), R29
+       FMOVD   8*15(RSP), F8
+       FMOVD   8*16(RSP), F9
+       FMOVD   8*17(RSP), F10
+       FMOVD   8*18(RSP), F11
+       FMOVD   8*19(RSP), F12
+       FMOVD   8*20(RSP), F13
+       FMOVD   8*21(RSP), F14
+       FMOVD   8*22(RSP), F15
+
        RET
 
 // int32 tfork(void *param, uintptr psize, M *mp, G *gp, void (*fn)(void));