From: Austin Clements Date: Wed, 14 Apr 2021 03:46:18 +0000 (-0400) Subject: runtime: minor refactoring of _rt0_amd64_lib X-Git-Tag: go1.17beta1~629 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3e0b1cdb5d;p=gostls13.git runtime: minor refactoring of _rt0_amd64_lib 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 Run-TryBot: Austin Clements TryBot-Result: Go Bot Reviewed-by: Cherry Zhang --- diff --git a/src/runtime/asm_amd64.s b/src/runtime/asm_amd64.s index a88cd17e6b..1c74d70d36 100644 --- a/src/runtime/asm_amd64.s +++ b/src/runtime/asm_amd64.s @@ -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.