aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/asm_amd64.s
diff options
context:
space:
mode:
authorqmuntal <quimmuntal@gmail.com>2026-03-05 10:07:49 +0100
committerGopher Robot <gobot@golang.org>2026-03-18 15:32:53 -0700
commit6bdfdb5f51951584732e6a95a7ee8a5ba5e8cb93 (patch)
tree5de5bf3d98eda9a353de1028b9e0836adb77ea2f /src/runtime/asm_amd64.s
parent8e137ff9953d7a535170c9f3ff2c55811e7e13c3 (diff)
downloadgo-6bdfdb5f51951584732e6a95a7ee8a5ba5e8cb93.tar.xz
runtime: implement part of library initialization in Go
All architectures supporting c-shared and c-archive share the same initialization code in assembly, and most of it can be implemented in pure Go. Cq-Include-Trybots: luci.golang.try:gotip-darwin-arm64-longtest,gotip-linux-ppc64le_power10,gotip-linux-riscv64,gotip-linux-loong64,gotip-linux-s390x Change-Id: Iaa9fb7d6f9ca8785f1098461646d607ef6b00d47 Reviewed-on: https://go-review.googlesource.com/c/go/+/706417 Auto-Submit: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org>
Diffstat (limited to 'src/runtime/asm_amd64.s')
-rw-r--r--src/runtime/asm_amd64.s49
1 files changed, 8 insertions, 41 deletions
diff --git a/src/runtime/asm_amd64.s b/src/runtime/asm_amd64.s
index 09fd8e11d2..94120cdbed 100644
--- a/src/runtime/asm_amd64.s
+++ b/src/runtime/asm_amd64.s
@@ -36,55 +36,22 @@ TEXT _rt0_amd64_lib(SB),NOSPLIT|NOFRAME,$0
MOVQ DI, _rt0_amd64_lib_argc<>(SB)
MOVQ SI, _rt0_amd64_lib_argv<>(SB)
- // Synchronous initialization.
-#ifndef GOOS_windows
- // Avoid calling it on Windows because it is not used
- // and it would crash the application due to the autogenerated
- // ABI wrapper trying to access a non-existent TLS slot.
- CALL runtime·libpreinit(SB)
-#endif
-
- // Create a new thread to finish Go runtime initialization.
- MOVQ _cgo_sys_thread_create(SB), AX
- TESTQ AX, AX
- JZ nocgo
-
- // We're calling back to C.
- // Align stack per C ABI requirements.
- MOVQ SP, BX // Callee-save in C ABI
- ANDQ $~15, SP
- MOVQ $_rt0_amd64_lib_go(SB), DI
- MOVQ $0, SI
#ifdef GOOS_windows
- // For Windows ABI
- MOVQ DI, CX
- MOVQ SI, DX
- // Leave space for four words on the stack as required
- // by the Windows amd64 calling convention.
- ADJSP $32
-#endif
- CALL AX
-#ifdef GOOS_windows
- ADJSP $-32 // just to make the assembler not complain about unbalanced stack
+ // Set up a dummy TLS value on Windows so that the autogenerated
+ // ABI wrappers don't crash when trying to load G from TLS before
+ // wintls has set up the real TLS slot in rt0_go.
+ MOVQ $zeroTLS<>(SB), DI
+ CALL runtime·settls(SB)
#endif
- MOVQ BX, SP
- JMP restore
-nocgo:
- ADJSP $16
- MOVQ $0x800000, 0(SP) // stacksize
- MOVQ $_rt0_amd64_lib_go(SB), AX
- MOVQ AX, 8(SP) // fn
- CALL runtime·newosproc0(SB)
- ADJSP $-16
+ CALL runtime·libInit(SB)
-restore:
POP_REGS_HOST_TO_ABI0()
RET
-// _rt0_amd64_lib_go initializes the Go runtime.
+// rt0_lib_go initializes the Go runtime.
// This is started in a separate thread by _rt0_amd64_lib.
-TEXT _rt0_amd64_lib_go(SB),NOSPLIT,$0
+TEXT runtime·rt0_lib_go<ABIInternal>(SB),NOSPLIT,$0
MOVQ _rt0_amd64_lib_argc<>(SB), DI
MOVQ _rt0_amd64_lib_argv<>(SB), SI
JMP runtime·rt0_go(SB)