-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgo120.c
More file actions
147 lines (139 loc) · 3.71 KB
/
go120.c
File metadata and controls
147 lines (139 loc) · 3.71 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
struct GoSlice
{
void *data;
size_t len;
size_t capacity;
};
struct GoString
{
char *data;
size_t len;
};
struct GoBitVector
{
uint32_t bitnum;
char *bytedata;
};
struct pcHeader
{
uint32_t magic; // 0xFFFFFFF1
char pad1; // 0
char pad2; // 0
char minLC; // min instruction size
char ptrSize; // size of a ptr in bytes
int * nfunc; // number of functions in the module
int * nfiles; // number of entries in the file tab
int * textStart; // base for function entry PC offsets in this module, equal to moduledata.text
int * funcnameOffset; // offset to the funcnametab variable from pcHeader
int * cuOffset; // offset to the cutab variable from pcHeader
int * filetabOffset; // offset to the filetab variable from pcHeader
int * pctabOffset; // offset to the pctab variable from pcHeader
int * pclnOffset; // offset to the pclntab variable from pcHeader
};
struct ftab
{
uint32_t entryoff; // Offset from the field textStart of pcHeader
uint32_t funcoff; // Offset from pclntable base, which is current address
};
struct _func
{
uint32_t entryoff; // Offset from the field textStart of pcHeader
uint32_t nameoff; // offset to func name from funcnametab of moduledata
// other fields follow...
};
struct moduledata
{
pcHeader *pcHeader; // replaces pclnTable
GoSlice funcnametab; // function name table
GoSlice cutab;
GoSlice filetab;
GoSlice pctab;
GoSlice pclntable; // should be use as ftab now
GoSlice ftab;
void *findfunctab;
void *minpc;
void *maxpc;
void *text;
void *etext;
void *noptrdata;
void *enoptrdata;
void *data;
void *edata;
void *bss;
void *ebss;
void *noptrbss;
void *enoptrbss;
void *covctrs;
void *ecovctrs;
void *end;
void *gcdata;
void *gcbss;
void *types;
void *etypes;
void *rodata;
void *gofunc; // go.func.*
GoSlice textsectmap; // textsect []
GoSlice typelinks; // offsets from types
GoSlice itablinks;
GoSlice ptab;
GoString pluginpath;
GoSlice pkghashes;
GoString modulename;
GoSlice modulehashes;
char hasmain; // 1 if module contains the main function, 0 otherwise
GoBitVector gcdatamask;
GoBitVector gcbssmask;
void *typemap; // offset to *_rtype in previous module
char bad; // module failed to load and should be ignored
struct moduledata *next;
};
enum kind : uint8_t
{
INVALID = 0x0,
BOOL = 0x1,
INT = 0x2,
INT8 = 0x3,
INT16 = 0x4,
INT32 = 0x5,
INT64 = 0x6,
UINT = 0x7,
UINT8 = 0x8,
UINT16 = 0x9,
UINT32 = 0xa,
UINT64 = 0xb,
UINTPTR = 0xc,
FLOAT32 = 0xd,
FLOAT64 = 0xe,
COMPLEX64 = 0xf,
COMPLEX128 = 0x10,
ARRAY = 0x11,
CHAN = 0x12,
FUNC = 0x13,
INTERFACE = 0x14,
MAP = 0x15,
PTR = 0x16,
SLICE = 0x17,
STRING = 0x18,
STRUCT = 0x19,
UNSAFEPTR = 0x1a,
CHAN_DIRECTIFACE = 0x32,
FUNC_DIRECTIFACE = 0x33,
MAP_DIRECTIFACE = 0x35,
STRUCT_DIRECTIFACE = 0x39
};
struct rtype
{
size_t size;
void* ptrdata; // number of bytes in the type that can contain pointers
uint32_t hash; // hash of type; avoids computation in hash tables
uint8_t tflag; // extra type information flags
uint8_t align; // alignment of variable with this type
uint8_t fieldAlign; // alignment of struct field with this type
enum kind _kind; // enumeration for C
// function for comparing objects of this type
// (ptr to object A, ptr to object B) -> ==?
void* equal;
void* gcdata; // garbage collection data
uint32_t str; // string form
uint32_t ptrToThis; // type for pointer to this type, may be zero
};