]> Cypherpunks repositories - gostls13.git/commitdiff
internal/abi: common up some offset/size functions
authorDavid Chase <drchase@google.com>
Mon, 13 Feb 2023 23:52:16 +0000 (18:52 -0500)
committerDavid Chase <drchase@google.com>
Wed, 10 May 2023 21:44:05 +0000 (21:44 +0000)
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>
src/cmd/compile/internal/reflectdata/reflect.go
src/cmd/link/internal/ld/decodesym.go

index ede05bfcf762a22c2f612fee803ec6283a5ac4d4..eeda3cb4e2bc334d5c820e71796ed55e37728c40 100644 (file)
@@ -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
index f7293ff032c5be14435b692e17683dc41f78b8a0..7fccc7d980400be5419fe251fc8108309b967861 100644 (file)
@@ -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