]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: minor refactoring of _rt0_amd64_lib
authorAustin Clements <austin@google.com>
Wed, 14 Apr 2021 03:46:18 +0000 (23:46 -0400)
committerAustin Clements <austin@google.com>
Thu, 15 Apr 2021 12:38:09 +0000 (12:38 +0000)
This function bounces between the C and Go ABIs a few times. This CL
narrows the scope of the Go -> C transition to just around the branch
that calls C. This lets us take advantage of C callee-save registers
to simplify the code a little.

Change-Id: I1ffa0b9e50325425c5ec66596978aeb6450a6b57
Reviewed-on: https://go-review.googlesource.com/c/go/+/309929
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/runtime/asm_amd64.s

index a88cd17e6b5af10e5d193e417da1005e58b1b8ad..1c74d70d36f3e327c5119fb1321fe509e8305048 100644 (file)
@@ -28,10 +28,7 @@ TEXT main(SB),NOSPLIT,$-8
 // c-archive) or when the shared library is loaded (for c-shared).
 // We expect argc and argv to be passed in the usual C ABI registers
 // DI and SI.
-TEXT _rt0_amd64_lib(SB),NOSPLIT,$0x50
-       // Align stack per ELF ABI requirements.
-       MOVQ    SP, AX
-       ANDQ    $~15, SP
+TEXT _rt0_amd64_lib(SB),NOSPLIT,$0x40
        // Save C ABI callee-saved registers, as caller may need them.
        MOVQ    BX, 0x10(SP)
        MOVQ    BP, 0x18(SP)
@@ -39,7 +36,6 @@ TEXT _rt0_amd64_lib(SB),NOSPLIT,$0x50
        MOVQ    R13, 0x28(SP)
        MOVQ    R14, 0x30(SP)
        MOVQ    R15, 0x38(SP)
-       MOVQ    AX, 0x40(SP)
 
        MOVQ    DI, _rt0_amd64_lib_argc<>(SB)
        MOVQ    SI, _rt0_amd64_lib_argv<>(SB)
@@ -51,9 +47,15 @@ TEXT _rt0_amd64_lib(SB),NOSPLIT,$0x50
        MOVQ    _cgo_sys_thread_create(SB), AX
        TESTQ   AX, AX
        JZ      nocgo
+
+       // We're calling back to C.
+       // Align stack per ELF ABI requirements.
+       MOVQ    SP, BX  // Callee-save in C ABI
+       ANDQ    $~15, SP
        MOVQ    $_rt0_amd64_lib_go(SB), DI
        MOVQ    $0, SI
        CALL    AX
+       MOVQ    BX, SP
        JMP     restore
 
 nocgo:
@@ -69,7 +71,6 @@ restore:
        MOVQ    0x28(SP), R13
        MOVQ    0x30(SP), R14
        MOVQ    0x38(SP), R15
-       MOVQ    0x40(SP), SP
        RET
 
 // _rt0_amd64_lib_go initializes the Go runtime.