github.com/pkujhd/goloader@v0.0.0-20240411034752-1a28096bd7bd/func.1.18.go (about) 1 //go:build go1.18 && !go1.20 2 // +build go1.18,!go1.20 3 4 package goloader 5 6 import "github.com/pkujhd/goloader/obj" 7 8 // A funcID identifies particular functions that need to be treated 9 // specially by the runtime. 10 // Note that in some situations involving plugins, there may be multiple 11 // copies of a particular special runtime function. 12 // Note: this list must match the list in cmd/internal/objabi/funcid.go. 13 type funcID uint8 14 15 // A FuncFlag holds bits about a function. 16 // This list must match the list in cmd/internal/objabi/funcid.go. 17 type funcFlag uint8 18 19 // Layout of in-memory per-function information prepared by linker 20 // See https://golang.org/s/go12symtab. 21 // Keep in sync with linker (../cmd/link/internal/ld/pcln.go:/pclntab) 22 // and with package debug/gosym and with symtab.go in package runtime. 23 type _func struct { 24 Entryoff uint32 // start pc, as offset from moduledata.text/pcHeader.textStart 25 Nameoff int32 // function name 26 27 Args int32 // in/out args size 28 Deferreturn uint32 // offset of start of a deferreturn call instruction from entry, if any. 29 30 Pcsp uint32 31 Pcfile uint32 32 Pcln uint32 33 Npcdata uint32 34 CuOffset uint32 // runtime.cutab offset of this function's CU 35 FuncID funcID // set for certain special runtime functions 36 Flag funcFlag 37 _ [1]byte // pad 38 Nfuncdata uint8 // must be last, must end on a uint32-aligned boundary 39 } 40 41 func initfunc(symbol *obj.ObjSymbol, nameOff, pcspOff, pcfileOff, pclnOff, cuOff int) _func { 42 fdata := _func{ 43 Entryoff: uint32(0), 44 Nameoff: int32(nameOff), 45 Args: int32(symbol.Func.Args), 46 Deferreturn: uint32(0), 47 Pcsp: uint32(pcspOff), 48 Pcfile: uint32(pcfileOff), 49 Pcln: uint32(pclnOff), 50 Npcdata: uint32(len(symbol.Func.PCData)), 51 CuOffset: uint32(cuOff), 52 FuncID: funcID(symbol.Func.FuncID), 53 Flag: funcFlag(symbol.Func.FuncFlag), 54 Nfuncdata: uint8(len(symbol.Func.FuncData)), 55 } 56 return fdata 57 } 58 59 func setfuncentry(f *_func, entry uintptr, text uintptr) { 60 f.Entryoff = uint32(entry - text) 61 } 62 63 func getfuncentry(f *_func, text uintptr) uintptr { 64 return text + uintptr(f.Entryoff) 65 } 66 67 func getfuncname(f *_func, md *moduledata) string { 68 if f.Nameoff <= 0 || f.Nameoff >= int32(len(md.funcnametab)) { 69 return EmptyString 70 } 71 return gostringnocopy(&(md.funcnametab[f.Nameoff])) 72 } 73 74 func getfuncID(f *_func) uint8 { 75 return uint8(f.FuncID) 76 } 77 78 func adaptePCFile(linker *Linker, symbol *obj.ObjSymbol) { 79 }