forked from pkujhd/goloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdymcode.1.16.go
123 lines (112 loc) · 4.07 KB
/
dymcode.1.16.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// +build go1.16
// +build !go1.17
package goloader
import (
"unsafe"
)
const (
R_PCREL = 16
// R_TLS_LE, used on 386, amd64, and ARM, resolves to the offset of the
// thread-local symbol from the thread local base and is used to implement the
// "local exec" model for tls access (r.Sym is not set on intel platforms but is
// set to a TLS symbol -- runtime.tlsg -- in the linker when externally linking).
R_TLS_LE = 17
// R_USEIFACE marks a type is converted to an interface in the function this
// relocation is applied to. The target is a type descriptor.
// This is a marker relocation (0-sized), for the linker's reachabililty
// analysis.
R_USEIFACE = 25
// R_USEIFACEMETHOD marks an interface method that is used in the function
// this relocation is applied to. The target is an interface type descriptor.
// The addend is the offset of the method in the type descriptor.
// This is a marker relocation (0-sized), for the linker's reachabililty
// analysis.
R_USEIFACEMETHOD = 26
// R_METHODOFF resolves to a 32-bit offset from the beginning of the section
// holding the data being relocated to the referenced symbol.
// It is a variant of R_ADDROFF used when linking from the uncommonType of a
// *rtype, and may be set to zero by the linker if it determines the method
// text is unreachable by the linked program.
R_METHODOFF = 27
// R_ADDRCUOFF resolves to a pointer-sized offset from the start of the
// symbol's DWARF compile unit.
R_ADDRCUOFF = 58
)
// copy from $GOROOT/src/cmd/internal/objabi/symkind.go
const (
// An otherwise invalid zero value for the type
Sxxx = iota
// Executable instructions
STEXT
// Read only static data
SRODATA
// Static data that does not contain any pointers
SNOPTRDATA
// Static data
SDATA
// Statically data that is initially all 0s
SBSS
// Statically data that is initially all 0s and does not contain pointers
SNOPTRBSS
// Thread-local data that is initially all 0s
STLSBSS
// Debugging data
SDWARFCUINFO
SDWARFCONST
SDWARFFCN
SDWARFABSFCN
SDWARFTYPE
SDWARFVAR
SDWARFRANGE
SDWARFLOC
SDWARFLINES
// ABI alias. An ABI alias symbol is an empty symbol with a
// single relocation with 0 size that references the native
// function implementation symbol.
//
// TODO(austin): Remove this and all uses once the compiler
// generates real ABI wrappers rather than symbol aliases.
SABIALIAS
// Coverage instrumentation counter for libfuzzer.
SLIBFUZZER_EXTRA_COUNTER
// Update cmd/link/internal/sym/AbiSymKindToSymKind for new SymKind values.
)
func (linker *Linker) addStackObject(funcname string, symbolMap map[string]uintptr) (err error) {
return linker._addStackObject(funcname, symbolMap)
}
func (linker *Linker) addDeferReturn(_func *_func) (err error) {
return linker._addDeferReturn(_func)
}
// inlinedCall is the encoding of entries in the FUNCDATA_InlTree table.
type inlinedCall struct {
parent int16 // index of parent in the inltree, or < 0
funcID funcID // type of the called function
_ byte
file int32 // fileno index into filetab
line int32 // line number of the call site
func_ int32 // offset into pclntab for name of called function
parentPc int32 // position of an instruction whose source position is the call site (offset from entry)
}
func (linker *Linker) initInlinedCall(inl InlTreeNode, _func *_func) inlinedCall {
inlname := inl.Func
return inlinedCall{
parent: int16(inl.Parent),
funcID: _func.funcID,
file: findFileTab(linker, inl.File),
line: int32(inl.Line),
func_: int32(linker.namemap[inlname]),
parentPc: int32(inl.ParentPC)}
}
func (linker *Linker) addInlineTree(_func *_func, objsym *ObjSymbol) (err error) {
return linker._addInlineTree(_func, objsym)
}
func (linker *Linker) _buildModule(codeModule *CodeModule) {
module := codeModule.module
module.pcHeader = (*pcHeader)(unsafe.Pointer(&(module.pclntable[0])))
module.pcHeader.nfunc = len(module.ftab)
module.pcHeader.nfiles = (uint)(len(module.filetab))
module.funcnametab = module.pclntable
module.pctab = module.pclntable
module.cutab = linker.filetab
module.filetab = module.pclntable
}