all: use kind* of abi

For #59670

Change-Id: Id66e102f13e529dd041b68ce869026a56f0a1b9b
GitHub-Last-Rev: 43aa9376f7
GitHub-Pull-Request: golang/go#65564
Reviewed-on: https://go-review.googlesource.com/c/go/+/562298
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Austin Clements <austin@google.com>
This commit is contained in:
qiulaidongfeng 2024-04-02 13:08:24 +00:00 committed by Gopher Robot
parent e3ec1ca17e
commit daaf1f2220
28 changed files with 235 additions and 313 deletions

View File

@ -624,33 +624,33 @@ func dmethodptrOff(c rttype.Cursor, x *obj.LSym) {
r.Type = objabi.R_METHODOFF r.Type = objabi.R_METHODOFF
} }
var kinds = []int{ var kinds = []abi.Kind{
types.TINT: objabi.KindInt, types.TINT: abi.Int,
types.TUINT: objabi.KindUint, types.TUINT: abi.Uint,
types.TINT8: objabi.KindInt8, types.TINT8: abi.Int8,
types.TUINT8: objabi.KindUint8, types.TUINT8: abi.Uint8,
types.TINT16: objabi.KindInt16, types.TINT16: abi.Int16,
types.TUINT16: objabi.KindUint16, types.TUINT16: abi.Uint16,
types.TINT32: objabi.KindInt32, types.TINT32: abi.Int32,
types.TUINT32: objabi.KindUint32, types.TUINT32: abi.Uint32,
types.TINT64: objabi.KindInt64, types.TINT64: abi.Int64,
types.TUINT64: objabi.KindUint64, types.TUINT64: abi.Uint64,
types.TUINTPTR: objabi.KindUintptr, types.TUINTPTR: abi.Uintptr,
types.TFLOAT32: objabi.KindFloat32, types.TFLOAT32: abi.Float32,
types.TFLOAT64: objabi.KindFloat64, types.TFLOAT64: abi.Float64,
types.TBOOL: objabi.KindBool, types.TBOOL: abi.Bool,
types.TSTRING: objabi.KindString, types.TSTRING: abi.String,
types.TPTR: objabi.KindPtr, types.TPTR: abi.Pointer,
types.TSTRUCT: objabi.KindStruct, types.TSTRUCT: abi.Struct,
types.TINTER: objabi.KindInterface, types.TINTER: abi.Interface,
types.TCHAN: objabi.KindChan, types.TCHAN: abi.Chan,
types.TMAP: objabi.KindMap, types.TMAP: abi.Map,
types.TARRAY: objabi.KindArray, types.TARRAY: abi.Array,
types.TSLICE: objabi.KindSlice, types.TSLICE: abi.Slice,
types.TFUNC: objabi.KindFunc, types.TFUNC: abi.Func,
types.TCOMPLEX64: objabi.KindComplex64, types.TCOMPLEX64: abi.Complex64,
types.TCOMPLEX128: objabi.KindComplex128, types.TCOMPLEX128: abi.Complex128,
types.TUNSAFEPTR: objabi.KindUnsafePointer, types.TUNSAFEPTR: abi.UnsafePointer,
} }
var ( var (
@ -743,14 +743,14 @@ func dcommontype(c rttype.Cursor, t *types.Type) {
c.Field("Align_").WriteUint8(uint8(t.Alignment())) c.Field("Align_").WriteUint8(uint8(t.Alignment()))
c.Field("FieldAlign_").WriteUint8(uint8(t.Alignment())) c.Field("FieldAlign_").WriteUint8(uint8(t.Alignment()))
i = kinds[t.Kind()] kind := kinds[t.Kind()]
if types.IsDirectIface(t) { if types.IsDirectIface(t) {
i |= objabi.KindDirectIface kind |= abi.KindDirectIface
} }
if useGCProg { if useGCProg {
i |= objabi.KindGCProg kind |= abi.KindGCProg
} }
c.Field("Kind_").WriteUint8(uint8(i)) c.Field("Kind_").WriteUint8(uint8(kind))
c.Field("Equal").WritePtr(eqfunc) c.Field("Equal").WritePtr(eqfunc)
c.Field("GCData").WritePtr(gcsym) c.Field("GCData").WritePtr(gcsym)

View File

@ -1,40 +0,0 @@
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package objabi
// Must match runtime and reflect.
// Included by cmd/gc.
const (
KindBool = 1 + iota
KindInt
KindInt8
KindInt16
KindInt32
KindInt64
KindUint
KindUint8
KindUint16
KindUint32
KindUint64
KindUintptr
KindFloat32
KindFloat64
KindComplex64
KindComplex128
KindArray
KindChan
KindFunc
KindInterface
KindMap
KindPtr
KindSlice
KindString
KindStruct
KindUnsafePointer
KindDirectIface = 1 << 5
KindGCProg = 1 << 6
KindMask = (1 << 5) - 1
)

View File

@ -11,6 +11,7 @@ import (
"cmd/link/internal/loader" "cmd/link/internal/loader"
"cmd/link/internal/sym" "cmd/link/internal/sym"
"fmt" "fmt"
"internal/abi"
"internal/buildcfg" "internal/buildcfg"
"strings" "strings"
"unicode" "unicode"
@ -511,7 +512,7 @@ func (d *deadcodePass) decodeIfaceMethod(ldr *loader.Loader, arch *sys.Arch, sym
if p == nil { if p == nil {
panic(fmt.Sprintf("missing symbol %q", ldr.SymName(symIdx))) panic(fmt.Sprintf("missing symbol %q", ldr.SymName(symIdx)))
} }
if decodetypeKind(arch, p)&kindMask != kindInterface { if abi.Kind(decodetypeKind(arch, p)&abi.KindMask) != abi.Interface {
panic(fmt.Sprintf("symbol %q is not an interface", ldr.SymName(symIdx))) panic(fmt.Sprintf("symbol %q is not an interface", ldr.SymName(symIdx)))
} }
relocs := ldr.Relocs(symIdx) relocs := ldr.Relocs(symIdx)
@ -532,22 +533,22 @@ func (d *deadcodePass) decodetypeMethods(ldr *loader.Loader, arch *sys.Arch, sym
panic(fmt.Sprintf("no methods on %q", ldr.SymName(symIdx))) panic(fmt.Sprintf("no methods on %q", ldr.SymName(symIdx)))
} }
off := commonsize(arch) // reflect.rtype off := commonsize(arch) // reflect.rtype
switch decodetypeKind(arch, p) & kindMask { switch abi.Kind(decodetypeKind(arch, p) & abi.KindMask) {
case kindStruct: // reflect.structType case abi.Struct: // reflect.structType
off += 4 * arch.PtrSize off += 4 * arch.PtrSize
case kindPtr: // reflect.ptrType case abi.Pointer: // reflect.ptrType
off += arch.PtrSize off += arch.PtrSize
case kindFunc: // reflect.funcType case abi.Func: // reflect.funcType
off += arch.PtrSize // 4 bytes, pointer aligned off += arch.PtrSize // 4 bytes, pointer aligned
case kindSlice: // reflect.sliceType case abi.Slice: // reflect.sliceType
off += arch.PtrSize off += arch.PtrSize
case kindArray: // reflect.arrayType case abi.Array: // reflect.arrayType
off += 3 * arch.PtrSize off += 3 * arch.PtrSize
case kindChan: // reflect.chanType case abi.Chan: // reflect.chanType
off += 2 * arch.PtrSize off += 2 * arch.PtrSize
case kindMap: // reflect.mapType case abi.Map: // reflect.mapType
off += 4*arch.PtrSize + 8 off += 4*arch.PtrSize + 8
case kindInterface: // reflect.interfaceType case abi.Interface: // reflect.interfaceType
off += 3 * arch.PtrSize off += 3 * arch.PtrSize
default: default:
// just Sizeof(rtype) // just Sizeof(rtype)

View File

@ -5,7 +5,6 @@
package ld package ld
import ( import (
"cmd/internal/objabi"
"cmd/internal/sys" "cmd/internal/sys"
"cmd/link/internal/loader" "cmd/link/internal/loader"
"cmd/link/internal/sym" "cmd/link/internal/sym"
@ -39,12 +38,12 @@ func uncommonSize(arch *sys.Arch) int { return int(abi.UncommonSize()) }
// Type.commonType.kind // Type.commonType.kind
func decodetypeKind(arch *sys.Arch, p []byte) uint8 { func decodetypeKind(arch *sys.Arch, p []byte) uint8 {
return p[2*arch.PtrSize+7] & objabi.KindMask // 0x13 / 0x1f return p[2*arch.PtrSize+7] & abi.KindMask // 0x13 / 0x1f
} }
// Type.commonType.kind // Type.commonType.kind
func decodetypeUsegcprog(arch *sys.Arch, p []byte) uint8 { func decodetypeUsegcprog(arch *sys.Arch, p []byte) uint8 {
return p[2*arch.PtrSize+7] & objabi.KindGCProg // 0x13 / 0x1f return p[2*arch.PtrSize+7] & abi.KindGCProg // 0x13 / 0x1f
} }
// Type.commonType.size // Type.commonType.size
@ -81,19 +80,6 @@ func decodetypeIfaceMethodCount(arch *sys.Arch, p []byte) int64 {
return int64(decodeInuxi(arch, p[commonsize(arch)+2*arch.PtrSize:], arch.PtrSize)) return int64(decodeInuxi(arch, p[commonsize(arch)+2*arch.PtrSize:], arch.PtrSize))
} }
// Matches runtime/typekind.go and reflect.Kind.
const (
kindArray = 17
kindChan = 18
kindFunc = 19
kindInterface = 20
kindMap = 21
kindPtr = 22
kindSlice = 23
kindStruct = 25
kindMask = (1 << 5) - 1
)
func decodeReloc(ldr *loader.Loader, symIdx loader.Sym, relocs *loader.Relocs, off int32) loader.Reloc { func decodeReloc(ldr *loader.Loader, symIdx loader.Sym, relocs *loader.Relocs, off int32) loader.Reloc {
for j := 0; j < relocs.Count(); j++ { for j := 0; j < relocs.Count(); j++ {
rel := relocs.At(j) rel := relocs.At(j)

View File

@ -542,44 +542,44 @@ func (d *dwctxt) newtype(gotype loader.Sym) *dwarf.DWDie {
bytesize := decodetypeSize(d.arch, tdata) bytesize := decodetypeSize(d.arch, tdata)
var die, typedefdie *dwarf.DWDie var die, typedefdie *dwarf.DWDie
switch kind { switch abi.Kind(kind) {
case objabi.KindBool: case abi.Bool:
die = d.newdie(&dwtypes, dwarf.DW_ABRV_BASETYPE, name) die = d.newdie(&dwtypes, dwarf.DW_ABRV_BASETYPE, name)
newattr(die, dwarf.DW_AT_encoding, dwarf.DW_CLS_CONSTANT, dwarf.DW_ATE_boolean, 0) newattr(die, dwarf.DW_AT_encoding, dwarf.DW_CLS_CONSTANT, dwarf.DW_ATE_boolean, 0)
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0) newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0)
case objabi.KindInt, case abi.Int,
objabi.KindInt8, abi.Int8,
objabi.KindInt16, abi.Int16,
objabi.KindInt32, abi.Int32,
objabi.KindInt64: abi.Int64:
die = d.newdie(&dwtypes, dwarf.DW_ABRV_BASETYPE, name) die = d.newdie(&dwtypes, dwarf.DW_ABRV_BASETYPE, name)
newattr(die, dwarf.DW_AT_encoding, dwarf.DW_CLS_CONSTANT, dwarf.DW_ATE_signed, 0) newattr(die, dwarf.DW_AT_encoding, dwarf.DW_CLS_CONSTANT, dwarf.DW_ATE_signed, 0)
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0) newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0)
case objabi.KindUint, case abi.Uint,
objabi.KindUint8, abi.Uint8,
objabi.KindUint16, abi.Uint16,
objabi.KindUint32, abi.Uint32,
objabi.KindUint64, abi.Uint64,
objabi.KindUintptr: abi.Uintptr:
die = d.newdie(&dwtypes, dwarf.DW_ABRV_BASETYPE, name) die = d.newdie(&dwtypes, dwarf.DW_ABRV_BASETYPE, name)
newattr(die, dwarf.DW_AT_encoding, dwarf.DW_CLS_CONSTANT, dwarf.DW_ATE_unsigned, 0) newattr(die, dwarf.DW_AT_encoding, dwarf.DW_CLS_CONSTANT, dwarf.DW_ATE_unsigned, 0)
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0) newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0)
case objabi.KindFloat32, case abi.Float32,
objabi.KindFloat64: abi.Float64:
die = d.newdie(&dwtypes, dwarf.DW_ABRV_BASETYPE, name) die = d.newdie(&dwtypes, dwarf.DW_ABRV_BASETYPE, name)
newattr(die, dwarf.DW_AT_encoding, dwarf.DW_CLS_CONSTANT, dwarf.DW_ATE_float, 0) newattr(die, dwarf.DW_AT_encoding, dwarf.DW_CLS_CONSTANT, dwarf.DW_ATE_float, 0)
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0) newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0)
case objabi.KindComplex64, case abi.Complex64,
objabi.KindComplex128: abi.Complex128:
die = d.newdie(&dwtypes, dwarf.DW_ABRV_BASETYPE, name) die = d.newdie(&dwtypes, dwarf.DW_ABRV_BASETYPE, name)
newattr(die, dwarf.DW_AT_encoding, dwarf.DW_CLS_CONSTANT, dwarf.DW_ATE_complex_float, 0) newattr(die, dwarf.DW_AT_encoding, dwarf.DW_CLS_CONSTANT, dwarf.DW_ATE_complex_float, 0)
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0) newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0)
case objabi.KindArray: case abi.Array:
die = d.newdie(&dwtypes, dwarf.DW_ABRV_ARRAYTYPE, name) die = d.newdie(&dwtypes, dwarf.DW_ABRV_ARRAYTYPE, name)
typedefdie = d.dotypedef(&dwtypes, name, die) typedefdie = d.dotypedef(&dwtypes, name, die)
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0) newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0)
@ -592,7 +592,7 @@ func (d *dwctxt) newtype(gotype loader.Sym) *dwarf.DWDie {
d.newrefattr(fld, dwarf.DW_AT_type, d.uintptrInfoSym) d.newrefattr(fld, dwarf.DW_AT_type, d.uintptrInfoSym)
case objabi.KindChan: case abi.Chan:
die = d.newdie(&dwtypes, dwarf.DW_ABRV_CHANTYPE, name) die = d.newdie(&dwtypes, dwarf.DW_ABRV_CHANTYPE, name)
s := decodetypeChanElem(d.ldr, d.arch, gotype) s := decodetypeChanElem(d.ldr, d.arch, gotype)
d.newrefattr(die, dwarf.DW_AT_go_elem, d.defgotype(s)) d.newrefattr(die, dwarf.DW_AT_go_elem, d.defgotype(s))
@ -600,7 +600,7 @@ func (d *dwctxt) newtype(gotype loader.Sym) *dwarf.DWDie {
// but that would change the order of DIEs we output. // but that would change the order of DIEs we output.
d.newrefattr(die, dwarf.DW_AT_type, s) d.newrefattr(die, dwarf.DW_AT_type, s)
case objabi.KindFunc: case abi.Func:
die = d.newdie(&dwtypes, dwarf.DW_ABRV_FUNCTYPE, name) die = d.newdie(&dwtypes, dwarf.DW_ABRV_FUNCTYPE, name)
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0) newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0)
typedefdie = d.dotypedef(&dwtypes, name, die) typedefdie = d.dotypedef(&dwtypes, name, die)
@ -626,7 +626,7 @@ func (d *dwctxt) newtype(gotype loader.Sym) *dwarf.DWDie {
d.newrefattr(fld, dwarf.DW_AT_type, d.defptrto(d.defgotype(s))) d.newrefattr(fld, dwarf.DW_AT_type, d.defptrto(d.defgotype(s)))
} }
case objabi.KindInterface: case abi.Interface:
die = d.newdie(&dwtypes, dwarf.DW_ABRV_IFACETYPE, name) die = d.newdie(&dwtypes, dwarf.DW_ABRV_IFACETYPE, name)
typedefdie = d.dotypedef(&dwtypes, name, die) typedefdie = d.dotypedef(&dwtypes, name, die)
data := d.ldr.Data(gotype) data := d.ldr.Data(gotype)
@ -639,7 +639,7 @@ func (d *dwctxt) newtype(gotype loader.Sym) *dwarf.DWDie {
} }
d.newrefattr(die, dwarf.DW_AT_type, d.defgotype(s)) d.newrefattr(die, dwarf.DW_AT_type, d.defgotype(s))
case objabi.KindMap: case abi.Map:
die = d.newdie(&dwtypes, dwarf.DW_ABRV_MAPTYPE, name) die = d.newdie(&dwtypes, dwarf.DW_ABRV_MAPTYPE, name)
s := decodetypeMapKey(d.ldr, d.arch, gotype) s := decodetypeMapKey(d.ldr, d.arch, gotype)
d.newrefattr(die, dwarf.DW_AT_go_key, d.defgotype(s)) d.newrefattr(die, dwarf.DW_AT_go_key, d.defgotype(s))
@ -649,13 +649,13 @@ func (d *dwctxt) newtype(gotype loader.Sym) *dwarf.DWDie {
// but that would change the order of the DIEs. // but that would change the order of the DIEs.
d.newrefattr(die, dwarf.DW_AT_type, gotype) d.newrefattr(die, dwarf.DW_AT_type, gotype)
case objabi.KindPtr: case abi.Pointer:
die = d.newdie(&dwtypes, dwarf.DW_ABRV_PTRTYPE, name) die = d.newdie(&dwtypes, dwarf.DW_ABRV_PTRTYPE, name)
typedefdie = d.dotypedef(&dwtypes, name, die) typedefdie = d.dotypedef(&dwtypes, name, die)
s := decodetypePtrElem(d.ldr, d.arch, gotype) s := decodetypePtrElem(d.ldr, d.arch, gotype)
d.newrefattr(die, dwarf.DW_AT_type, d.defgotype(s)) d.newrefattr(die, dwarf.DW_AT_type, d.defgotype(s))
case objabi.KindSlice: case abi.Slice:
die = d.newdie(&dwtypes, dwarf.DW_ABRV_SLICETYPE, name) die = d.newdie(&dwtypes, dwarf.DW_ABRV_SLICETYPE, name)
typedefdie = d.dotypedef(&dwtypes, name, die) typedefdie = d.dotypedef(&dwtypes, name, die)
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0) newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0)
@ -663,11 +663,11 @@ func (d *dwctxt) newtype(gotype loader.Sym) *dwarf.DWDie {
elem := d.defgotype(s) elem := d.defgotype(s)
d.newrefattr(die, dwarf.DW_AT_go_elem, elem) d.newrefattr(die, dwarf.DW_AT_go_elem, elem)
case objabi.KindString: case abi.String:
die = d.newdie(&dwtypes, dwarf.DW_ABRV_STRINGTYPE, name) die = d.newdie(&dwtypes, dwarf.DW_ABRV_STRINGTYPE, name)
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0) newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0)
case objabi.KindStruct: case abi.Struct:
die = d.newdie(&dwtypes, dwarf.DW_ABRV_STRUCTTYPE, name) die = d.newdie(&dwtypes, dwarf.DW_ABRV_STRUCTTYPE, name)
typedefdie = d.dotypedef(&dwtypes, name, die) typedefdie = d.dotypedef(&dwtypes, name, die)
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0) newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0)
@ -688,7 +688,7 @@ func (d *dwctxt) newtype(gotype loader.Sym) *dwarf.DWDie {
} }
} }
case objabi.KindUnsafePointer: case abi.UnsafePointer:
die = d.newdie(&dwtypes, dwarf.DW_ABRV_BARE_PTRTYPE, name) die = d.newdie(&dwtypes, dwarf.DW_ABRV_BARE_PTRTYPE, name)
default: default:
@ -748,7 +748,7 @@ func (d *dwctxt) defptrto(dwtype loader.Sym) loader.Sym {
// pointers of slices. Link to the ones we can find. // pointers of slices. Link to the ones we can find.
gts := d.ldr.Lookup("type:"+ptrname, 0) gts := d.ldr.Lookup("type:"+ptrname, 0)
if gts != 0 && d.ldr.AttrReachable(gts) { if gts != 0 && d.ldr.AttrReachable(gts) {
newattr(pdie, dwarf.DW_AT_go_kind, dwarf.DW_CLS_CONSTANT, int64(objabi.KindPtr), 0) newattr(pdie, dwarf.DW_AT_go_kind, dwarf.DW_CLS_CONSTANT, int64(abi.Pointer), 0)
newattr(pdie, dwarf.DW_AT_go_runtime_type, dwarf.DW_CLS_GO_TYPEREF, 0, dwSym(gts)) newattr(pdie, dwarf.DW_AT_go_runtime_type, dwarf.DW_CLS_GO_TYPEREF, 0, dwSym(gts))
} }
@ -1759,7 +1759,7 @@ func dwarfGenerateDebugInfo(ctxt *Link) {
uintptrDie := d.mkBuiltinType(ctxt, dwarf.DW_ABRV_BASETYPE, "uintptr") uintptrDie := d.mkBuiltinType(ctxt, dwarf.DW_ABRV_BASETYPE, "uintptr")
newattr(uintptrDie, dwarf.DW_AT_encoding, dwarf.DW_CLS_CONSTANT, dwarf.DW_ATE_unsigned, 0) newattr(uintptrDie, dwarf.DW_AT_encoding, dwarf.DW_CLS_CONSTANT, dwarf.DW_ATE_unsigned, 0)
newattr(uintptrDie, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, int64(d.arch.PtrSize), 0) newattr(uintptrDie, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, int64(d.arch.PtrSize), 0)
newattr(uintptrDie, dwarf.DW_AT_go_kind, dwarf.DW_CLS_CONSTANT, objabi.KindUintptr, 0) newattr(uintptrDie, dwarf.DW_AT_go_kind, dwarf.DW_CLS_CONSTANT, int64(abi.Uintptr), 0)
newattr(uintptrDie, dwarf.DW_AT_go_runtime_type, dwarf.DW_CLS_GO_TYPEREF, 0, dwSym(d.lookupOrDiag("type:uintptr"))) newattr(uintptrDie, dwarf.DW_AT_go_runtime_type, dwarf.DW_CLS_GO_TYPEREF, 0, dwSym(d.lookupOrDiag("type:uintptr")))
d.uintptrInfoSym = d.mustFind("uintptr") d.uintptrInfoSym = d.mustFind("uintptr")

View File

@ -24,7 +24,7 @@ type Type struct {
TFlag TFlag // extra type information flags TFlag TFlag // extra type information flags
Align_ uint8 // alignment of variable with this type Align_ uint8 // alignment of variable with this type
FieldAlign_ uint8 // alignment of struct field with this type FieldAlign_ uint8 // alignment of struct field with this type
Kind_ uint8 // enumeration for C Kind_ Kind // enumeration for C
// function for comparing objects of this type // function for comparing objects of this type
// (ptr to object A, ptr to object B) -> ==? // (ptr to object A, ptr to object B) -> ==?
Equal func(unsafe.Pointer, unsafe.Pointer) bool Equal func(unsafe.Pointer, unsafe.Pointer) bool
@ -38,7 +38,7 @@ type Type struct {
// A Kind represents the specific kind of type that a Type represents. // A Kind represents the specific kind of type that a Type represents.
// The zero Kind is not a valid kind. // The zero Kind is not a valid kind.
type Kind uint type Kind uint8
const ( const (
Invalid Kind = iota Invalid Kind = iota

View File

@ -58,7 +58,7 @@ func FuncLayout(t Type, rcvr Type) (frametype Type, argSize, retOffset uintptr,
inReg = append(inReg, bool2byte(abid.inRegPtrs.Get(i))) inReg = append(inReg, bool2byte(abid.inRegPtrs.Get(i)))
outReg = append(outReg, bool2byte(abid.outRegPtrs.Get(i))) outReg = append(outReg, bool2byte(abid.outRegPtrs.Get(i)))
} }
if ft.Kind_&kindGCProg != 0 { if ft.Kind_&abi.KindGCProg != 0 {
panic("can't handle gc programs") panic("can't handle gc programs")
} }
@ -97,7 +97,7 @@ func MapBucketOf(x, y Type) Type {
func CachedBucketOf(m Type) Type { func CachedBucketOf(m Type) Type {
t := m.(*rtype) t := m.(*rtype)
if Kind(t.t.Kind_&kindMask) != Map { if Kind(t.t.Kind_&abi.KindMask) != Map {
panic("not map") panic("not map")
} }
tt := (*mapType)(unsafe.Pointer(t)) tt := (*mapType)(unsafe.Pointer(t))

View File

@ -454,12 +454,6 @@ func (m Method) IsExported() bool {
return m.PkgPath == "" return m.PkgPath == ""
} }
const (
kindDirectIface = 1 << 5
kindGCProg = 1 << 6 // Type.gc points to GC program
kindMask = (1 << 5) - 1
)
// String returns the name of k. // String returns the name of k.
func (k Kind) String() string { func (k Kind) String() string {
if uint(k) < uint(len(kindNames)) { if uint(k) < uint(len(kindNames)) {
@ -2068,7 +2062,7 @@ func bucketOf(ktyp, etyp *abi.Type) *abi.Type {
b := &abi.Type{ b := &abi.Type{
Align_: goarch.PtrSize, Align_: goarch.PtrSize,
Size_: size, Size_: size,
Kind_: uint8(Struct), Kind_: abi.Struct,
PtrBytes: ptrdata, PtrBytes: ptrdata,
GCData: gcdata, GCData: gcdata,
} }
@ -2084,7 +2078,7 @@ func (t *rtype) gcSlice(begin, end uintptr) []byte {
// emitGCMask writes the GC mask for [n]typ into out, starting at bit // emitGCMask writes the GC mask for [n]typ into out, starting at bit
// offset base. // offset base.
func emitGCMask(out []byte, base uintptr, typ *abi.Type, n uintptr) { func emitGCMask(out []byte, base uintptr, typ *abi.Type, n uintptr) {
if typ.Kind_&kindGCProg != 0 { if typ.Kind_&abi.KindGCProg != 0 {
panic("reflect: unexpected GC program") panic("reflect: unexpected GC program")
} }
ptrs := typ.PtrBytes / goarch.PtrSize ptrs := typ.PtrBytes / goarch.PtrSize
@ -2103,7 +2097,7 @@ func emitGCMask(out []byte, base uintptr, typ *abi.Type, n uintptr) {
// appendGCProg appends the GC program for the first ptrdata bytes of // appendGCProg appends the GC program for the first ptrdata bytes of
// typ to dst and returns the extended slice. // typ to dst and returns the extended slice.
func appendGCProg(dst []byte, typ *abi.Type) []byte { func appendGCProg(dst []byte, typ *abi.Type) []byte {
if typ.Kind_&kindGCProg != 0 { if typ.Kind_&abi.KindGCProg != 0 {
// Element has GC program; emit one element. // Element has GC program; emit one element.
n := uintptr(*(*uint32)(unsafe.Pointer(typ.GCData))) n := uintptr(*(*uint32)(unsafe.Pointer(typ.GCData)))
prog := typ.GcSlice(4, 4+n-1) prog := typ.GcSlice(4, 4+n-1)
@ -2283,7 +2277,7 @@ func StructOf(fields []StructField) Type {
} }
f, fpkgpath := runtimeStructField(field) f, fpkgpath := runtimeStructField(field)
ft := f.Typ ft := f.Typ
if ft.Kind_&kindGCProg != 0 { if ft.Kind_&abi.KindGCProg != 0 {
hasGCProg = true hasGCProg = true
} }
if fpkgpath != "" { if fpkgpath != "" {
@ -2372,7 +2366,7 @@ func StructOf(fields []StructField) Type {
// Issue 15924. // Issue 15924.
panic("reflect: embedded type with methods not implemented if type is not first field") panic("reflect: embedded type with methods not implemented if type is not first field")
} }
if len(fields) > 1 && ft.Kind_&kindDirectIface != 0 { if len(fields) > 1 && ft.Kind_&abi.KindDirectIface != 0 {
panic("reflect: embedded type with methods not implemented for non-pointer type") panic("reflect: embedded type with methods not implemented for non-pointer type")
} }
for _, m := range unt.Methods() { for _, m := range unt.Methods() {
@ -2590,10 +2584,10 @@ func StructOf(fields []StructField) Type {
} }
prog = append(prog, 0) prog = append(prog, 0)
*(*uint32)(unsafe.Pointer(&prog[0])) = uint32(len(prog) - 4) *(*uint32)(unsafe.Pointer(&prog[0])) = uint32(len(prog) - 4)
typ.Kind_ |= kindGCProg typ.Kind_ |= abi.KindGCProg
typ.GCData = &prog[0] typ.GCData = &prog[0]
} else { } else {
typ.Kind_ &^= kindGCProg typ.Kind_ &^= abi.KindGCProg
bv := new(bitVector) bv := new(bitVector)
addTypeBits(bv, 0, &typ.Type) addTypeBits(bv, 0, &typ.Type)
if len(bv.data) > 0 { if len(bv.data) > 0 {
@ -2617,9 +2611,9 @@ func StructOf(fields []StructField) Type {
switch { switch {
case len(fs) == 1 && !ifaceIndir(fs[0].Typ): case len(fs) == 1 && !ifaceIndir(fs[0].Typ):
// structs of 1 direct iface type can be direct // structs of 1 direct iface type can be direct
typ.Kind_ |= kindDirectIface typ.Kind_ |= abi.KindDirectIface
default: default:
typ.Kind_ &^= kindDirectIface typ.Kind_ &^= abi.KindDirectIface
} }
return addToCache(toType(&typ.Type)) return addToCache(toType(&typ.Type))
@ -2745,11 +2739,11 @@ func ArrayOf(length int, elem Type) Type {
case length == 1: case length == 1:
// In memory, 1-element array looks just like the element. // In memory, 1-element array looks just like the element.
array.Kind_ |= typ.Kind_ & kindGCProg array.Kind_ |= typ.Kind_ & abi.KindGCProg
array.GCData = typ.GCData array.GCData = typ.GCData
array.PtrBytes = typ.PtrBytes array.PtrBytes = typ.PtrBytes
case typ.Kind_&kindGCProg == 0 && array.Size_ <= abi.MaxPtrmaskBytes*8*goarch.PtrSize: case typ.Kind_&abi.KindGCProg == 0 && array.Size_ <= abi.MaxPtrmaskBytes*8*goarch.PtrSize:
// Element is small with pointer mask; array is still small. // Element is small with pointer mask; array is still small.
// Create direct pointer mask by turning each 1 bit in elem // Create direct pointer mask by turning each 1 bit in elem
// into length 1 bits in larger mask. // into length 1 bits in larger mask.
@ -2786,7 +2780,7 @@ func ArrayOf(length int, elem Type) Type {
prog = appendVarint(prog, uintptr(length)-1) prog = appendVarint(prog, uintptr(length)-1)
prog = append(prog, 0) prog = append(prog, 0)
*(*uint32)(unsafe.Pointer(&prog[0])) = uint32(len(prog) - 4) *(*uint32)(unsafe.Pointer(&prog[0])) = uint32(len(prog) - 4)
array.Kind_ |= kindGCProg array.Kind_ |= abi.KindGCProg
array.GCData = &prog[0] array.GCData = &prog[0]
array.PtrBytes = array.Size_ // overestimate but ok; must match program array.PtrBytes = array.Size_ // overestimate but ok; must match program
} }
@ -2812,9 +2806,9 @@ func ArrayOf(length int, elem Type) Type {
switch { switch {
case length == 1 && !ifaceIndir(typ): case length == 1 && !ifaceIndir(typ):
// array of 1 direct iface type can be direct // array of 1 direct iface type can be direct
array.Kind_ |= kindDirectIface array.Kind_ |= abi.KindDirectIface
default: default:
array.Kind_ &^= kindDirectIface array.Kind_ &^= abi.KindDirectIface
} }
ti, _ := lookupCache.LoadOrStore(ckey, toRType(&array.Type)) ti, _ := lookupCache.LoadOrStore(ckey, toRType(&array.Type))
@ -2914,7 +2908,7 @@ func funcLayout(t *funcType, rcvr *abi.Type) (frametype *abi.Type, framePool *sy
// ifaceIndir reports whether t is stored indirectly in an interface value. // ifaceIndir reports whether t is stored indirectly in an interface value.
func ifaceIndir(t *abi.Type) bool { func ifaceIndir(t *abi.Type) bool {
return t.Kind_&kindDirectIface == 0 return t.Kind_&abi.KindDirectIface == 0
} }
// Note: this type must agree with runtime.bitvector. // Note: this type must agree with runtime.bitvector.
@ -2942,7 +2936,7 @@ func addTypeBits(bv *bitVector, offset uintptr, t *abi.Type) {
return return
} }
switch Kind(t.Kind_ & kindMask) { switch Kind(t.Kind_ & abi.KindMask) {
case Chan, Func, Map, Pointer, Slice, String, UnsafePointer: case Chan, Func, Map, Pointer, Slice, String, UnsafePointer:
// 1 pointer at start of representation // 1 pointer at start of representation
for bv.n < uint32(offset/uintptr(goarch.PtrSize)) { for bv.n < uint32(offset/uintptr(goarch.PtrSize)) {

View File

@ -154,30 +154,30 @@ func typehash(t *_type, p unsafe.Pointer, h uintptr) uintptr {
return memhash(p, h, t.Size_) return memhash(p, h, t.Size_)
} }
} }
switch t.Kind_ & kindMask { switch t.Kind_ & abi.KindMask {
case kindFloat32: case abi.Float32:
return f32hash(p, h) return f32hash(p, h)
case kindFloat64: case abi.Float64:
return f64hash(p, h) return f64hash(p, h)
case kindComplex64: case abi.Complex64:
return c64hash(p, h) return c64hash(p, h)
case kindComplex128: case abi.Complex128:
return c128hash(p, h) return c128hash(p, h)
case kindString: case abi.String:
return strhash(p, h) return strhash(p, h)
case kindInterface: case abi.Interface:
i := (*interfacetype)(unsafe.Pointer(t)) i := (*interfacetype)(unsafe.Pointer(t))
if len(i.Methods) == 0 { if len(i.Methods) == 0 {
return nilinterhash(p, h) return nilinterhash(p, h)
} }
return interhash(p, h) return interhash(p, h)
case kindArray: case abi.Array:
a := (*arraytype)(unsafe.Pointer(t)) a := (*arraytype)(unsafe.Pointer(t))
for i := uintptr(0); i < a.Len; i++ { for i := uintptr(0); i < a.Len; i++ {
h = typehash(a.Elem, add(p, i*a.Elem.Size_), h) h = typehash(a.Elem, add(p, i*a.Elem.Size_), h)
} }
return h return h
case kindStruct: case abi.Struct:
s := (*structtype)(unsafe.Pointer(t)) s := (*structtype)(unsafe.Pointer(t))
for _, f := range s.Fields { for _, f := range s.Fields {
if f.Name.IsBlank() { if f.Name.IsBlank() {
@ -204,10 +204,10 @@ func mapKeyError2(t *_type, p unsafe.Pointer) error {
if t.TFlag&abi.TFlagRegularMemory != 0 { if t.TFlag&abi.TFlagRegularMemory != 0 {
return nil return nil
} }
switch t.Kind_ & kindMask { switch t.Kind_ & abi.KindMask {
case kindFloat32, kindFloat64, kindComplex64, kindComplex128, kindString: case abi.Float32, abi.Float64, abi.Complex64, abi.Complex128, abi.String:
return nil return nil
case kindInterface: case abi.Interface:
i := (*interfacetype)(unsafe.Pointer(t)) i := (*interfacetype)(unsafe.Pointer(t))
var t *_type var t *_type
var pdata *unsafe.Pointer var pdata *unsafe.Pointer
@ -236,7 +236,7 @@ func mapKeyError2(t *_type, p unsafe.Pointer) error {
} else { } else {
return mapKeyError2(t, *pdata) return mapKeyError2(t, *pdata)
} }
case kindArray: case abi.Array:
a := (*arraytype)(unsafe.Pointer(t)) a := (*arraytype)(unsafe.Pointer(t))
for i := uintptr(0); i < a.Len; i++ { for i := uintptr(0); i < a.Len; i++ {
if err := mapKeyError2(a.Elem, add(p, i*a.Elem.Size_)); err != nil { if err := mapKeyError2(a.Elem, add(p, i*a.Elem.Size_)); err != nil {
@ -244,7 +244,7 @@ func mapKeyError2(t *_type, p unsafe.Pointer) error {
} }
} }
return nil return nil
case kindStruct: case abi.Struct:
s := (*structtype)(unsafe.Pointer(t)) s := (*structtype)(unsafe.Pointer(t))
for _, f := range s.Fields { for _, f := range s.Fields {
if f.Name.IsBlank() { if f.Name.IsBlank() {

View File

@ -83,6 +83,7 @@
package runtime package runtime
import ( import (
"internal/abi"
"internal/goarch" "internal/goarch"
"internal/goexperiment" "internal/goexperiment"
"internal/runtime/atomic" "internal/runtime/atomic"
@ -110,7 +111,7 @@ func arena_newArena() unsafe.Pointer {
//go:linkname arena_arena_New arena.runtime_arena_arena_New //go:linkname arena_arena_New arena.runtime_arena_arena_New
func arena_arena_New(arena unsafe.Pointer, typ any) any { func arena_arena_New(arena unsafe.Pointer, typ any) any {
t := (*_type)(efaceOf(&typ).data) t := (*_type)(efaceOf(&typ).data)
if t.Kind_&kindMask != kindPtr { if t.Kind_&abi.KindMask != abi.Pointer {
throw("arena_New: non-pointer type") throw("arena_New: non-pointer type")
} }
te := (*ptrtype)(unsafe.Pointer(t)).Elem te := (*ptrtype)(unsafe.Pointer(t)).Elem
@ -144,12 +145,12 @@ func arena_heapify(s any) any {
var v unsafe.Pointer var v unsafe.Pointer
e := efaceOf(&s) e := efaceOf(&s)
t := e._type t := e._type
switch t.Kind_ & kindMask { switch t.Kind_ & abi.KindMask {
case kindString: case abi.String:
v = stringStructOf((*string)(e.data)).str v = stringStructOf((*string)(e.data)).str
case kindSlice: case abi.Slice:
v = (*slice)(e.data).array v = (*slice)(e.data).array
case kindPtr: case abi.Pointer:
v = e.data v = e.data
default: default:
panic("arena: Clone only supports pointers, slices, and strings") panic("arena: Clone only supports pointers, slices, and strings")
@ -161,13 +162,13 @@ func arena_heapify(s any) any {
} }
// Heap-allocate storage for a copy. // Heap-allocate storage for a copy.
var x any var x any
switch t.Kind_ & kindMask { switch t.Kind_ & abi.KindMask {
case kindString: case abi.String:
s1 := s.(string) s1 := s.(string)
s2, b := rawstring(len(s1)) s2, b := rawstring(len(s1))
copy(b, s1) copy(b, s1)
x = s2 x = s2
case kindSlice: case abi.Slice:
len := (*slice)(e.data).len len := (*slice)(e.data).len
et := (*slicetype)(unsafe.Pointer(t)).Elem et := (*slicetype)(unsafe.Pointer(t)).Elem
sl := new(slice) sl := new(slice)
@ -175,7 +176,7 @@ func arena_heapify(s any) any {
xe := efaceOf(&x) xe := efaceOf(&x)
xe._type = t xe._type = t
xe.data = unsafe.Pointer(sl) xe.data = unsafe.Pointer(sl)
case kindPtr: case abi.Pointer:
et := (*ptrtype)(unsafe.Pointer(t)).Elem et := (*ptrtype)(unsafe.Pointer(t)).Elem
e2 := newobject(et) e2 := newobject(et)
typedmemmove(et, e2, e.data) typedmemmove(et, e2, e.data)
@ -295,11 +296,11 @@ func (a *userArena) slice(sl any, cap int) {
} }
i := efaceOf(&sl) i := efaceOf(&sl)
typ := i._type typ := i._type
if typ.Kind_&kindMask != kindPtr { if typ.Kind_&abi.KindMask != abi.Pointer {
panic("slice result of non-ptr type") panic("slice result of non-ptr type")
} }
typ = (*ptrtype)(unsafe.Pointer(typ)).Elem typ = (*ptrtype)(unsafe.Pointer(typ)).Elem
if typ.Kind_&kindMask != kindSlice { if typ.Kind_&abi.KindMask != abi.Slice {
panic("slice of non-ptr-to-slice type") panic("slice of non-ptr-to-slice type")
} }
typ = (*slicetype)(unsafe.Pointer(typ)).Elem typ = (*slicetype)(unsafe.Pointer(typ)).Elem

View File

@ -85,6 +85,7 @@
package runtime package runtime
import ( import (
"internal/abi"
"internal/goarch" "internal/goarch"
"internal/goexperiment" "internal/goexperiment"
"runtime/internal/sys" "runtime/internal/sys"
@ -501,29 +502,29 @@ func cgoCheckPointer(ptr any, arg any) {
t := ep._type t := ep._type
top := true top := true
if arg != nil && (t.Kind_&kindMask == kindPtr || t.Kind_&kindMask == kindUnsafePointer) { if arg != nil && (t.Kind_&abi.KindMask == abi.Pointer || t.Kind_&abi.KindMask == abi.UnsafePointer) {
p := ep.data p := ep.data
if t.Kind_&kindDirectIface == 0 { if t.Kind_&abi.KindDirectIface == 0 {
p = *(*unsafe.Pointer)(p) p = *(*unsafe.Pointer)(p)
} }
if p == nil || !cgoIsGoPointer(p) { if p == nil || !cgoIsGoPointer(p) {
return return
} }
aep := efaceOf(&arg) aep := efaceOf(&arg)
switch aep._type.Kind_ & kindMask { switch aep._type.Kind_ & abi.KindMask {
case kindBool: case abi.Bool:
if t.Kind_&kindMask == kindUnsafePointer { if t.Kind_&abi.KindMask == abi.UnsafePointer {
// We don't know the type of the element. // We don't know the type of the element.
break break
} }
pt := (*ptrtype)(unsafe.Pointer(t)) pt := (*ptrtype)(unsafe.Pointer(t))
cgoCheckArg(pt.Elem, p, true, false, cgoCheckPointerFail) cgoCheckArg(pt.Elem, p, true, false, cgoCheckPointerFail)
return return
case kindSlice: case abi.Slice:
// Check the slice rather than the pointer. // Check the slice rather than the pointer.
ep = aep ep = aep
t = ep._type t = ep._type
case kindArray: case abi.Array:
// Check the array rather than the pointer. // Check the array rather than the pointer.
// Pass top as false since we have a pointer // Pass top as false since we have a pointer
// to the array. // to the array.
@ -535,7 +536,7 @@ func cgoCheckPointer(ptr any, arg any) {
} }
} }
cgoCheckArg(t, ep.data, t.Kind_&kindDirectIface == 0, top, cgoCheckPointerFail) cgoCheckArg(t, ep.data, t.Kind_&abi.KindDirectIface == 0, top, cgoCheckPointerFail)
} }
const cgoCheckPointerFail = "cgo argument has Go pointer to unpinned Go pointer" const cgoCheckPointerFail = "cgo argument has Go pointer to unpinned Go pointer"
@ -552,28 +553,28 @@ func cgoCheckArg(t *_type, p unsafe.Pointer, indir, top bool, msg string) {
return return
} }
switch t.Kind_ & kindMask { switch t.Kind_ & abi.KindMask {
default: default:
throw("can't happen") throw("can't happen")
case kindArray: case abi.Array:
at := (*arraytype)(unsafe.Pointer(t)) at := (*arraytype)(unsafe.Pointer(t))
if !indir { if !indir {
if at.Len != 1 { if at.Len != 1 {
throw("can't happen") throw("can't happen")
} }
cgoCheckArg(at.Elem, p, at.Elem.Kind_&kindDirectIface == 0, top, msg) cgoCheckArg(at.Elem, p, at.Elem.Kind_&abi.KindDirectIface == 0, top, msg)
return return
} }
for i := uintptr(0); i < at.Len; i++ { for i := uintptr(0); i < at.Len; i++ {
cgoCheckArg(at.Elem, p, true, top, msg) cgoCheckArg(at.Elem, p, true, top, msg)
p = add(p, at.Elem.Size_) p = add(p, at.Elem.Size_)
} }
case kindChan, kindMap: case abi.Chan, abi.Map:
// These types contain internal pointers that will // These types contain internal pointers that will
// always be allocated in the Go heap. It's never OK // always be allocated in the Go heap. It's never OK
// to pass them to C. // to pass them to C.
panic(errorString(msg)) panic(errorString(msg))
case kindFunc: case abi.Func:
if indir { if indir {
p = *(*unsafe.Pointer)(p) p = *(*unsafe.Pointer)(p)
} }
@ -581,7 +582,7 @@ func cgoCheckArg(t *_type, p unsafe.Pointer, indir, top bool, msg string) {
return return
} }
panic(errorString(msg)) panic(errorString(msg))
case kindInterface: case abi.Interface:
it := *(**_type)(p) it := *(**_type)(p)
if it == nil { if it == nil {
return return
@ -599,8 +600,8 @@ func cgoCheckArg(t *_type, p unsafe.Pointer, indir, top bool, msg string) {
if !top && !isPinned(p) { if !top && !isPinned(p) {
panic(errorString(msg)) panic(errorString(msg))
} }
cgoCheckArg(it, p, it.Kind_&kindDirectIface == 0, false, msg) cgoCheckArg(it, p, it.Kind_&abi.KindDirectIface == 0, false, msg)
case kindSlice: case abi.Slice:
st := (*slicetype)(unsafe.Pointer(t)) st := (*slicetype)(unsafe.Pointer(t))
s := (*slice)(p) s := (*slice)(p)
p = s.array p = s.array
@ -617,7 +618,7 @@ func cgoCheckArg(t *_type, p unsafe.Pointer, indir, top bool, msg string) {
cgoCheckArg(st.Elem, p, true, false, msg) cgoCheckArg(st.Elem, p, true, false, msg)
p = add(p, st.Elem.Size_) p = add(p, st.Elem.Size_)
} }
case kindString: case abi.String:
ss := (*stringStruct)(p) ss := (*stringStruct)(p)
if !cgoIsGoPointer(ss.str) { if !cgoIsGoPointer(ss.str) {
return return
@ -625,13 +626,13 @@ func cgoCheckArg(t *_type, p unsafe.Pointer, indir, top bool, msg string) {
if !top && !isPinned(ss.str) { if !top && !isPinned(ss.str) {
panic(errorString(msg)) panic(errorString(msg))
} }
case kindStruct: case abi.Struct:
st := (*structtype)(unsafe.Pointer(t)) st := (*structtype)(unsafe.Pointer(t))
if !indir { if !indir {
if len(st.Fields) != 1 { if len(st.Fields) != 1 {
throw("can't happen") throw("can't happen")
} }
cgoCheckArg(st.Fields[0].Typ, p, st.Fields[0].Typ.Kind_&kindDirectIface == 0, top, msg) cgoCheckArg(st.Fields[0].Typ, p, st.Fields[0].Typ.Kind_&abi.KindDirectIface == 0, top, msg)
return return
} }
for _, f := range st.Fields { for _, f := range st.Fields {
@ -640,7 +641,7 @@ func cgoCheckArg(t *_type, p unsafe.Pointer, indir, top bool, msg string) {
} }
cgoCheckArg(f.Typ, add(p, f.Offset), true, top, msg) cgoCheckArg(f.Typ, add(p, f.Offset), true, top, msg)
} }
case kindPtr, kindUnsafePointer: case abi.Pointer, abi.UnsafePointer:
if indir { if indir {
p = *(*unsafe.Pointer)(p) p = *(*unsafe.Pointer)(p)
if p == nil { if p == nil {
@ -754,5 +755,5 @@ func cgoCheckResult(val any) {
ep := efaceOf(&val) ep := efaceOf(&val)
t := ep._type t := ep._type
cgoCheckArg(t, ep.data, t.Kind_&kindDirectIface == 0, false, cgoResultFail) cgoCheckArg(t, ep.data, t.Kind_&abi.KindDirectIface == 0, false, cgoResultFail)
} }

View File

@ -8,6 +8,7 @@
package runtime package runtime
import ( import (
"internal/abi"
"internal/goarch" "internal/goarch"
"internal/goexperiment" "internal/goexperiment"
"unsafe" "unsafe"
@ -142,7 +143,7 @@ func cgoCheckTypedBlock(typ *_type, src unsafe.Pointer, off, size uintptr) {
size = ptrdataSize size = ptrdataSize
} }
if typ.Kind_&kindGCProg == 0 { if typ.Kind_&abi.KindGCProg == 0 {
cgoCheckBits(src, typ.GCData, off, size) cgoCheckBits(src, typ.GCData, off, size)
return return
} }
@ -259,14 +260,14 @@ func cgoCheckUsingType(typ *_type, src unsafe.Pointer, off, size uintptr) {
size = ptrdataSize size = ptrdataSize
} }
if typ.Kind_&kindGCProg == 0 { if typ.Kind_&abi.KindGCProg == 0 {
cgoCheckBits(src, typ.GCData, off, size) cgoCheckBits(src, typ.GCData, off, size)
return return
} }
switch typ.Kind_ & kindMask { switch typ.Kind_ & abi.KindMask {
default: default:
throw("can't happen") throw("can't happen")
case kindArray: case abi.Array:
at := (*arraytype)(unsafe.Pointer(typ)) at := (*arraytype)(unsafe.Pointer(typ))
for i := uintptr(0); i < at.Len; i++ { for i := uintptr(0); i < at.Len; i++ {
if off < at.Elem.Size_ { if off < at.Elem.Size_ {
@ -284,7 +285,7 @@ func cgoCheckUsingType(typ *_type, src unsafe.Pointer, off, size uintptr) {
} }
size -= checked size -= checked
} }
case kindStruct: case abi.Struct:
st := (*structtype)(unsafe.Pointer(typ)) st := (*structtype)(unsafe.Pointer(typ))
for _, f := range st.Fields { for _, f := range st.Fields {
if off < f.Typ.Size_ { if off < f.Typ.Size_ {

View File

@ -16,6 +16,7 @@
package runtime package runtime
import ( import (
"internal/abi"
"internal/runtime/atomic" "internal/runtime/atomic"
"runtime/internal/sys" "runtime/internal/sys"
"unsafe" "unsafe"
@ -277,8 +278,8 @@ func (l *dlogger) p(x any) *dlogger {
l.w.uvarint(0) l.w.uvarint(0)
} else { } else {
v := efaceOf(&x) v := efaceOf(&x)
switch v._type.Kind_ & kindMask { switch v._type.Kind_ & abi.KindMask {
case kindChan, kindFunc, kindMap, kindPtr, kindUnsafePointer: case abi.Chan, abi.Func, abi.Map, abi.Pointer, abi.UnsafePointer:
l.w.uvarint(uint64(uintptr(v.data))) l.w.uvarint(uint64(uintptr(v.data)))
default: default:
throw("not a pointer type") throw("not a pointer type")

View File

@ -4,7 +4,10 @@
package runtime package runtime
import "internal/bytealg" import (
"internal/abi"
"internal/bytealg"
)
// The Error interface identifies a run time error. // The Error interface identifies a run time error.
type Error interface { type Error interface {
@ -259,39 +262,39 @@ func printanycustomtype(i any) {
typestring := toRType(eface._type).string() typestring := toRType(eface._type).string()
switch eface._type.Kind_ { switch eface._type.Kind_ {
case kindString: case abi.String:
print(typestring, `("`, *(*string)(eface.data), `")`) print(typestring, `("`, *(*string)(eface.data), `")`)
case kindBool: case abi.Bool:
print(typestring, "(", *(*bool)(eface.data), ")") print(typestring, "(", *(*bool)(eface.data), ")")
case kindInt: case abi.Int:
print(typestring, "(", *(*int)(eface.data), ")") print(typestring, "(", *(*int)(eface.data), ")")
case kindInt8: case abi.Int8:
print(typestring, "(", *(*int8)(eface.data), ")") print(typestring, "(", *(*int8)(eface.data), ")")
case kindInt16: case abi.Int16:
print(typestring, "(", *(*int16)(eface.data), ")") print(typestring, "(", *(*int16)(eface.data), ")")
case kindInt32: case abi.Int32:
print(typestring, "(", *(*int32)(eface.data), ")") print(typestring, "(", *(*int32)(eface.data), ")")
case kindInt64: case abi.Int64:
print(typestring, "(", *(*int64)(eface.data), ")") print(typestring, "(", *(*int64)(eface.data), ")")
case kindUint: case abi.Uint:
print(typestring, "(", *(*uint)(eface.data), ")") print(typestring, "(", *(*uint)(eface.data), ")")
case kindUint8: case abi.Uint8:
print(typestring, "(", *(*uint8)(eface.data), ")") print(typestring, "(", *(*uint8)(eface.data), ")")
case kindUint16: case abi.Uint16:
print(typestring, "(", *(*uint16)(eface.data), ")") print(typestring, "(", *(*uint16)(eface.data), ")")
case kindUint32: case abi.Uint32:
print(typestring, "(", *(*uint32)(eface.data), ")") print(typestring, "(", *(*uint32)(eface.data), ")")
case kindUint64: case abi.Uint64:
print(typestring, "(", *(*uint64)(eface.data), ")") print(typestring, "(", *(*uint64)(eface.data), ")")
case kindUintptr: case abi.Uintptr:
print(typestring, "(", *(*uintptr)(eface.data), ")") print(typestring, "(", *(*uintptr)(eface.data), ")")
case kindFloat32: case abi.Float32:
print(typestring, "(", *(*float32)(eface.data), ")") print(typestring, "(", *(*float32)(eface.data), ")")
case kindFloat64: case abi.Float64:
print(typestring, "(", *(*float64)(eface.data), ")") print(typestring, "(", *(*float64)(eface.data), ")")
case kindComplex64: case abi.Complex64:
print(typestring, *(*complex64)(eface.data)) print(typestring, *(*complex64)(eface.data))
case kindComplex128: case abi.Complex128:
print(typestring, *(*complex128)(eface.data)) print(typestring, *(*complex128)(eface.data))
default: default:
print("(", typestring, ") ", eface.data) print("(", typestring, ") ", eface.data)

View File

@ -32,13 +32,13 @@ func InjectDebugCall(gp *g, fn any, regArgs *abi.RegArgs, stackArgs any, tkill f
} }
f := efaceOf(&fn) f := efaceOf(&fn)
if f._type == nil || f._type.Kind_&kindMask != kindFunc { if f._type == nil || f._type.Kind_&abi.KindMask != abi.Func {
return nil, plainError("fn must be a function") return nil, plainError("fn must be a function")
} }
fv := (*funcval)(f.data) fv := (*funcval)(f.data)
a := efaceOf(&stackArgs) a := efaceOf(&stackArgs)
if a._type != nil && a._type.Kind_&kindMask != kindPtr { if a._type != nil && a._type.Kind_&abi.KindMask != abi.Pointer {
return nil, plainError("args must be a pointer or nil") return nil, plainError("args must be a pointer or nil")
} }
argp := a.data argp := a.data

View File

@ -1909,7 +1909,7 @@ func NewUserArena() *UserArena {
func (a *UserArena) New(out *any) { func (a *UserArena) New(out *any) {
i := efaceOf(out) i := efaceOf(out)
typ := i._type typ := i._type
if typ.Kind_&kindMask != kindPtr { if typ.Kind_&abi.KindMask != abi.Pointer {
panic("new result of non-ptr type") panic("new result of non-ptr type")
} }
typ = (*ptrtype)(unsafe.Pointer(typ)).Elem typ = (*ptrtype)(unsafe.Pointer(typ)).Elem

View File

@ -206,7 +206,7 @@ func dumptype(t *_type) {
dwritebyte('.') dwritebyte('.')
dwrite(unsafe.Pointer(unsafe.StringData(name)), uintptr(len(name))) dwrite(unsafe.Pointer(unsafe.StringData(name)), uintptr(len(name)))
} }
dumpbool(t.Kind_&kindDirectIface == 0 || t.Pointers()) dumpbool(t.Kind_&abi.KindDirectIface == 0 || t.PtrBytes != 0)
} }
// dump an object. // dump an object.

View File

@ -5,6 +5,7 @@
package runtime package runtime
import ( import (
"internal/abi"
"internal/goarch" "internal/goarch"
"internal/runtime/atomic" "internal/runtime/atomic"
"runtime/internal/sys" "runtime/internal/sys"
@ -413,7 +414,7 @@ func typeBitsBulkBarrier(typ *_type, dst, src, size uintptr) {
println("runtime: typeBitsBulkBarrier with type ", toRType(typ).string(), " of size ", typ.Size_, " but memory size", size) println("runtime: typeBitsBulkBarrier with type ", toRType(typ).string(), " of size ", typ.Size_, " but memory size", size)
throw("runtime: invalid typeBitsBulkBarrier") throw("runtime: invalid typeBitsBulkBarrier")
} }
if typ.Kind_&kindGCProg != 0 { if typ.Kind_&abi.KindGCProg != 0 {
println("runtime: typeBitsBulkBarrier with type ", toRType(typ).string(), " with GC prog") println("runtime: typeBitsBulkBarrier with type ", toRType(typ).string(), " with GC prog")
throw("runtime: invalid typeBitsBulkBarrier") throw("runtime: invalid typeBitsBulkBarrier")
} }

View File

@ -215,7 +215,7 @@ func (span *mspan) typePointersOfUnchecked(addr uintptr) typePointers {
//go:nosplit //go:nosplit
func (span *mspan) typePointersOfType(typ *abi.Type, addr uintptr) typePointers { func (span *mspan) typePointersOfType(typ *abi.Type, addr uintptr) typePointers {
const doubleCheck = false const doubleCheck = false
if doubleCheck && (typ == nil || typ.Kind_&kindGCProg != 0) { if doubleCheck && (typ == nil || typ.Kind_&abi.KindGCProg != 0) {
throw("bad type passed to typePointersOfType") throw("bad type passed to typePointersOfType")
} }
if span.spanclass.noscan() { if span.spanclass.noscan() {
@ -459,7 +459,7 @@ func bulkBarrierPreWrite(dst, src, size uintptr, typ *abi.Type) {
} }
var tp typePointers var tp typePointers
if typ != nil && typ.Kind_&kindGCProg == 0 { if typ != nil && typ.Kind_&abi.KindGCProg == 0 {
tp = s.typePointersOfType(typ, dst) tp = s.typePointersOfType(typ, dst)
} else { } else {
tp = s.typePointersOf(dst, size) tp = s.typePointersOf(dst, size)
@ -520,7 +520,7 @@ func bulkBarrierPreWriteSrcOnly(dst, src, size uintptr, typ *abi.Type) {
} }
var tp typePointers var tp typePointers
if typ != nil && typ.Kind_&kindGCProg == 0 { if typ != nil && typ.Kind_&abi.KindGCProg == 0 {
tp = s.typePointersOfType(typ, dst) tp = s.typePointersOfType(typ, dst)
} else { } else {
tp = s.typePointersOf(dst, size) tp = s.typePointersOf(dst, size)
@ -860,7 +860,7 @@ func heapSetType(x, dataSize uintptr, typ *_type, header **_type, span *mspan) (
// Handle the case where we have no malloc header. // Handle the case where we have no malloc header.
scanSize = span.writeHeapBitsSmall(x, dataSize, typ) scanSize = span.writeHeapBitsSmall(x, dataSize, typ)
} else { } else {
if typ.Kind_&kindGCProg != 0 { if typ.Kind_&abi.KindGCProg != 0 {
// Allocate space to unroll the gcprog. This space will consist of // Allocate space to unroll the gcprog. This space will consist of
// a dummy _type value and the unrolled gcprog. The dummy _type will // a dummy _type value and the unrolled gcprog. The dummy _type will
// refer to the bitmap, and the mspan will refer to the dummy _type. // refer to the bitmap, and the mspan will refer to the dummy _type.
@ -964,7 +964,7 @@ func doubleCheckHeapPointers(x, dataSize uintptr, typ *_type, header **_type, sp
} }
println("runtime: extra pointer:", hex(addr)) println("runtime: extra pointer:", hex(addr))
} }
print("runtime: hasHeader=", header != nil, " typ.Size_=", typ.Size_, " hasGCProg=", typ.Kind_&kindGCProg != 0, "\n") print("runtime: hasHeader=", header != nil, " typ.Size_=", typ.Size_, " hasGCProg=", typ.Kind_&abi.KindGCProg != 0, "\n")
print("runtime: x=", hex(x), " dataSize=", dataSize, " elemsize=", span.elemsize, "\n") print("runtime: x=", hex(x), " dataSize=", dataSize, " elemsize=", span.elemsize, "\n")
print("runtime: typ=", unsafe.Pointer(typ), " typ.PtrBytes=", typ.PtrBytes, "\n") print("runtime: typ=", unsafe.Pointer(typ), " typ.PtrBytes=", typ.PtrBytes, "\n")
print("runtime: limit=", hex(x+span.elemsize), "\n") print("runtime: limit=", hex(x+span.elemsize), "\n")
@ -1062,10 +1062,10 @@ func doubleCheckHeapPointersInterior(x, interior, size, dataSize uintptr, typ *_
//go:nosplit //go:nosplit
func doubleCheckTypePointersOfType(s *mspan, typ *_type, addr, size uintptr) { func doubleCheckTypePointersOfType(s *mspan, typ *_type, addr, size uintptr) {
if typ == nil || typ.Kind_&kindGCProg != 0 { if typ == nil || typ.Kind_&abi.KindGCProg != 0 {
return return
} }
if typ.Kind_&kindMask == kindInterface { if typ.Kind_&abi.KindMask == abi.Interface {
// Interfaces are unfortunately inconsistently handled // Interfaces are unfortunately inconsistently handled
// when it comes to the type pointer, so it's easy to // when it comes to the type pointer, so it's easy to
// produce a lot of false positives here. // produce a lot of false positives here.
@ -1130,7 +1130,7 @@ func getgcmask(ep any) (mask []byte) {
t := e._type t := e._type
var et *_type var et *_type
if t.Kind_&kindMask != kindPtr { if t.Kind_&abi.KindMask != abi.Pointer {
throw("bad argument to getgcmask: expected type to be a pointer to the value type whose mask is being queried") throw("bad argument to getgcmask: expected type to be a pointer to the value type whose mask is being queried")
} }
et = (*ptrtype)(unsafe.Pointer(t)).Elem et = (*ptrtype)(unsafe.Pointer(t)).Elem
@ -1200,7 +1200,7 @@ func getgcmask(ep any) (mask []byte) {
maskFromHeap = maskFromHeap[:len(maskFromHeap)-1] maskFromHeap = maskFromHeap[:len(maskFromHeap)-1]
} }
if et.Kind_&kindGCProg == 0 { if et.Kind_&abi.KindGCProg == 0 {
// Unroll again, but this time from the type information. // Unroll again, but this time from the type information.
maskFromType := make([]byte, (limit-base)/goarch.PtrSize) maskFromType := make([]byte, (limit-base)/goarch.PtrSize)
tp = s.typePointersOfType(et, base) tp = s.typePointersOfType(et, base)
@ -1298,7 +1298,7 @@ func userArenaHeapBitsSetType(typ *_type, ptr unsafe.Pointer, s *mspan) {
p := typ.GCData // start of 1-bit pointer mask (or GC program) p := typ.GCData // start of 1-bit pointer mask (or GC program)
var gcProgBits uintptr var gcProgBits uintptr
if typ.Kind_&kindGCProg != 0 { if typ.Kind_&abi.KindGCProg != 0 {
// Expand gc program, using the object itself for storage. // Expand gc program, using the object itself for storage.
gcProgBits = runGCProg(addb(p, 4), (*byte)(ptr)) gcProgBits = runGCProg(addb(p, 4), (*byte)(ptr))
p = (*byte)(ptr) p = (*byte)(ptr)
@ -1327,7 +1327,7 @@ func userArenaHeapBitsSetType(typ *_type, ptr unsafe.Pointer, s *mspan) {
h = h.pad(s, typ.Size_-typ.PtrBytes) h = h.pad(s, typ.Size_-typ.PtrBytes)
h.flush(s, uintptr(ptr), typ.Size_) h.flush(s, uintptr(ptr), typ.Size_)
if typ.Kind_&kindGCProg != 0 { if typ.Kind_&abi.KindGCProg != 0 {
// Zero out temporary ptrmask buffer inside object. // Zero out temporary ptrmask buffer inside object.
memclrNoHeapPointers(ptr, (gcProgBits+7)/8) memclrNoHeapPointers(ptr, (gcProgBits+7)/8)
} }

View File

@ -552,7 +552,7 @@ func heapBitsSetType(x, size, dataSize uintptr, typ *_type) {
h := writeHeapBitsForAddr(x) h := writeHeapBitsForAddr(x)
// Handle GC program. // Handle GC program.
if typ.Kind_&kindGCProg != 0 { if typ.Kind_&abi.KindGCProg != 0 {
// Expand the gc program into the storage we're going to use for the actual object. // Expand the gc program into the storage we're going to use for the actual object.
obj := (*uint8)(unsafe.Pointer(x)) obj := (*uint8)(unsafe.Pointer(x))
n := runGCProg(addb(typ.GCData, 4), obj) n := runGCProg(addb(typ.GCData, 4), obj)
@ -829,7 +829,7 @@ func userArenaHeapBitsSetType(typ *_type, ptr unsafe.Pointer, s *mspan) {
p := typ.GCData // start of 1-bit pointer mask (or GC program) p := typ.GCData // start of 1-bit pointer mask (or GC program)
var gcProgBits uintptr var gcProgBits uintptr
if typ.Kind_&kindGCProg != 0 { if typ.Kind_&abi.KindGCProg != 0 {
// Expand gc program, using the object itself for storage. // Expand gc program, using the object itself for storage.
gcProgBits = runGCProg(addb(p, 4), (*byte)(ptr)) gcProgBits = runGCProg(addb(p, 4), (*byte)(ptr))
p = (*byte)(ptr) p = (*byte)(ptr)
@ -852,7 +852,7 @@ func userArenaHeapBitsSetType(typ *_type, ptr unsafe.Pointer, s *mspan) {
h = h.pad(typ.Size_ - typ.PtrBytes) h = h.pad(typ.Size_ - typ.PtrBytes)
h.flush(uintptr(ptr), typ.Size_) h.flush(uintptr(ptr), typ.Size_)
if typ.Kind_&kindGCProg != 0 { if typ.Kind_&abi.KindGCProg != 0 {
// Zero out temporary ptrmask buffer inside object. // Zero out temporary ptrmask buffer inside object.
memclrNoHeapPointers(ptr, (gcProgBits+7)/8) memclrNoHeapPointers(ptr, (gcProgBits+7)/8)
} }

View File

@ -235,11 +235,11 @@ func runfinq() {
// confusing the write barrier. // confusing the write barrier.
*(*[2]uintptr)(frame) = [2]uintptr{} *(*[2]uintptr)(frame) = [2]uintptr{}
} }
switch f.fint.Kind_ & kindMask { switch f.fint.Kind_ & abi.KindMask {
case kindPtr: case abi.Pointer:
// direct use of pointer // direct use of pointer
*(*unsafe.Pointer)(r) = f.arg *(*unsafe.Pointer)(r) = f.arg
case kindInterface: case abi.Interface:
ityp := (*interfacetype)(unsafe.Pointer(f.fint)) ityp := (*interfacetype)(unsafe.Pointer(f.fint))
// set up with empty interface // set up with empty interface
(*eface)(r)._type = &f.ot.Type (*eface)(r)._type = &f.ot.Type
@ -418,7 +418,7 @@ func SetFinalizer(obj any, finalizer any) {
if etyp == nil { if etyp == nil {
throw("runtime.SetFinalizer: first argument is nil") throw("runtime.SetFinalizer: first argument is nil")
} }
if etyp.Kind_&kindMask != kindPtr { if etyp.Kind_&abi.KindMask != abi.Pointer {
throw("runtime.SetFinalizer: first argument is " + toRType(etyp).string() + ", not pointer") throw("runtime.SetFinalizer: first argument is " + toRType(etyp).string() + ", not pointer")
} }
ot := (*ptrtype)(unsafe.Pointer(etyp)) ot := (*ptrtype)(unsafe.Pointer(etyp))
@ -464,7 +464,7 @@ func SetFinalizer(obj any, finalizer any) {
return return
} }
if ftyp.Kind_&kindMask != kindFunc { if ftyp.Kind_&abi.KindMask != abi.Func {
throw("runtime.SetFinalizer: second argument is " + toRType(ftyp).string() + ", not a function") throw("runtime.SetFinalizer: second argument is " + toRType(ftyp).string() + ", not a function")
} }
ft := (*functype)(unsafe.Pointer(ftyp)) ft := (*functype)(unsafe.Pointer(ftyp))
@ -479,13 +479,13 @@ func SetFinalizer(obj any, finalizer any) {
case fint == etyp: case fint == etyp:
// ok - same type // ok - same type
goto okarg goto okarg
case fint.Kind_&kindMask == kindPtr: case fint.Kind_&abi.KindMask == abi.Pointer:
if (fint.Uncommon() == nil || etyp.Uncommon() == nil) && (*ptrtype)(unsafe.Pointer(fint)).Elem == ot.Elem { if (fint.Uncommon() == nil || etyp.Uncommon() == nil) && (*ptrtype)(unsafe.Pointer(fint)).Elem == ot.Elem {
// ok - not same type, but both pointers, // ok - not same type, but both pointers,
// one or the other is unnamed, and same element type, so assignable. // one or the other is unnamed, and same element type, so assignable.
goto okarg goto okarg
} }
case fint.Kind_&kindMask == kindInterface: case fint.Kind_&abi.KindMask == abi.Interface:
ityp := (*interfacetype)(unsafe.Pointer(fint)) ityp := (*interfacetype)(unsafe.Pointer(fint))
if len(ityp.Methods) == 0 { if len(ityp.Methods) == 0 {
// ok - satisfies empty interface // ok - satisfies empty interface

View File

@ -5,6 +5,7 @@
package runtime package runtime
import ( import (
"internal/abi"
"internal/runtime/atomic" "internal/runtime/atomic"
"unsafe" "unsafe"
) )
@ -107,7 +108,7 @@ func pinnerGetPtr(i *any) unsafe.Pointer {
if etyp == nil { if etyp == nil {
panic(errorString("runtime.Pinner: argument is nil")) panic(errorString("runtime.Pinner: argument is nil"))
} }
if kind := etyp.Kind_ & kindMask; kind != kindPtr && kind != kindUnsafePointer { if kind := etyp.Kind_ & abi.KindMask; kind != abi.Pointer && kind != abi.UnsafePointer {
panic(errorString("runtime.Pinner: argument is not a pointer: " + toRType(etyp).string())) panic(errorString("runtime.Pinner: argument is not a pointer: " + toRType(etyp).string()))
} }
if inUserArenaChunk(uintptr(e.data)) { if inUserArenaChunk(uintptr(e.data)) {

View File

@ -4,7 +4,10 @@
package runtime package runtime
import "unsafe" import (
"internal/abi"
"unsafe"
)
//go:linkname plugin_lastmoduleinit plugin.lastmoduleinit //go:linkname plugin_lastmoduleinit plugin.lastmoduleinit
func plugin_lastmoduleinit() (path string, syms map[string]any, initTasks []*initTask, errstr string) { func plugin_lastmoduleinit() (path string, syms map[string]any, initTasks []*initTask, errstr string) {
@ -85,7 +88,7 @@ func plugin_lastmoduleinit() (path string, syms map[string]any, initTasks []*ini
(*valp)[0] = unsafe.Pointer(t) (*valp)[0] = unsafe.Pointer(t)
name := symName.Name() name := symName.Name()
if t.Kind_&kindMask == kindFunc { if t.Kind_&abi.KindMask == abi.Func {
name = "." + name name = "." + name
} }
syms[name] = val syms[name] = val

View File

@ -93,8 +93,8 @@ const raceenabled = true
// callerpc is a return PC of the function that calls this function, // callerpc is a return PC of the function that calls this function,
// pc is start PC of the function that calls this function. // pc is start PC of the function that calls this function.
func raceReadObjectPC(t *_type, addr unsafe.Pointer, callerpc, pc uintptr) { func raceReadObjectPC(t *_type, addr unsafe.Pointer, callerpc, pc uintptr) {
kind := t.Kind_ & kindMask kind := t.Kind_ & abi.KindMask
if kind == kindArray || kind == kindStruct { if kind == abi.Array || kind == abi.Struct {
// for composite objects we have to read every address // for composite objects we have to read every address
// because a write might happen to any subobject. // because a write might happen to any subobject.
racereadrangepc(addr, t.Size_, callerpc, pc) racereadrangepc(addr, t.Size_, callerpc, pc)
@ -106,8 +106,8 @@ func raceReadObjectPC(t *_type, addr unsafe.Pointer, callerpc, pc uintptr) {
} }
func raceWriteObjectPC(t *_type, addr unsafe.Pointer, callerpc, pc uintptr) { func raceWriteObjectPC(t *_type, addr unsafe.Pointer, callerpc, pc uintptr) {
kind := t.Kind_ & kindMask kind := t.Kind_ & abi.KindMask
if kind == kindArray || kind == kindStruct { if kind == abi.Array || kind == abi.Struct {
// for composite objects we have to write every address // for composite objects we have to write every address
// because a write might happen to any subobject. // because a write might happen to any subobject.
racewriterangepc(addr, t.Size_, callerpc, pc) racewriterangepc(addr, t.Size_, callerpc, pc)

View File

@ -264,7 +264,7 @@ var methodValueCallFrameObjs [1]stackObjectRecord // initialized in stackobjecti
func stkobjinit() { func stkobjinit() {
var abiRegArgsEface any = abi.RegArgs{} var abiRegArgsEface any = abi.RegArgs{}
abiRegArgsType := efaceOf(&abiRegArgsEface)._type abiRegArgsType := efaceOf(&abiRegArgsEface)._type
if abiRegArgsType.Kind_&kindGCProg != 0 { if abiRegArgsType.Kind_&abi.KindGCProg != 0 {
throw("abiRegArgsType needs GC Prog, update methodValueCallFrameObjs") throw("abiRegArgsType needs GC Prog, update methodValueCallFrameObjs")
} }
// Set methodValueCallFrameObjs[0].gcdataoff so that // Set methodValueCallFrameObjs[0].gcdataoff so that

View File

@ -103,7 +103,7 @@ func (p *abiDesc) assignArg(t *_type) {
// registers and the stack. // registers and the stack.
panic("compileCallback: argument size is larger than uintptr") panic("compileCallback: argument size is larger than uintptr")
} }
if k := t.Kind_ & kindMask; GOARCH != "386" && (k == kindFloat32 || k == kindFloat64) { if k := t.Kind_ & abi.KindMask; GOARCH != "386" && (k == abi.Float32 || k == abi.Float64) {
// In fastcall, floating-point arguments in // In fastcall, floating-point arguments in
// the first four positions are passed in // the first four positions are passed in
// floating-point registers, which we don't // floating-point registers, which we don't
@ -174,21 +174,21 @@ func (p *abiDesc) assignArg(t *_type) {
// //
// Returns whether the assignment succeeded. // Returns whether the assignment succeeded.
func (p *abiDesc) tryRegAssignArg(t *_type, offset uintptr) bool { func (p *abiDesc) tryRegAssignArg(t *_type, offset uintptr) bool {
switch k := t.Kind_ & kindMask; k { switch k := t.Kind_ & abi.KindMask; k {
case kindBool, kindInt, kindInt8, kindInt16, kindInt32, kindUint, kindUint8, kindUint16, kindUint32, kindUintptr, kindPtr, kindUnsafePointer: case abi.Bool, abi.Int, abi.Int8, abi.Int16, abi.Int32, abi.Uint, abi.Uint8, abi.Uint16, abi.Uint32, abi.Uintptr, abi.Pointer, abi.UnsafePointer:
// Assign a register for all these types. // Assign a register for all these types.
return p.assignReg(t.Size_, offset) return p.assignReg(t.Size_, offset)
case kindInt64, kindUint64: case abi.Int64, abi.Uint64:
// Only register-assign if the registers are big enough. // Only register-assign if the registers are big enough.
if goarch.PtrSize == 8 { if goarch.PtrSize == 8 {
return p.assignReg(t.Size_, offset) return p.assignReg(t.Size_, offset)
} }
case kindArray: case abi.Array:
at := (*arraytype)(unsafe.Pointer(t)) at := (*arraytype)(unsafe.Pointer(t))
if at.Len == 1 { if at.Len == 1 {
return p.tryRegAssignArg(at.Elem, offset) // TODO fix when runtime is fully commoned up w/ abi.Type return p.tryRegAssignArg(at.Elem, offset) // TODO fix when runtime is fully commoned up w/ abi.Type
} }
case kindStruct: case abi.Struct:
st := (*structtype)(unsafe.Pointer(t)) st := (*structtype)(unsafe.Pointer(t))
for i := range st.Fields { for i := range st.Fields {
f := &st.Fields[i] f := &st.Fields[i]
@ -269,7 +269,7 @@ func compileCallback(fn eface, cdecl bool) (code uintptr) {
cdecl = false cdecl = false
} }
if fn._type == nil || (fn._type.Kind_&kindMask) != kindFunc { if fn._type == nil || (fn._type.Kind_&abi.KindMask) != abi.Func {
panic("compileCallback: expected function with one uintptr-sized result") panic("compileCallback: expected function with one uintptr-sized result")
} }
ft := (*functype)(unsafe.Pointer(fn._type)) ft := (*functype)(unsafe.Pointer(fn._type))
@ -290,7 +290,7 @@ func compileCallback(fn eface, cdecl bool) (code uintptr) {
if ft.OutSlice()[0].Size_ != goarch.PtrSize { if ft.OutSlice()[0].Size_ != goarch.PtrSize {
panic("compileCallback: expected function with one uintptr-sized result") panic("compileCallback: expected function with one uintptr-sized result")
} }
if k := ft.OutSlice()[0].Kind_ & kindMask; k == kindFloat32 || k == kindFloat64 { if k := ft.OutSlice()[0].Kind_ & abi.KindMask; k == abi.Float32 || k == abi.Float64 {
// In cdecl and stdcall, float results are returned in // In cdecl and stdcall, float results are returned in
// ST(0). In fastcall, they're returned in XMM0. // ST(0). In fastcall, they're returned in XMM0.
// Either way, it's not AX. // Either way, it's not AX.

View File

@ -61,11 +61,11 @@ func (t rtype) pkgpath() string {
if u := t.uncommon(); u != nil { if u := t.uncommon(); u != nil {
return t.nameOff(u.PkgPath).Name() return t.nameOff(u.PkgPath).Name()
} }
switch t.Kind_ & kindMask { switch t.Kind_ & abi.KindMask {
case kindStruct: case abi.Struct:
st := (*structtype)(unsafe.Pointer(t.Type)) st := (*structtype)(unsafe.Pointer(t.Type))
return st.PkgPath.Name() return st.PkgPath.Name()
case kindInterface: case abi.Interface:
it := (*interfacetype)(unsafe.Pointer(t.Type)) it := (*interfacetype)(unsafe.Pointer(t.Type))
return it.PkgPath.Name() return it.PkgPath.Name()
} }
@ -338,8 +338,8 @@ func typesEqual(t, v *_type, seen map[_typePair]struct{}) bool {
if t == v { if t == v {
return true return true
} }
kind := t.Kind_ & kindMask kind := t.Kind_ & abi.KindMask
if kind != v.Kind_&kindMask { if kind != v.Kind_&abi.KindMask {
return false return false
} }
rt, rv := toRType(t), toRType(v) rt, rv := toRType(t), toRType(v)
@ -358,21 +358,21 @@ func typesEqual(t, v *_type, seen map[_typePair]struct{}) bool {
return false return false
} }
} }
if kindBool <= kind && kind <= kindComplex128 { if abi.Bool <= kind && kind <= abi.Complex128 {
return true return true
} }
switch kind { switch kind {
case kindString, kindUnsafePointer: case abi.String, abi.UnsafePointer:
return true return true
case kindArray: case abi.Array:
at := (*arraytype)(unsafe.Pointer(t)) at := (*arraytype)(unsafe.Pointer(t))
av := (*arraytype)(unsafe.Pointer(v)) av := (*arraytype)(unsafe.Pointer(v))
return typesEqual(at.Elem, av.Elem, seen) && at.Len == av.Len return typesEqual(at.Elem, av.Elem, seen) && at.Len == av.Len
case kindChan: case abi.Chan:
ct := (*chantype)(unsafe.Pointer(t)) ct := (*chantype)(unsafe.Pointer(t))
cv := (*chantype)(unsafe.Pointer(v)) cv := (*chantype)(unsafe.Pointer(v))
return ct.Dir == cv.Dir && typesEqual(ct.Elem, cv.Elem, seen) return ct.Dir == cv.Dir && typesEqual(ct.Elem, cv.Elem, seen)
case kindFunc: case abi.Func:
ft := (*functype)(unsafe.Pointer(t)) ft := (*functype)(unsafe.Pointer(t))
fv := (*functype)(unsafe.Pointer(v)) fv := (*functype)(unsafe.Pointer(v))
if ft.OutCount != fv.OutCount || ft.InCount != fv.InCount { if ft.OutCount != fv.OutCount || ft.InCount != fv.InCount {
@ -391,7 +391,7 @@ func typesEqual(t, v *_type, seen map[_typePair]struct{}) bool {
} }
} }
return true return true
case kindInterface: case abi.Interface:
it := (*interfacetype)(unsafe.Pointer(t)) it := (*interfacetype)(unsafe.Pointer(t))
iv := (*interfacetype)(unsafe.Pointer(v)) iv := (*interfacetype)(unsafe.Pointer(v))
if it.PkgPath.Name() != iv.PkgPath.Name() { if it.PkgPath.Name() != iv.PkgPath.Name() {
@ -420,19 +420,19 @@ func typesEqual(t, v *_type, seen map[_typePair]struct{}) bool {
} }
} }
return true return true
case kindMap: case abi.Map:
mt := (*maptype)(unsafe.Pointer(t)) mt := (*maptype)(unsafe.Pointer(t))
mv := (*maptype)(unsafe.Pointer(v)) mv := (*maptype)(unsafe.Pointer(v))
return typesEqual(mt.Key, mv.Key, seen) && typesEqual(mt.Elem, mv.Elem, seen) return typesEqual(mt.Key, mv.Key, seen) && typesEqual(mt.Elem, mv.Elem, seen)
case kindPtr: case abi.Pointer:
pt := (*ptrtype)(unsafe.Pointer(t)) pt := (*ptrtype)(unsafe.Pointer(t))
pv := (*ptrtype)(unsafe.Pointer(v)) pv := (*ptrtype)(unsafe.Pointer(v))
return typesEqual(pt.Elem, pv.Elem, seen) return typesEqual(pt.Elem, pv.Elem, seen)
case kindSlice: case abi.Slice:
st := (*slicetype)(unsafe.Pointer(t)) st := (*slicetype)(unsafe.Pointer(t))
sv := (*slicetype)(unsafe.Pointer(v)) sv := (*slicetype)(unsafe.Pointer(v))
return typesEqual(st.Elem, sv.Elem, seen) return typesEqual(st.Elem, sv.Elem, seen)
case kindStruct: case abi.Struct:
st := (*structtype)(unsafe.Pointer(t)) st := (*structtype)(unsafe.Pointer(t))
sv := (*structtype)(unsafe.Pointer(v)) sv := (*structtype)(unsafe.Pointer(v))
if len(st.Fields) != len(sv.Fields) { if len(st.Fields) != len(sv.Fields) {

View File

@ -4,40 +4,9 @@
package runtime package runtime
const ( import "internal/abi"
kindBool = 1 + iota
kindInt
kindInt8
kindInt16
kindInt32
kindInt64
kindUint
kindUint8
kindUint16
kindUint32
kindUint64
kindUintptr
kindFloat32
kindFloat64
kindComplex64
kindComplex128
kindArray
kindChan
kindFunc
kindInterface
kindMap
kindPtr
kindSlice
kindString
kindStruct
kindUnsafePointer
kindDirectIface = 1 << 5
kindGCProg = 1 << 6
kindMask = (1 << 5) - 1
)
// isDirectIface reports whether t is stored directly in an interface value. // isDirectIface reports whether t is stored directly in an interface value.
func isDirectIface(t *_type) bool { func isDirectIface(t *_type) bool {
return t.Kind_&kindDirectIface != 0 return t.Kind_&abi.KindDirectIface != 0
} }