]> Cypherpunks.ru repositories - gostls13.git/commitdiff
runtime: use ABIInternal for most calls to sigtrampgo
authorMichael Pratt <mpratt@google.com>
Mon, 7 Mar 2022 22:52:53 +0000 (17:52 -0500)
committerMichael Pratt <mpratt@google.com>
Tue, 26 Apr 2022 18:48:16 +0000 (18:48 +0000)
sigtramp on openbsd-arm64 is teetering on the edge of the nosplit stack
limit. Add more headroom by calling sigtrampgo using ABIInternal, which
eliminates a 48-byte ABI wrapper frame.

openbsd-amd64 has slightly more space, but is also close to the limit,
so convert it as well.

Other operating systems don't have it as bad, but many have nearly
identical implementations of sigtramp, so I have converted them as well.

I've omitted darwin-arm64 and solaris, as those are quite different and
would benefit from not needing ifdef for both cases.

For #51485.

Change-Id: I70512645d4208b346a59d5e5d03836a45833b1d7
Reviewed-on: https://go-review.googlesource.com/c/go/+/390814
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/runtime/sys_darwin_amd64.s
src/runtime/sys_dragonfly_amd64.s
src/runtime/sys_freebsd_amd64.s
src/runtime/sys_freebsd_arm64.s
src/runtime/sys_linux_amd64.s
src/runtime/sys_linux_arm64.s
src/runtime/sys_netbsd_amd64.s
src/runtime/sys_netbsd_arm64.s
src/runtime/sys_openbsd_amd64.s
src/runtime/sys_openbsd_arm64.s

index db4715d2b772160a4b96317e2ce77a4a6399c6d4..8e75a38bd2f791e6635bcf9fe1b2c294844a2995 100644 (file)
@@ -218,13 +218,21 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$0
        // Transition from C ABI to Go ABI.
        PUSH_REGS_HOST_TO_ABI0()
 
-       // Call into the Go signal handler
+       // Set up ABIInternal environment: g in R14, cleared X15.
+       get_tls(R12)
+       MOVQ    g(R12), R14
+       PXOR    X15, X15
+
+       // Reserve space for spill slots.
        NOP     SP              // disable vet stack checking
-       ADJSP   $24
-       MOVL    DI, 0(SP)       // sig
-       MOVQ    SI, 8(SP)       // info
-       MOVQ    DX, 16(SP)      // ctx
-       CALL    ·sigtrampgo(SB)
+       ADJSP   $24
+
+       // Call into the Go signal handler
+       MOVQ    DI, AX  // sig
+       MOVQ    SI, BX  // info
+       MOVQ    DX, CX  // ctx
+       CALL    ·sigtrampgo<ABIInternal>(SB)
+
        ADJSP   $-24
 
        POP_REGS_HOST_TO_ABI0()
index 684c9ab7f0e1609ae51c8a9c1093a9383c446dc0..48b04ff9797364531e5101b5f46bcb1434f66d04 100644 (file)
@@ -226,13 +226,21 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$0
        // Transition from C ABI to Go ABI.
        PUSH_REGS_HOST_TO_ABI0()
 
-       // Call into the Go signal handler
+       // Set up ABIInternal environment: g in R14, cleared X15.
+       get_tls(R12)
+       MOVQ    g(R12), R14
+       PXOR    X15, X15
+
+       // Reserve space for spill slots.
        NOP     SP              // disable vet stack checking
-       ADJSP   $24
-       MOVQ    DI, 0(SP)       // sig
-       MOVQ    SI, 8(SP)       // info
-       MOVQ    DX, 16(SP)      // ctx
-       CALL    ·sigtrampgo(SB)
+       ADJSP   $24
+
+       // Call into the Go signal handler
+       MOVQ    DI, AX  // sig
+       MOVQ    SI, BX  // info
+       MOVQ    DX, CX  // ctx
+       CALL    ·sigtrampgo<ABIInternal>(SB)
+
        ADJSP   $-24
 
        POP_REGS_HOST_TO_ABI0()
index cc95da7e64529b0d6846a4e7cfe6646ea0ab54c5..159f5c66ab99f254711b0577c59180e5f3cc8fdd 100644 (file)
@@ -228,13 +228,21 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$0
        // Transition from C ABI to Go ABI.
        PUSH_REGS_HOST_TO_ABI0()
 
-       // Call into the Go signal handler
+       // Set up ABIInternal environment: g in R14, cleared X15.
+       get_tls(R12)
+       MOVQ    g(R12), R14
+       PXOR    X15, X15
+
+       // Reserve space for spill slots.
        NOP     SP              // disable vet stack checking
-        ADJSP   $24
-       MOVQ    DI, 0(SP)       // sig
-       MOVQ    SI, 8(SP)       // info
-       MOVQ    DX, 16(SP)      // ctx
-       CALL    ·sigtrampgo(SB)
+       ADJSP   $24
+
+       // Call into the Go signal handler
+       MOVQ    DI, AX  // sig
+       MOVQ    SI, BX  // info
+       MOVQ    DX, CX  // ctx
+       CALL    ·sigtrampgo<ABIInternal>(SB)
+
        ADJSP   $-24
 
         POP_REGS_HOST_TO_ABI0()
