Source file src/runtime/cgo/callbacks_unix.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 unix
     6  
     7  package cgo
     8  
     9  import _ "unsafe" // for go:linkname
    10  
    11  // We need to reference the addresses of the C functions in Go code,
    12  // but we don't want to reference them directly in text. Otherwise it
    13  // may cause dynamic relocations in the text segment, or even build
    14  // failures in some settings, e.g. linking with -Bsymbolic-functions.
    15  // Reference them via variables with an extra level of indirection to
    16  // avoid that.
    17  
    18  //go:cgo_import_static x_cgo_init
    19  //go:linkname x_cgo_init x_cgo_init
    20  //go:linkname _cgo_init _cgo_init
    21  var x_cgo_init byte
    22  var _cgo_init = &x_cgo_init
    23  
    24  //go:cgo_import_static x_cgo_thread_start
    25  //go:linkname x_cgo_thread_start x_cgo_thread_start
    26  //go:linkname _cgo_thread_start _cgo_thread_start
    27  var x_cgo_thread_start byte
    28  var _cgo_thread_start = &x_cgo_thread_start
    29  
    30  // Creates a new system thread without updating any Go state.
    31  //
    32  // This method is invoked during shared library loading to create a new OS
    33  // thread to perform the runtime initialization. This method is similar to
    34  // x_cgo_thread_start except that it doesn't update any Go state.
    35  
    36  //go:cgo_import_static x_cgo_sys_thread_create
    37  //go:linkname x_cgo_sys_thread_create x_cgo_sys_thread_create
    38  //go:linkname _cgo_sys_thread_create _cgo_sys_thread_create
    39  var x_cgo_sys_thread_create byte
    40  var _cgo_sys_thread_create = &x_cgo_sys_thread_create
    41  
    42  // Store the g into the thread-specific value.
    43  // So that pthread_key_destructor will dropm when the thread is exiting.
    44  
    45  //go:cgo_import_static x_cgo_bindm
    46  //go:linkname x_cgo_bindm x_cgo_bindm
    47  //go:linkname _cgo_bindm _cgo_bindm
    48  var x_cgo_bindm byte
    49  var _cgo_bindm = &x_cgo_bindm
    50  
    51  // x_cgo_getstackbound gets the thread's C stack size and
    52  // set the G's stack bound based on the stack size.
    53  
    54  //go:cgo_import_static x_cgo_getstackbound
    55  //go:linkname x_cgo_getstackbound x_cgo_getstackbound
    56  //go:linkname _cgo_getstackbound _cgo_getstackbound
    57  var x_cgo_getstackbound byte
    58  var _cgo_getstackbound = &x_cgo_getstackbound
    59  

View as plain text