diff options
| author | qmuntal <quimmuntal@gmail.com> | 2026-03-05 10:07:49 +0100 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2026-03-18 15:32:53 -0700 |
| commit | 6bdfdb5f51951584732e6a95a7ee8a5ba5e8cb93 (patch) | |
| tree | 5de5bf3d98eda9a353de1028b9e0836adb77ea2f /src/runtime/proc.go | |
| parent | 8e137ff9953d7a535170c9f3ff2c55811e7e13c3 (diff) | |
| download | go-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/proc.go')
| -rw-r--r-- | src/runtime/proc.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/runtime/proc.go b/src/runtime/proc.go index db4febace9..71e80e9cb7 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -8156,3 +8156,24 @@ func doInit1(t *initTask) { t.state = 2 // initialization done } } + +// libInit is common startup code for most architectures when +// using -buildmode=c-archive or -buildmode=c-shared. +// +// May run with m.p==nil, so write barriers are not allowed. +// +//go:nowritebarrierrec +//go:nosplit +func libInit() { + // Synchronous initialization. + libpreinit() + + // Asynchronous initialization. + // Prefer creating a thread via cgo if it is available. + if _cgo_sys_thread_create != nil { + asmcgocall(_cgo_sys_thread_create, unsafe.Pointer(abi.FuncPCABIInternal(rt0_lib_go))) + } else { + const stackSize = 0x800000 // 8192KB + newosproc0(stackSize, unsafe.Pointer(abi.FuncPCABIInternal(rt0_lib_go))) + } +} |
