1 //go:build go1.23 && !go1.25
2 // +build go1.23,!go1.25
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 `unsafe`
24 `github.com/bytedance/sonic/loader/internal/rt`
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 bad bool // module failed to load and should be ignored
71 72 gcdatamask, gcbssmask bitVector
73 74 typemap map[int32]*rt.GoType // offset to *_rtype in previous module
75 76 next *moduledata
77 }
78 79 type _func struct {
80 entryOff uint32 // start pc, as offset from moduledata.text/pcHeader.textStart
81 nameOff int32 // function name, as index into moduledata.funcnametab.
82 83 args int32 // in/out args size
84 deferreturn uint32 // offset of start of a deferreturn call instruction from entry, if any.
85 86 pcsp uint32
87 pcfile uint32
88 pcln uint32
89 npcdata uint32
90 cuOffset uint32 // runtime.cutab offset of this function's CU
91 startLine int32 // line number of start of function (func keyword/TEXT directive)
92 funcID uint8 // set for certain special runtime functions
93 flag uint8
94 _ [1]byte // pad
95 nfuncdata uint8 //
96 97 // The end of the struct is followed immediately by two variable-length
98 // arrays that reference the pcdata and funcdata locations for this
99 // function.
100 101 // pcdata contains the offset into moduledata.pctab for the start of
102 // that index's table. e.g.,
103 // &moduledata.pctab[_func.pcdata[_PCDATA_UnsafePoint]] is the start of
104 // the unsafe point table.
105 //
106 // An offset of 0 indicates that there is no table.
107 //
108 // pcdata [npcdata]uint32
109 110 // funcdata contains the offset past moduledata.gofunc which contains a
111 // pointer to that index's funcdata. e.g.,
112 // *(moduledata.gofunc + _func.funcdata[_FUNCDATA_ArgsPointerMaps]) is
113 // the argument pointer map.
114 //
115 // An offset of ^uint32(0) indicates that there is no entry.
116 //
117 // funcdata [nfuncdata]uint32
118 }
119