-
Notifications
You must be signed in to change notification settings - Fork 59
/
deferreturn.go
34 lines (30 loc) · 925 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.24
// +build go1.14,!go1.24
package goloader
import (
"cmd/objfile/sys"
"fmt"
"github.com/pkujhd/goloader/objabi/dataindex"
)
func (linker *Linker) addDeferReturn(_func *_func, module *moduledata) (err error) {
funcname := getfuncname(_func, module)
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.SymName == 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
}