@@ -245,13 +253,21 @@ TEXT runtime·sigprofNonGoWrapper<>(SB),NOSPLIT,$0
        // Transition from C ABI to Go ABI.
        PUSH_REGS_HOST_TO_ABI0()
 
-       // Call into the Go signal handler
+       // Set up ABIInternal environment: g in R14, cleared X15.
+       get_tls(R12)
+       MOVQ    g(R12), R14
+       PXOR    X15, X15
+
+       // Reserve space for spill slots.
        NOP     SP              // disable vet stack checking
-       ADJSP   $24
-       MOVL    DI, 0(SP)       // sig
-       MOVQ    SI, 8(SP)       // info
-       MOVQ    DX, 16(SP)      // ctx
-       CALL    ·sigprofNonGo(SB)
+       ADJSP   $24
+
+       // Call into the Go signal handler
+       MOVQ    DI, AX  // sig
+       MOVQ    SI, BX  // info
+       MOVQ    DX, CX  // ctx
+       CALL    ·sigprofNonGo<ABIInternal>(SB)
+
        ADJSP   $-24
 
        POP_REGS_HOST_TO_ABI0()
index 7b05fb09004ab125ad68bc6155ff79451b2be012..a4f12eb3b923cda8be5bab42d791a0369f49b027 100644 (file)
@@ -295,10 +295,16 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$176
        BEQ     2(PC)
        BL      runtime·load_g(SB)
 
+#ifdef GOEXPERIMENT_regabiargs
+       // Restore signum to R0.
+       MOVW    8(RSP), R0
+       // R1 and R2 already contain info and ctx, respectively.
+#else
        MOVD    R1, 16(RSP)
        MOVD    R2, 24(RSP)
-       MOVD    $runtime·sigtrampgo(SB), R0
-       BL      (R0)
+#endif
+       MOVD    $runtime·sigtrampgo<ABIInternal>(SB), R3
+       BL      (R3)
 
        // Restore callee-save registers.
        RESTORE_R19_TO_R28(8*4)
index 4be0801114bd34d42110ad4757e4ce0065fdcb28..f2dfbbb70c3fc5a3dd611a37d7ea60feb3985c51 100644 (file)
@@ -343,13 +343,21 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$0
        // Transition from C ABI to Go ABI.
        PUSH_REGS_HOST_TO_ABI0()
 
-       // Call into the Go signal handler
+       // Set up ABIInternal environment: g in R14, cleared X15.
+       get_tls(R12)
+       MOVQ    g(R12), R14
+       PXOR    X15, X15
+
+       // Reserve space for spill slots.
        NOP     SP              // disable vet stack checking
-        ADJSP   $24
-       MOVQ    DI, 0(SP)       // sig
-       MOVQ    SI, 8(SP)       // info
-       MOVQ    DX, 16(SP)      // ctx
-       CALL    ·sigtrampgo(SB)
+       ADJSP   $24
+
+       // Call into the Go signal handler
+       MOVQ    DI, AX  // sig
+       MOVQ    SI, BX  // info
+       MOVQ    DX, CX  // ctx
+       CALL    ·sigtrampgo<ABIInternal>(SB)
+
        ADJSP   $-24
 
         POP_REGS_HOST_TO_ABI0()
@@ -360,13 +368,21 @@ TEXT runtime·sigprofNonGoWrapper<>(SB),NOSPLIT,$0
        // Transition from C ABI to Go ABI.
        PUSH_REGS_HOST_TO_ABI0()
 
-       // Call into the Go signal handler
+       // Set up ABIInternal environment: g in R14, cleared X15.
+       get_tls(R12)
+       MOVQ    g(R12), R14
+       PXOR    X15, X15
+
+       // Reserve space for spill slots.
        NOP     SP              // disable vet stack checking
-       ADJSP   $24
-       MOVL    DI, 0(SP)       // sig
-       MOVQ    SI, 8(SP)       // info
-       MOVQ    DX, 16(SP)      // ctx
-       CALL    ·sigprofNonGo(SB)
+       ADJSP   $24
+
+       // Call into the Go signal handler
+       MOVQ    DI, AX  // sig
+       MOVQ    SI, BX  // info
+       MOVQ    DX, CX  // ctx
+       CALL    ·sigprofNonGo<ABIInternal>(SB)
+
        ADJSP   $-24
 
        POP_REGS_HOST_TO_ABI0()
index 36ac014f03fd12e539a64053f531ce3d360e6039..8e7cbf7d11e07b87a1aff9f4d8693b1460e2d301 100644 (file)
@@ -459,10 +459,16 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$176
        CBZ     R0, 2(PC)
        BL      runtime·load_g(SB)
 
+#ifdef GOEXPERIMENT_regabiargs
+       // Restore signum to R0.
+       MOVW    8(RSP), R0
+       // R1 and R2 already contain info and ctx, respectively.
+#else
        MOVD    R1, 16(RSP)
        MOVD    R2, 24(RSP)
