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