github.com/primecitizens/pcz/std@v0.2.1/runtime/sym.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  
     4  //go:build pcz
     5  
     6  package runtime
     7  
     8  import (
     9  	"unsafe"
    10  
    11  	stdgo "github.com/primecitizens/pcz/std/builtin/go"
    12  	stdmap "github.com/primecitizens/pcz/std/builtin/map"
    13  	stdtype "github.com/primecitizens/pcz/std/builtin/type"
    14  	"github.com/primecitizens/pcz/std/core/abi"
    15  	"github.com/primecitizens/pcz/std/core/assert"
    16  
    17  	// _ "github.com/primecitizens/pcz/std/core/gc"    // import implementation of gcWritBarrier
    18  	_ "github.com/primecitizens/pcz/std/core/stack" // import implementation of morestack and morestack_noctxt
    19  	_ "github.com/primecitizens/pcz/std/rt0"        // import the magic line
    20  )
    21  
    22  var (
    23  	// Set by the linker so the runtime can determine the buildmode.
    24  	islibrary bool // -buildmode=c-shared
    25  	isarchive bool // -buildmode=c-archive
    26  
    27  	goarm uint8 // set by cmd/link on arm systems
    28  
    29  	// base address for all 0-byte allocations
    30  	zerobase uintptr
    31  
    32  	lastmoduledatap *moduledata // linker symbol
    33  	firstmoduledata moduledata  // linker symbol
    34  
    35  	// This slice records the initializing tasks that need to be
    36  	// done to start up the runtime. It is built by the linker.
    37  	//
    38  	// See $GOROOT/src/runtime/proc.go#var:runtime_inittasks
    39  	// NOTE: It is used by rt0.start().
    40  	runtime_inittasks []*abi.InitTask
    41  
    42  	// The compiler knows about this variable.
    43  	// If you change it, you must change builtin/runtime.go, too.
    44  	// If you change the first four bytes, you must also change the write
    45  	// barrier insertion code.
    46  	writeBarrier struct {
    47  		enabled bool    // compiler emits a check of this before calling write barrier
    48  		pad     [3]byte // compiler uses 32-bit load for "enabled" field
    49  		needed  bool    // whether we need a write barrier for current GC phase
    50  		cgo     bool    // whether we need a write barrier for a cgo check
    51  		alignme uint64  // guarantee alignment so that compiler can use a 32 or 64-bit load
    52  	}
    53  
    54  	// pinnedTypemaps are the map[typeOff]*_type from the moduledata objects.
    55  	//
    56  	// These typemap objects are allocated at run time on the heap, but the
    57  	// only direct reference to them is in the moduledata, created by the
    58  	// linker and marked SNOPTRDATA so it is ignored by the GC.
    59  	//
    60  	// To make sure the map isn't collected, we keep a second reference here.
    61  	pinnedTypemaps []map[abi.TypeOff]*abi.Type
    62  
    63  	// set using cmd/go/internal/modload.ModInfoProg
    64  	modinfo string
    65  
    66  	// buildVersion is the Go tree's version string at build time.
    67  	//
    68  	// This is set by the linker.
    69  	//
    70  	// This is accessed by "go version <binary>".
    71  	buildVersion string
    72  
    73  	defaultGOROOT string // set by cmd/link
    74  
    75  	// cgoAlwaysFalse is a boolean value that is always false.
    76  	// The cgo-generated code says if cgoAlwaysFalse { cgoUse(p) }.
    77  	// The compiler cannot see that cgoAlwaysFalse is always false,
    78  	// so it emits the test and keeps the call, giving the desired
    79  	// escape analysis result. The test is cheaper than the call.
    80  	cgoAlwaysFalse bool
    81  )
    82  
    83  // The linker redirects a reference of a method that it determined
    84  // unreachable to a reference to this function, so it will throw if
    85  // ever called.
    86  //
    87  //go:nosplit
    88  func unreachableMethod() {
    89  	assert.Unreachable()
    90  }
    91  
    92  // This is exported as ABI0 via linkname so obj can call it.
    93  //
    94  //go:nosplit
    95  //go:linkname morestackc
    96  func morestackc() {
    97  	assert.Throw("attempt", "to", "execute", "system", "stack", "code", "on", "user", "stack")
    98  }
    99  
   100  type (
   101  	_panic = stdgo.Panic
   102  	_defer = stdgo.Defer
   103  	hiter  = stdmap.HashIter
   104  	g      = stdgo.GHead
   105  )
   106  
   107  // getg returns the pointer to the current g.
   108  // The compiler rewrites calls to this function into instructions
   109  // that fetch the g directly (from TLS or from the dedicated register).
   110  func getg() *g
   111  
   112  // function symbols required by linker (defined in core/stack/morestack.s)
   113  func morestack()
   114  func morestack_noctxt()
   115  
   116  // Called from compiled code; declared for vet; do NOT call from Go.
   117  //
   118  // see $GOROOT/src/runtime/
   119  func gcWriteBarrier1()
   120  func gcWriteBarrier2()
   121  func gcWriteBarrier3()
   122  func gcWriteBarrier4()
   123  func gcWriteBarrier5()
   124  func gcWriteBarrier6()
   125  func gcWriteBarrier7()
   126  func gcWriteBarrier8()
   127  
   128  // mapinitnoop is a no-op function known the Go linker; if a given global
   129  // map (of the right size) is determined to be dead, the linker will
   130  // rewrite the relocation (from the package init func) from the outlined
   131  // map init function to this symbol.
   132  //
   133  // Defined in assembly so as to avoid complications with
   134  // instrumentation (coverage, etc).
   135  func mapinitnoop()
   136  
   137  // type symbols required by linker
   138  type moduledata abi.ModuleData
   139  
   140  // type symbols required by dwarf genertion
   141  //
   142  // See src/cmd/link/internal/ld/dwarf.go#func:dwarfGenerateDebugInfo
   143  type (
   144  	eface stdtype.Eface
   145  	iface stdtype.Iface
   146  
   147  	// Variant with *byte pointer type for DWARF debugging.
   148  	stringStructDWARF struct {
   149  		str *byte
   150  		len int
   151  	}
   152  
   153  	// here we keep a copy of stdslice.SliceHeader as we want `array` field instead fo `Array`
   154  	slice struct {
   155  		// NOTE: linker checks `array` field for dwarf
   156  		// 		DO NOT CHANGE THESE NAMES
   157  		array unsafe.Pointer
   158  		len   int
   159  		cap   int
   160  	}
   161  
   162  	hmap stdmap.HashMap
   163  	bmap stdmap.MapBucket
   164  
   165  	sudog stdgo.Sudog
   166  	waitq stdgo.Waitq
   167  	hchan stdgo.Chan
   168  
   169  	itab abi.Itab
   170  
   171  	// initTask abi.InitTask
   172  
   173  	// The compiler knows that a print of a value of this type
   174  	// should use printhex instead of printuint (decimal).
   175  	hex uint64
   176  )