-       MOVD    $runtime·sigtrampgo(SB), R0
-       BL      (R0)
+#endif
+       MOVD    $runtime·sigtrampgo<ABIInternal>(SB), R3
+       BL      (R3)
 
        // Restore callee-save registers.
        RESTORE_R19_TO_R28(8*4)
@@ -476,10 +482,14 @@ TEXT runtime·sigprofNonGoWrapper<>(SB),NOSPLIT,$176
        SAVE_R19_TO_R28(8*4)
        SAVE_F8_TO_F15(8*14)
 
+#ifdef GOEXPERIMENT_regabiargs
+       // R0, R1 and R2 already contain sig, info and ctx, respectively.
+#else
        MOVW    R0, 8(RSP)      // sig
        MOVD    R1, 16(RSP)     // info
        MOVD    R2, 24(RSP)     // ctx
-       CALL    runtime·sigprofNonGo(SB)
+#endif
+       CALL    runtime·sigprofNonGo<ABIInternal>(SB)
 
        // Restore callee-save registers.
        RESTORE_R19_TO_R28(8*4)
index 41eddf373505aa454bbee1a2c29ba124f417be59..ade11366e5ee4311c9a8ea2d9c011069b8c85323 100644 (file)
@@ -309,13 +309,21 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$0
        // Transition from C ABI to Go ABI.
        PUSH_REGS_HOST_TO_ABI0()
 
-       // Call into the Go signal handler
+       // Set up ABIInternal environment: g in R14, cleared X15.
+       get_tls(R12)
+       MOVQ    g(R12), R14
+       PXOR    X15, X15
+
+       // Reserve space for spill slots.
        NOP     SP              // disable vet stack checking
-        ADJSP   $24
-       MOVQ    DI, 0(SP)       // sig
-       MOVQ    SI, 8(SP)       // info
-       MOVQ    DX, 16(SP)      // ctx
-       CALL    ·sigtrampgo(SB)
+       ADJSP   $24
+
+       // Call into the Go signal handler
+       MOVQ    DI, AX  // sig
+       MOVQ    SI, BX  // info
+       MOVQ    DX, CX  // ctx
+       CALL    ·sigtrampgo<ABIInternal>(SB)
+
        ADJSP   $-24
 
         POP_REGS_HOST_TO_ABI0()
index 32e6740c5205037b5bdec511f1c2ddd3284e9e07..6bcd3445d3e11e5a3a89826efc0eed073d5453c6 100644 (file)
@@ -317,9 +317,15 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$176
        BEQ     2(PC)
        BL      runtime·load_g(SB)
 
+#ifdef GOEXPERIMENT_regabiargs
+       // Restore signum to R0.
+       MOVW    8(RSP), R0
+       // R1 and R2 already contain info and ctx, respectively.
+#else
        MOVD    R1, 16(RSP)
        MOVD    R2, 24(RSP)
-       BL      runtime·sigtrampgo(SB)
+#endif
+       BL      runtime·sigtrampgo<ABIInternal>(SB)
 
        // Restore callee-save registers.
        RESTORE_R19_TO_R28(8*4)
index fc6d5dc387dd2c05500890e799dc4110fed3698e..f71f5ccead6f15ee3fe7306d3bb20aab06d95a4d 100644 (file)
@@ -62,16 +62,24 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$0
        // Transition from C ABI to Go ABI.
        PUSH_REGS_HOST_TO_ABI0()
 
-       // Call into the Go signal handler
+       // Set up ABIInternal environment: g in R14, cleared X15.
+       get_tls(R12)
+       MOVQ    g(R12), R14
+       PXOR    X15, X15
+
+       // Reserve space for spill slots.
        NOP     SP              // disable vet stack checking
-        ADJSP   $24
-       MOVQ    DI, 0(SP)       // sig
-       MOVQ    SI, 8(SP)       // info
-       MOVQ    DX, 16(SP)      // ctx
-       CALL    ·sigtrampgo(SB)
+       ADJSP   $24
+
+       // Call into the Go signal handler
+       MOVQ    DI, AX  // sig
+       MOVQ    SI, BX  // info
+       MOVQ    DX, CX  // ctx
+       CALL    ·sigtrampgo<ABIInternal>(SB)
+
        ADJSP   $-24
 
-        POP_REGS_HOST_TO_ABI0()
+       POP_REGS_HOST_TO_ABI0()
        RET
 
 //
index 7c1886e0a04afda2b457da140d3ffc843812eae5..4a3f2fc3a2acb85a8fd49e5707be8b42cf6e3ce5 100644 (file)
@@ -62,9 +62,15 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$192
        MOVW    R0, 8(RSP)              // signum
        BL      runtime·load_g(SB)
 
+#ifdef GOEXPERIMENT_regabiargs
+       // Restore signum to R0.
+       MOVW    8(RSP), R0
+       // R1 and R2 already contain info and ctx, respectively.
+#else
        MOVD    R1, 16(RSP)
        MOVD    R2, 24(RSP)
-       BL      runtime·sigtrampgo(SB)
+#endif
+       BL      runtime·sigtrampgo<ABIInternal>(SB)
 
        // Restore callee-save registers.
        RESTORE_R19_TO_R28(8*4)