Source file src/runtime/libinit.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build 386 || amd64 || arm || arm64 || loong64 || ppc64 || ppc64le || riscv64 || s390x
     6  
     7  package runtime
     8  
     9  import (
    10  	"internal/abi"
    11  	"unsafe"
    12  )
    13  
    14  // libInit is common startup code for most architectures when
    15  // using -buildmode=c-archive or -buildmode=c-shared.
    16  //
    17  // May run with m.p==nil, so write barriers are not allowed.
    18  //
    19  //go:nowritebarrierrec
    20  //go:nosplit
    21  func libInit() {
    22  	// Synchronous initialization.
    23  	libpreinit()
    24  
    25  	// Asynchronous initialization.
    26  	// Prefer creating a thread via cgo if it is available.
    27  	if _cgo_sys_thread_create != nil {
    28  		// No g because the TLS is not set up until later in rt0_go.
    29  		asmcgocall_no_g(_cgo_sys_thread_create, unsafe.Pointer(abi.FuncPCABIInternal(rt0_lib_go)))
    30  	} else {
    31  		const stackSize = 0x800000 // 8192KB
    32  		newosproc0(stackSize, unsafe.Pointer(abi.FuncPCABIInternal(rt0_lib_go)))
    33  	}
    34  }
    35  

View as plain text