Commit 8d36a784 authored by Russ Cox's avatar Russ Cox

reflect: add pointer word to CommonType

The pointer will eventually let us find *T given T.
This CL just makes room for it, always storing a zero.

R=r, r2
CC=golang-dev
https://golang.org/cl/4221046
parent 820dc9ff
...@@ -592,7 +592,8 @@ dcommontype(Sym *s, int ot, Type *t) ...@@ -592,7 +592,8 @@ dcommontype(Sym *s, int ot, Type *t)
// fieldAlign uint8; // fieldAlign uint8;
// kind uint8; // kind uint8;
// string *string; // string *string;
// *nameInfo; // *extraType;
// ptrToThis *Type
// } // }
ot = duintptr(s, ot, t->width); ot = duintptr(s, ot, t->width);
ot = duint32(s, ot, typehash(t)); ot = duint32(s, ot, typehash(t));
...@@ -616,7 +617,7 @@ dcommontype(Sym *s, int ot, Type *t) ...@@ -616,7 +617,7 @@ dcommontype(Sym *s, int ot, Type *t)
ot = dsymptr(s, ot, s1, 0); // extraType ot = dsymptr(s, ot, s1, 0); // extraType
else else
ot = duintptr(s, ot, 0); ot = duintptr(s, ot, 0);
ot = duintptr(s, ot, 0); // ptr type (placeholder for now)
return ot; return ot;
} }
......
...@@ -772,6 +772,9 @@ enum { ...@@ -772,6 +772,9 @@ enum {
KindUnsafePointer, KindUnsafePointer,
KindNoPointers = 1<<7, KindNoPointers = 1<<7,
// size of Type interface header + CommonType structure.
CommonSize = 2*PtrSize+ 4*PtrSize + 8,
}; };
static Reloc* static Reloc*
...@@ -849,59 +852,59 @@ decodetype_size(Sym *s) ...@@ -849,59 +852,59 @@ decodetype_size(Sym *s)
static Sym* static Sym*
decodetype_arrayelem(Sym *s) decodetype_arrayelem(Sym *s)
{ {
return decode_reloc_sym(s, 5*PtrSize + 8); // 0x1c / 0x30 return decode_reloc_sym(s, CommonSize); // 0x1c / 0x30
} }
static vlong static vlong
decodetype_arraylen(Sym *s) decodetype_arraylen(Sym *s)
{ {
return decode_inuxi(s->p + 6*PtrSize + 8, PtrSize); return decode_inuxi(s->p + CommonSize+PtrSize, PtrSize);
} }
// Type.PtrType.elem // Type.PtrType.elem
static Sym* static Sym*
decodetype_ptrelem(Sym *s) decodetype_ptrelem(Sym *s)
{ {
return decode_reloc_sym(s, 5*PtrSize + 8); // 0x1c / 0x30 return decode_reloc_sym(s, CommonSize); // 0x1c / 0x30
} }
// Type.MapType.key, elem // Type.MapType.key, elem
static Sym* static Sym*
decodetype_mapkey(Sym *s) decodetype_mapkey(Sym *s)
{ {
return decode_reloc_sym(s, 5*PtrSize + 8); // 0x1c / 0x30 return decode_reloc_sym(s, CommonSize); // 0x1c / 0x30
} }
static Sym* static Sym*
decodetype_mapvalue(Sym *s) decodetype_mapvalue(Sym *s)
{ {
return decode_reloc_sym(s, 6*PtrSize + 8); // 0x20 / 0x38 return decode_reloc_sym(s, CommonSize+PtrSize); // 0x20 / 0x38
} }
// Type.ChanType.elem // Type.ChanType.elem
static Sym* static Sym*
decodetype_chanelem(Sym *s) decodetype_chanelem(Sym *s)
{ {
return decode_reloc_sym(s, 5*PtrSize + 8); // 0x1c / 0x30 return decode_reloc_sym(s, CommonSize); // 0x1c / 0x30
} }
// Type.FuncType.dotdotdot // Type.FuncType.dotdotdot
static int static int
decodetype_funcdotdotdot(Sym *s) decodetype_funcdotdotdot(Sym *s)
{ {
return s->p[5*PtrSize + 8]; return s->p[CommonSize];
} }
// Type.FuncType.in.len // Type.FuncType.in.len
static int static int
decodetype_funcincount(Sym *s) decodetype_funcincount(Sym *s)
{ {
return decode_inuxi(s->p + 7*PtrSize + 8, 4); return decode_inuxi(s->p + CommonSize+2*PtrSize, 4);
} }
static int static int
decodetype_funcoutcount(Sym *s) decodetype_funcoutcount(Sym *s)
{ {
return decode_inuxi(s->p + 8*PtrSize + 16, 4); return decode_inuxi(s->p + CommonSize+3*PtrSize + 2*4, 4);
} }
static Sym* static Sym*
...@@ -909,7 +912,7 @@ decodetype_funcintype(Sym *s, int i) ...@@ -909,7 +912,7 @@ decodetype_funcintype(Sym *s, int i)
{ {
Reloc *r; Reloc *r;
r = decode_reloc(s, 6*PtrSize + 8); r = decode_reloc(s, CommonSize + PtrSize);
if (r == nil) if (r == nil)
return nil; return nil;
return decode_reloc_sym(r->sym, r->add + i * PtrSize); return decode_reloc_sym(r->sym, r->add + i * PtrSize);
...@@ -920,7 +923,7 @@ decodetype_funcouttype(Sym *s, int i) ...@@ -920,7 +923,7 @@ decodetype_funcouttype(Sym *s, int i)
{ {
Reloc *r; Reloc *r;
r = decode_reloc(s, 7*PtrSize + 16); r = decode_reloc(s, CommonSize + 2*PtrSize + 2*4);
if (r == nil) if (r == nil)
return nil; return nil;
return decode_reloc_sym(r->sym, r->add + i * PtrSize); return decode_reloc_sym(r->sym, r->add + i * PtrSize);
...@@ -930,15 +933,18 @@ decodetype_funcouttype(Sym *s, int i) ...@@ -930,15 +933,18 @@ decodetype_funcouttype(Sym *s, int i)
static int static int
decodetype_structfieldcount(Sym *s) decodetype_structfieldcount(Sym *s)
{ {
return decode_inuxi(s->p + 6*PtrSize + 8, 4); // 0x20 / 0x38 return decode_inuxi(s->p + CommonSize + PtrSize, 4);
} }
// Type.StructType.fields[]-> name, typ and offset. sizeof(structField) = 5*PtrSize enum {
StructFieldSize = 5*PtrSize
};
// Type.StructType.fields[]-> name, typ and offset.
static char* static char*
decodetype_structfieldname(Sym *s, int i) decodetype_structfieldname(Sym *s, int i)
{ {
// go.string."foo" 0x28 / 0x40 // go.string."foo" 0x28 / 0x40
s = decode_reloc_sym(s, 6*PtrSize + 0x10 + i*5*PtrSize); s = decode_reloc_sym(s, CommonSize + PtrSize + 2*4 + i*StructFieldSize);
if (s == nil) // embedded structs have a nil name. if (s == nil) // embedded structs have a nil name.
return nil; return nil;
s = decode_reloc_sym(s, 0); // string."foo" s = decode_reloc_sym(s, 0); // string."foo"
...@@ -950,20 +956,20 @@ decodetype_structfieldname(Sym *s, int i) ...@@ -950,20 +956,20 @@ decodetype_structfieldname(Sym *s, int i)
static Sym* static Sym*
decodetype_structfieldtype(Sym *s, int i) decodetype_structfieldtype(Sym *s, int i)
{ {
return decode_reloc_sym(s, 8*PtrSize + 0x10 + i*5*PtrSize); // 0x30 / 0x50 return decode_reloc_sym(s, CommonSize + PtrSize + 2*4 + i*StructFieldSize + 2*PtrSize);
} }
static vlong static vlong
decodetype_structfieldoffs(Sym *s, int i) decodetype_structfieldoffs(Sym *s, int i)
{ {
return decode_inuxi(s->p + 10*PtrSize + 0x10 + i*5*PtrSize, 4); // 0x38 / 0x60 return decode_inuxi(s->p + CommonSize + PtrSize + 2*4 + i*StructFieldSize + 4*PtrSize, 4);
} }
// InterfaceTYpe.methods.len // InterfaceTYpe.methods.len
static vlong static vlong
decodetype_ifacemethodcount(Sym *s) decodetype_ifacemethodcount(Sym *s)
{ {
return decode_inuxi(s->p + 6*PtrSize + 8, 4); return decode_inuxi(s->p + CommonSize + PtrSize, 4);
} }
......
...@@ -48,6 +48,7 @@ type commonType struct { ...@@ -48,6 +48,7 @@ type commonType struct {
kind uint8 kind uint8
string *string string *string
*uncommonType *uncommonType
ptrToThis *runtime.Type
} }
type method struct { type method struct {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* data structures and must be kept in sync with this file: * data structures and must be kept in sync with this file:
* *
* ../../cmd/gc/reflect.c * ../../cmd/gc/reflect.c
* ../../cmd/ld/dwarf.c * ../../cmd/ld/dwarf.c decodetype_*
* ../reflect/type.go * ../reflect/type.go
* type.h * type.h
*/ */
...@@ -35,6 +35,7 @@ type commonType struct { ...@@ -35,6 +35,7 @@ type commonType struct {
kind uint8 // enumeration for C kind uint8 // enumeration for C
string *string // string form; unnecessary but undeniably useful string *string // string form; unnecessary but undeniably useful
*uncommonType // (relatively) uncommon fields *uncommonType // (relatively) uncommon fields
ptrToThis *Type // pointer to this type, if used in binary or has methods
} }
// Values for commonType.kind. // Values for commonType.kind.
......
...@@ -31,6 +31,7 @@ struct CommonType ...@@ -31,6 +31,7 @@ struct CommonType
uint8 kind; uint8 kind;
String *string; String *string;
UncommonType *x; UncommonType *x;
Type *ptrto;
}; };
enum { enum {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment