mirror of https://github.com/golang/go.git
internal/abi: common up some offset/size functions
Change-Id: I92eeed20af35c7dec309457a80b8fd44eb70b57f Reviewed-on: https://go-review.googlesource.com/c/go/+/467876 Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@google.com>
This commit is contained in:
parent
8e8f4be3f4
commit
3f9521b2f0
|
|
@ -77,15 +77,15 @@ const (
|
||||||
MAXELEMSIZE = abi.MapMaxElemBytes
|
MAXELEMSIZE = abi.MapMaxElemBytes
|
||||||
)
|
)
|
||||||
|
|
||||||
func structfieldSize() int { return 3 * types.PtrSize } // Sizeof(runtime.structfield{})
|
func structfieldSize() int { return abi.StructFieldSize(types.PtrSize) } // Sizeof(runtime.structfield{})
|
||||||
func imethodSize() int { return 4 + 4 } // Sizeof(runtime.imethod{})
|
func imethodSize() int { return abi.IMethodSize(types.PtrSize) } // Sizeof(runtime.imethod{})
|
||||||
func commonSize() int { return 4*types.PtrSize + 8 + 8 } // Sizeof(runtime._type{})
|
func commonSize() int { return abi.CommonSize(types.PtrSize) } // Sizeof(runtime._type{})
|
||||||
|
|
||||||
func uncommonSize(t *types.Type) int { // Sizeof(runtime.uncommontype{})
|
func uncommonSize(t *types.Type) int { // Sizeof(runtime.uncommontype{})
|
||||||
if t.Sym() == nil && len(methods(t)) == 0 {
|
if t.Sym() == nil && len(methods(t)) == 0 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return 4 + 2 + 2 + 4 + 4
|
return int(abi.UncommonSize())
|
||||||
}
|
}
|
||||||
|
|
||||||
func makefield(name string, t *types.Type) *types.Field {
|
func makefield(name string, t *types.Type) *types.Field {
|
||||||
|
|
@ -149,13 +149,13 @@ func MapBucketType(t *types.Type) *types.Type {
|
||||||
base.Fatalf("unsupported map key type for %v", t)
|
base.Fatalf("unsupported map key type for %v", t)
|
||||||
}
|
}
|
||||||
if BUCKETSIZE < 8 {
|
if BUCKETSIZE < 8 {
|
||||||
base.Fatalf("bucket size too small for proper alignment")
|
base.Fatalf("bucket size %d too small for proper alignment %d", BUCKETSIZE, 8)
|
||||||
}
|
}
|
||||||
if uint8(keytype.Alignment()) > BUCKETSIZE {
|
if uint8(keytype.Alignment()) > BUCKETSIZE {
|
||||||
base.Fatalf("key align too big for %v", t)
|
base.Fatalf("key align too big for %v", t)
|
||||||
}
|
}
|
||||||
if uint8(elemtype.Alignment()) > BUCKETSIZE {
|
if uint8(elemtype.Alignment()) > BUCKETSIZE {
|
||||||
base.Fatalf("elem align too big for %v", t)
|
base.Fatalf("elem align %d too big for %v, BUCKETSIZE=%d", elemtype.Alignment(), t, BUCKETSIZE)
|
||||||
}
|
}
|
||||||
if keytype.Size() > MAXKEYSIZE {
|
if keytype.Size() > MAXKEYSIZE {
|
||||||
base.Fatalf("key size to large for %v", t)
|
base.Fatalf("key size to large for %v", t)
|
||||||
|
|
@ -191,7 +191,8 @@ func MapBucketType(t *types.Type) *types.Type {
|
||||||
// Double-check that overflow field is final memory in struct,
|
// Double-check that overflow field is final memory in struct,
|
||||||
// with no padding at end.
|
// with no padding at end.
|
||||||
if overflow.Offset != bucket.Size()-int64(types.PtrSize) {
|
if overflow.Offset != bucket.Size()-int64(types.PtrSize) {
|
||||||
base.Fatalf("bad offset of overflow in bmap for %v", t)
|
base.Fatalf("bad offset of overflow in bmap for %v, overflow.Offset=%d, bucket.Size()-int64(types.PtrSize)=%d",
|
||||||
|
t, overflow.Offset, bucket.Size()-int64(types.PtrSize))
|
||||||
}
|
}
|
||||||
|
|
||||||
t.MapType().Bucket = bucket
|
t.MapType().Bucket = bucket
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,9 @@ func decodeInuxi(arch *sys.Arch, p []byte, sz int) uint64 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func commonsize(arch *sys.Arch) int { return 4*arch.PtrSize + 8 + 8 } // runtime._type
|
func commonsize(arch *sys.Arch) int { return abi.CommonSize(arch.PtrSize) } // runtime._type
|
||||||
func structfieldSize(arch *sys.Arch) int { return 3 * arch.PtrSize } // runtime.structfield
|
func structfieldSize(arch *sys.Arch) int { return abi.StructFieldSize(arch.PtrSize) } // runtime.structfield
|
||||||
func uncommonSize() int { return 4 + 2 + 2 + 4 + 4 } // runtime.uncommontype
|
func uncommonSize(arch *sys.Arch) int { return int(abi.UncommonSize()) } // runtime.uncommontype
|
||||||
|
|
||||||
// Type.commonType.kind
|
// Type.commonType.kind
|
||||||
func decodetypeKind(arch *sys.Arch, p []byte) uint8 {
|
func decodetypeKind(arch *sys.Arch, p []byte) uint8 {
|
||||||
|
|
@ -139,7 +139,7 @@ func decodetypeFuncInType(ldr *loader.Loader, arch *sys.Arch, symIdx loader.Sym,
|
||||||
uadd += 4
|
uadd += 4
|
||||||
}
|
}
|
||||||
if decodetypeHasUncommon(arch, ldr.Data(symIdx)) {
|
if decodetypeHasUncommon(arch, ldr.Data(symIdx)) {
|
||||||
uadd += uncommonSize()
|
uadd += uncommonSize(arch)
|
||||||
}
|
}
|
||||||
return decodeRelocSym(ldr, symIdx, relocs, int32(uadd+i*arch.PtrSize))
|
return decodeRelocSym(ldr, symIdx, relocs, int32(uadd+i*arch.PtrSize))
|
||||||
}
|
}
|
||||||
|
|
@ -187,7 +187,7 @@ func decodetypeStructFieldArrayOff(ldr *loader.Loader, arch *sys.Arch, symIdx lo
|
||||||
data := ldr.Data(symIdx)
|
data := ldr.Data(symIdx)
|
||||||
off := commonsize(arch) + 4*arch.PtrSize
|
off := commonsize(arch) + 4*arch.PtrSize
|
||||||
if decodetypeHasUncommon(arch, data) {
|
if decodetypeHasUncommon(arch, data) {
|
||||||
off += uncommonSize()
|
off += uncommonSize(arch)
|
||||||
}
|
}
|
||||||
off += i * structfieldSize(arch)
|
off += i * structfieldSize(arch)
|
||||||
return off
|
return off
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue