forked from pkujhd/goloader
-
Notifications
You must be signed in to change notification settings - Fork 4
/
deferreturn.go
34 lines (30 loc) · 933 Bytes
/
deferreturn.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//go:build go1.14 && !go1.23
// +build go1.14,!go1.23
package goloader
import (
"cmd/objfile/sys"
"fmt"
"github.com/eh-steve/goloader/objabi/dataindex"
)
func (linker *Linker) addDeferReturn(_func *_func) (err error) {
funcname := gostringnocopy(&linker.funcnametab[_func.nameoff])
Func := linker.symMap[funcname].Func
if Func != nil && len(Func.FuncData) > dataindex.FUNCDATA_OpenCodedDeferInfo {
sym := linker.symMap[funcname]
for _, r := range sym.Reloc {
if r.Sym.Name == RuntimeDeferReturn {
// ../cmd/link/internal/ld/pcln.go:pclntab
switch linker.Arch.Name {
case sys.Arch386.Name, sys.ArchAMD64.Name:
_func.deferreturn = uint32(r.Offset) - uint32(sym.Offset) - 1
case sys.ArchARM.Name, sys.ArchARM64.Name:
_func.deferreturn = uint32(r.Offset) - uint32(sym.Offset)
default:
err = fmt.Errorf("not support arch:%s", linker.Arch.Name)
}
break
}
}
}
return err
}