github.com/goshafaq/sonic@v0.0.0-20231026082336-871835fb94c6/loader/funcdata_go121.go (about)

     1  //go:build go1.21 && !go1.22
     2  // +build go1.21,!go1.22
     3  
     4  /*
     5   * Copyright 2021 ByteDance Inc.
     6   *
     7   * Licensed under the Apache License, Version 2.0 (the "License");
     8   * you may not use this file except in compliance with the License.
     9   * You may obtain a copy of the License at
    10   *
    11   *     http://www.apache.org/licenses/LICENSE-2.0
    12   *
    13   * Unless required by applicable law or agreed to in writing, software
    14   * distributed under the License is distributed on an "AS IS" BASIS,
    15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16   * See the License for the specific language governing permissions and
    17   * limitations under the License.
    18   */
    19  
    20  package loader
    21  
    22  import (
    23  	"github.com/goshafaq/sonic/internal/rt"
    24  	"unsafe"
    25  )
    26  
    27  const (
    28  	_Magic uint32 = 0xFFFFFFF1
    29  )
    30  
    31  type moduledata struct {
    32  	pcHeader     *pcHeader
    33  	funcnametab  []byte
    34  	cutab        []uint32
    35  	filetab      []byte
    36  	pctab        []byte
    37  	pclntable    []byte
    38  	ftab         []funcTab
    39  	findfunctab  uintptr
    40  	minpc, maxpc uintptr // first func address, last func address + last func size
    41  
    42  	text, etext           uintptr // start/end of text, (etext-text) must be greater than MIN_FUNC
    43  	noptrdata, enoptrdata uintptr
    44  	data, edata           uintptr
    45  	bss, ebss             uintptr
    46  	noptrbss, enoptrbss   uintptr
    47  	covctrs, ecovctrs     uintptr
    48  	end, gcdata, gcbss    uintptr
    49  	types, etypes         uintptr
    50  	rodata                uintptr
    51  	gofunc                uintptr // go.func.* is actual funcinfo object in image
    52  
    53  	textsectmap []textSection // see runtime/symtab.go: textAddr()
    54  	typelinks   []int32       // offsets from types
    55  	itablinks   []*rt.GoItab
    56  
    57  	ptab []ptabEntry
    58  
    59  	pluginpath string
    60  	pkghashes  []modulehash
    61  
    62  	// This slice records the initializing tasks that need to be
    63  	// done to start up the program. It is built by the linker.
    64  	inittasks []unsafe.Pointer
    65  
    66  	modulename   string
    67  	modulehashes []modulehash
    68  
    69  	hasmain uint8 // 1 if module contains the main function, 0 otherwise
    70  
    71  	gcdatamask, gcbssmask bitVector
    72  
    73  	typemap map[int32]*rt.GoType // offset to *_rtype in previous module
    74  
    75  	bad bool // module failed to load and should be ignored
    76  
    77  	next *moduledata
    78  }
    79  
    80  type _func struct {
    81  	entryOff uint32 // start pc, as offset from moduledata.text/pcHeader.textStart
    82  	nameOff  int32  // function name, as index into moduledata.funcnametab.
    83  
    84  	args        int32  // in/out args size
    85  	deferreturn uint32 // offset of start of a deferreturn call instruction from entry, if any.
    86  
    87  	pcsp      uint32
    88  	pcfile    uint32
    89  	pcln      uint32
    90  	npcdata   uint32
    91  	cuOffset  uint32 // runtime.cutab offset of this function's CU
    92  	startLine int32  // line number of start of function (func keyword/TEXT directive)
    93  	funcID    uint8  // set for certain special runtime functions
    94  	flag      uint8
    95  	_         [1]byte // pad
    96  	nfuncdata uint8   //
    97  
    98  	// The end of the struct is followed immediately by two variable-length
    99  	// arrays that reference the pcdata and funcdata locations for this
   100  	// function.
   101  
   102  	// pcdata contains the offset into moduledata.pctab for the start of
   103  	// that index's table. e.g.,
   104  	// &moduledata.pctab[_func.pcdata[_PCDATA_UnsafePoint]] is the start of
   105  	// the unsafe point table.
   106  	//
   107  	// An offset of 0 indicates that there is no table.
   108  	//
   109  	// pcdata [npcdata]uint32
   110  
   111  	// funcdata contains the offset past moduledata.gofunc which contains a
   112  	// pointer to that index's funcdata. e.g.,
   113  	// *(moduledata.gofunc +  _func.funcdata[_FUNCDATA_ArgsPointerMaps]) is
   114  	// the argument pointer map.
   115  	//
   116  	// An offset of ^uint32(0) indicates that there is no entry.
   117  	//
   118  	// funcdata [nfuncdata]uint32
   119  }