aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/asm_amd64.s
diff options
context:
space:
mode:
authorqmuntal <quimmuntal@gmail.com>2025-09-23 18:19:47 +0200
committerQuim Muntal <quimmuntal@gmail.com>2025-09-25 23:48:32 -0700
commitfdea7da3e68b66514c7466696ecb6b034224ded0 (patch)
treead3565f1139cc25d3c241671d1fc18c25b485fbd /src/runtime/asm_amd64.s
parente8a4f508d1140eef70463c6c085c352418e03d9c (diff)
downloadgo-fdea7da3e68b66514c7466696ecb6b034224ded0.tar.xz
runtime: use common library entry point on windows amd64/386
Windows can reuse the common library entry point instead of implementing a its own version. Note that windows/arm64 already uses the common one. Change-Id: I1a27bbec04bfd1d58a136638bafcdc0583bd106f Reviewed-on: https://go-review.googlesource.com/c/go/+/706235 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/runtime/asm_amd64.s')
-rw-r--r--src/runtime/asm_amd64.s18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/runtime/asm_amd64.s b/src/runtime/asm_amd64.s
index cf1d49a4ad..525df96f00 100644
--- a/src/runtime/asm_amd64.s
+++ b/src/runtime/asm_amd64.s
@@ -37,7 +37,12 @@ TEXT _rt0_amd64_lib(SB),NOSPLIT|NOFRAME,$0
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
@@ -45,12 +50,23 @@ TEXT _rt0_amd64_lib(SB),NOSPLIT|NOFRAME,$0
JZ nocgo
// We're calling back to C.
- // Align stack per ELF ABI requirements.
+ // 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
+#endif
MOVQ BX, SP
JMP restore