funcdata_go121.go 3.7 KB

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