From: David Chase Date: Mon, 13 Feb 2023 23:52:16 +0000 (-0500) Subject: internal/abi: common up some offset/size functions X-Git-Tag: go1.21rc1~602 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3f9521b2f00b2dba9781c52ed489372a8b5960fe;p=gostls13.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 TryBot-Result: Gopher Robot Run-TryBot: David Chase Reviewed-by: Keith Randall --- diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go index ede05bfcf7..eeda3cb4e2 100644 --- a/src/cmd/compile/internal/reflectdata/reflect.go +++ b/src/cmd/compile/internal/reflectdata/reflect.go @@ -77,15 +77,15 @@ const ( MAXELEMSIZE = abi.MapMaxElemBytes ) -func structfieldSize() int { return 3 * types.PtrSize } // Sizeof(runtime.structfield{}) -func imethodSize() int { return 4 + 4 } // Sizeof(runtime.imethod{}) -func commonSize() int { return 4*types.PtrSize + 8 + 8 } // Sizeof(runtime._type{}) +func structfieldSize() int { return abi.StructFieldSize(types.PtrSize) } // Sizeof(runtime.structfield{}) +func imethodSize() int { return abi.IMethodSize(types.PtrSize) } // Sizeof(runtime.imethod{}) +func commonSize() int { return abi.CommonSize(types.PtrSize) } // Sizeof(runtime._type{}) func uncommonSize(t *types.Type) int { // Sizeof(runtime.uncommontype{}) if t.Sym() == nil && len(methods(t)) == 0 { return 0 } - return 4 + 2 + 2 + 4 + 4 + return int(abi.UncommonSize()) } 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) } 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 { base.Fatalf("key align too big for %v", t) } 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 { 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, // with no padding at end. 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 diff --git a/src/cmd/link/internal/ld/decodesym.go b/src/cmd/link/internal/ld/decodesym.go index f7293ff032..7fccc7d980 100644 --- a/src/cmd/link/internal/ld/decodesym.go +++ b/src/cmd/link/internal/ld/decodesym.go @@ -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 structfieldSize(arch *sys.Arch) int { return 3 * arch.PtrSize } // runtime.structfield -func uncommonSize() int { return 4 + 2 + 2 + 4 + 4 } // runtime.uncommontype +func commonsize(arch *sys.Arch) int { return abi.CommonSize(arch.PtrSize) } // runtime._type +func structfieldSize(arch *sys.Arch) int { return abi.StructFieldSize(arch.PtrSize) } // runtime.structfield +func uncommonSize(arch *sys.Arch) int { return int(abi.UncommonSize()) } // runtime.uncommontype // Type.commonType.kind 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 } if decodetypeHasUncommon(arch, ldr.Data(symIdx)) { - uadd += uncommonSize() + uadd += uncommonSize(arch) } 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) off := commonsize(arch) + 4*arch.PtrSize if decodetypeHasUncommon(arch, data) { - off += uncommonSize() + off += uncommonSize(arch) } off += i * structfieldSize(arch) return off