]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: revert "move zeroVal to internal/abi"
authorRuss Cox <rsc@golang.org>
Wed, 22 May 2024 03:04:21 +0000 (23:04 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 22 May 2024 21:17:38 +0000 (21:17 +0000)
This reverts CL 581395, commit 2f5b420fb5984842afab37a9c2e66e6599107483.
It breaks a linkname from github.com/ugorji/go/codec.
For #67401.

A followup CL will document this dependence.

Change-Id: I66d6c39c03e769ab829ca4c3f4f61277b93380d3
Reviewed-on: https://go-review.googlesource.com/c/go/+/587216
TryBot-Bypass: Russ Cox <rsc@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/internal/abi/runtime.go
src/reflect/value.go
src/runtime/iface.go
src/runtime/map.go
src/runtime/map_fast32.go
src/runtime/map_fast64.go
src/runtime/map_faststr.go
src/runtime/runtime.go

index 2a3181a48d343c0672be987e2c1c64f8c58b3bc9..9b91cdf5ef60c0136e068a1d3c3f81c271fd6e7c 100644 (file)
@@ -4,8 +4,5 @@
 
 package abi
 
-// ZeroValSize is the size in bytes of [ZeroVal].
+// ZeroValSize is the size in bytes of runtime.zeroVal.
 const ZeroValSize = 1024
-
-// ZeroVal is a region containing all zero bytes.
-var ZeroVal [ZeroValSize]byte
index c93afb99ebee07d0b86c71bcc204bdb23d5981e1..56d8ba708c2c82d1f105c338bc968c04b8274415 100644 (file)
@@ -1591,7 +1591,7 @@ func (v Value) IsZero() bool {
                        // v.ptr doesn't escape, as Equal functions are compiler generated
                        // and never escape. The escape analysis doesn't know, as it is a
                        // function pointer call.
-                       return typ.Equal(abi.NoEscape(v.ptr), unsafe.Pointer(&abi.ZeroVal[0]))
+                       return typ.Equal(abi.NoEscape(v.ptr), unsafe.Pointer(&zeroVal[0]))
                }
                if typ.TFlag&abi.TFlagRegularMemory != 0 {
                        // For some types where the zero value is a value where all bits of this type are 0
@@ -1617,7 +1617,7 @@ func (v Value) IsZero() bool {
                // If the type is comparable, then compare directly with zero.
                if typ.Equal != nil && typ.Size() <= abi.ZeroValSize {
                        // See noescape justification above.
-                       return typ.Equal(abi.NoEscape(v.ptr), unsafe.Pointer(&abi.ZeroVal[0]))
+                       return typ.Equal(abi.NoEscape(v.ptr), unsafe.Pointer(&zeroVal[0]))
                }
                if typ.TFlag&abi.TFlagRegularMemory != 0 {
                        // For some types where the zero value is a value where all bits of this type are 0
@@ -2312,7 +2312,7 @@ func (v Value) Set(x Value) {
        }
        x = x.assignTo("reflect.Set", v.typ(), target)
        if x.flag&flagIndir != 0 {
-               if x.ptr == unsafe.Pointer(&abi.ZeroVal[0]) {
+               if x.ptr == unsafe.Pointer(&zeroVal[0]) {
                        typedmemclr(v.typ(), v.ptr)
                } else {
                        typedmemmove(v.typ(), v.ptr, x.ptr)
@@ -3280,7 +3280,7 @@ func Zero(typ Type) Value {
        if t.IfaceIndir() {
                var p unsafe.Pointer
                if t.Size() <= abi.ZeroValSize {
-                       p = unsafe.Pointer(&abi.ZeroVal[0])
+                       p = unsafe.Pointer(&zeroVal[0])
                } else {
                        p = unsafe_New(t)
                }
@@ -3289,6 +3289,9 @@ func Zero(typ Type) Value {
        return Value{t, nil, fl}
 }
 
+//go:linkname zeroVal runtime.zeroVal
+var zeroVal [abi.ZeroValSize]byte
+
 // New returns a Value representing a pointer to a new zero value
 // for the specified type. That is, the returned Value's Type is [PointerTo](typ).
 func New(typ Type) Value {
index f9c4c8e42d6963475199cf93664e850dfd26128c..67e703869121bc08033da653ecf2b7e425eef1a8 100644 (file)
@@ -391,7 +391,7 @@ func convT64(val uint64) (x unsafe.Pointer) {
 
 func convTstring(val string) (x unsafe.Pointer) {
        if val == "" {
-               x = unsafe.Pointer(&abi.ZeroVal[0])
+               x = unsafe.Pointer(&zeroVal[0])
        } else {
                x = mallocgc(unsafe.Sizeof(val), stringType, true)
                *(*string)(x) = val
@@ -402,7 +402,7 @@ func convTstring(val string) (x unsafe.Pointer) {
 func convTslice(val []byte) (x unsafe.Pointer) {
        // Note: this must work for any element type, not just byte.
        if (*slice)(unsafe.Pointer(&val)).array == nil {
-               x = unsafe.Pointer(&abi.ZeroVal[0])
+               x = unsafe.Pointer(&zeroVal[0])
        } else {
                x = mallocgc(unsafe.Sizeof(val), sliceType, true)
                *(*[]byte)(x) = val
index ebfe3b6707d69b23ef55e432a18a3bb619b9cd0c..7be27fd56942ea011c3659cd79c69abb6438ba8c 100644 (file)
@@ -402,7 +402,7 @@ func mapaccess1(t *maptype, h *hmap, key unsafe.Pointer) unsafe.Pointer {
                if err := mapKeyError(t, key); err != nil {
                        panic(err) // see issue 23734
                }
-               return unsafe.Pointer(&abi.ZeroVal[0])
+               return unsafe.Pointer(&zeroVal[0])
        }
        if h.flags&hashWriting != 0 {
                fatal("concurrent map read and map write")
@@ -443,7 +443,7 @@ bucketloop:
                        }
                }
        }
-       return unsafe.Pointer(&abi.ZeroVal[0])
+       return unsafe.Pointer(&zeroVal[0])
 }
 
 func mapaccess2(t *maptype, h *hmap, key unsafe.Pointer) (unsafe.Pointer, bool) {
@@ -463,7 +463,7 @@ func mapaccess2(t *maptype, h *hmap, key unsafe.Pointer) (unsafe.Pointer, bool)
                if err := mapKeyError(t, key); err != nil {
                        panic(err) // see issue 23734
                }
-               return unsafe.Pointer(&abi.ZeroVal[0]), false
+               return unsafe.Pointer(&zeroVal[0]), false
        }
        if h.flags&hashWriting != 0 {
                fatal("concurrent map read and map write")
@@ -504,7 +504,7 @@ bucketloop:
                        }
                }
        }
-       return unsafe.Pointer(&abi.ZeroVal[0]), false
+       return unsafe.Pointer(&zeroVal[0]), false
 }
 
 // returns both key and elem. Used by map iterator.
@@ -553,7 +553,7 @@ bucketloop:
 
 func mapaccess1_fat(t *maptype, h *hmap, key, zero unsafe.Pointer) unsafe.Pointer {
        e := mapaccess1(t, h, key)
-       if e == unsafe.Pointer(&abi.ZeroVal[0]) {
+       if e == unsafe.Pointer(&zeroVal[0]) {
                return zero
        }
        return e
@@ -561,7 +561,7 @@ func mapaccess1_fat(t *maptype, h *hmap, key, zero unsafe.Pointer) unsafe.Pointe
 
 func mapaccess2_fat(t *maptype, h *hmap, key, zero unsafe.Pointer) (unsafe.Pointer, bool) {
        e := mapaccess1(t, h, key)
-       if e == unsafe.Pointer(&abi.ZeroVal[0]) {
+       if e == unsafe.Pointer(&zeroVal[0]) {
                return zero, false
        }
        return e, true
index 06dcbcabc461d645f52e1eac78a117f9b612e3dd..7e52240e77988acb26b17ad6e028d58b2aa862c2 100644 (file)
@@ -16,7 +16,7 @@ func mapaccess1_fast32(t *maptype, h *hmap, key uint32) unsafe.Pointer {
                racereadpc(unsafe.Pointer(h), callerpc, abi.FuncPCABIInternal(mapaccess1_fast32))
        }
        if h == nil || h.count == 0 {
-               return unsafe.Pointer(&abi.ZeroVal[0])
+               return unsafe.Pointer(&zeroVal[0])
        }
        if h.flags&hashWriting != 0 {
                fatal("concurrent map read and map write")
@@ -47,7 +47,7 @@ func mapaccess1_fast32(t *maptype, h *hmap, key uint32) unsafe.Pointer {
                        }
                }
        }
-       return unsafe.Pointer(&abi.ZeroVal[0])
+       return unsafe.Pointer(&zeroVal[0])
 }
 
 func mapaccess2_fast32(t *maptype, h *hmap, key uint32) (unsafe.Pointer, bool) {
@@ -56,7 +56,7 @@ func mapaccess2_fast32(t *maptype, h *hmap, key uint32) (unsafe.Pointer, bool) {
                racereadpc(unsafe.Pointer(h), callerpc, abi.FuncPCABIInternal(mapaccess2_fast32))
        }
        if h == nil || h.count == 0 {
-               return unsafe.Pointer(&abi.ZeroVal[0]), false
+               return unsafe.Pointer(&zeroVal[0]), false
        }
        if h.flags&hashWriting != 0 {
                fatal("concurrent map read and map write")
@@ -87,7 +87,7 @@ func mapaccess2_fast32(t *maptype, h *hmap, key uint32) (unsafe.Pointer, bool) {
                        }
                }
        }
-       return unsafe.Pointer(&abi.ZeroVal[0]), false
+       return unsafe.Pointer(&zeroVal[0]), false
 }
 
 func mapassign_fast32(t *maptype, h *hmap, key uint32) unsafe.Pointer {
index c8b34dd41bc219de6e2f9445a90eae4ce46fbc19..2c365183cb74523cf881c96c90722495ff29acf5 100644 (file)
@@ -16,7 +16,7 @@ func mapaccess1_fast64(t *maptype, h *hmap, key uint64) unsafe.Pointer {
                racereadpc(unsafe.Pointer(h), callerpc, abi.FuncPCABIInternal(mapaccess1_fast64))
        }
        if h == nil || h.count == 0 {
-               return unsafe.Pointer(&abi.ZeroVal[0])
+               return unsafe.Pointer(&zeroVal[0])
        }
        if h.flags&hashWriting != 0 {
                fatal("concurrent map read and map write")
@@ -47,7 +47,7 @@ func mapaccess1_fast64(t *maptype, h *hmap, key uint64) unsafe.Pointer {
                        }
                }
        }
-       return unsafe.Pointer(&abi.ZeroVal[0])
+       return unsafe.Pointer(&zeroVal[0])
 }
 
 func mapaccess2_fast64(t *maptype, h *hmap, key uint64) (unsafe.Pointer, bool) {
@@ -56,7 +56,7 @@ func mapaccess2_fast64(t *maptype, h *hmap, key uint64) (unsafe.Pointer, bool) {
                racereadpc(unsafe.Pointer(h), callerpc, abi.FuncPCABIInternal(mapaccess2_fast64))
        }
        if h == nil || h.count == 0 {
-               return unsafe.Pointer(&abi.ZeroVal[0]), false
+               return unsafe.Pointer(&zeroVal[0]), false
        }
        if h.flags&hashWriting != 0 {
                fatal("concurrent map read and map write")
@@ -87,7 +87,7 @@ func mapaccess2_fast64(t *maptype, h *hmap, key uint64) (unsafe.Pointer, bool) {
                        }
                }
        }
-       return unsafe.Pointer(&abi.ZeroVal[0]), false
+       return unsafe.Pointer(&zeroVal[0]), false
 }
 
 func mapassign_fast64(t *maptype, h *hmap, key uint64) unsafe.Pointer {
index 38841aee4b5af9f01569cf95da2021fc365c6f8a..d989190f710b5f2c3d1d5364dd8da819c342f2e1 100644 (file)
@@ -16,7 +16,7 @@ func mapaccess1_faststr(t *maptype, h *hmap, ky string) unsafe.Pointer {
                racereadpc(unsafe.Pointer(h), callerpc, abi.FuncPCABIInternal(mapaccess1_faststr))
        }
        if h == nil || h.count == 0 {
-               return unsafe.Pointer(&abi.ZeroVal[0])
+               return unsafe.Pointer(&zeroVal[0])
        }
        if h.flags&hashWriting != 0 {
                fatal("concurrent map read and map write")
@@ -39,7 +39,7 @@ func mapaccess1_faststr(t *maptype, h *hmap, ky string) unsafe.Pointer {
                                        return add(unsafe.Pointer(b), dataOffset+abi.MapBucketCount*2*goarch.PtrSize+i*uintptr(t.ValueSize))
                                }
                        }
-                       return unsafe.Pointer(&abi.ZeroVal[0])
+                       return unsafe.Pointer(&zeroVal[0])
                }
                // long key, try not to do more comparisons than necessary
                keymaybe := uintptr(abi.MapBucketCount)
@@ -74,7 +74,7 @@ func mapaccess1_faststr(t *maptype, h *hmap, ky string) unsafe.Pointer {
                                return add(unsafe.Pointer(b), dataOffset+abi.MapBucketCount*2*goarch.PtrSize+keymaybe*uintptr(t.ValueSize))
                        }
                }
-               return unsafe.Pointer(&abi.ZeroVal[0])
+               return unsafe.Pointer(&zeroVal[0])
        }
 dohash:
        hash := t.Hasher(noescape(unsafe.Pointer(&ky)), uintptr(h.hash0))
@@ -102,7 +102,7 @@ dohash:
                        }
                }
        }
-       return unsafe.Pointer(&abi.ZeroVal[0])
+       return unsafe.Pointer(&zeroVal[0])
 }
 
 func mapaccess2_faststr(t *maptype, h *hmap, ky string) (unsafe.Pointer, bool) {
@@ -111,7 +111,7 @@ func mapaccess2_faststr(t *maptype, h *hmap, ky string) (unsafe.Pointer, bool) {
                racereadpc(unsafe.Pointer(h), callerpc, abi.FuncPCABIInternal(mapaccess2_faststr))
        }
        if h == nil || h.count == 0 {
-               return unsafe.Pointer(&abi.ZeroVal[0]), false
+               return unsafe.Pointer(&zeroVal[0]), false
        }
        if h.flags&hashWriting != 0 {
                fatal("concurrent map read and map write")
@@ -134,7 +134,7 @@ func mapaccess2_faststr(t *maptype, h *hmap, ky string) (unsafe.Pointer, bool) {
                                        return add(unsafe.Pointer(b), dataOffset+abi.MapBucketCount*2*goarch.PtrSize+i*uintptr(t.ValueSize)), true
                                }
                        }
-                       return unsafe.Pointer(&abi.ZeroVal[0]), false
+                       return unsafe.Pointer(&zeroVal[0]), false
                }
                // long key, try not to do more comparisons than necessary
                keymaybe := uintptr(abi.MapBucketCount)
@@ -169,7 +169,7 @@ func mapaccess2_faststr(t *maptype, h *hmap, ky string) (unsafe.Pointer, bool) {
                                return add(unsafe.Pointer(b), dataOffset+abi.MapBucketCount*2*goarch.PtrSize+keymaybe*uintptr(t.ValueSize)), true
                        }
                }
-               return unsafe.Pointer(&abi.ZeroVal[0]), false
+               return unsafe.Pointer(&zeroVal[0]), false
        }
 dohash:
        hash := t.Hasher(noescape(unsafe.Pointer(&ky)), uintptr(h.hash0))
@@ -197,7 +197,7 @@ dohash:
                        }
                }
        }
-       return unsafe.Pointer(&abi.ZeroVal[0]), false
+       return unsafe.Pointer(&zeroVal[0]), false
 }
 
 func mapassign_faststr(t *maptype, h *hmap, s string) unsafe.Pointer {
index f854fd5e417bf0a2607faffd6b53fdf7ba84a526..6cf903d2c1aae50763acb38b22d3b3a896be546c 100644 (file)
@@ -5,6 +5,7 @@
 package runtime
 
 import (
+       "internal/abi"
        "internal/runtime/atomic"
        "unsafe"
 )
@@ -301,3 +302,8 @@ var auxv []uintptr
 //
 //go:linkname getAuxv
 func getAuxv() []uintptr { return auxv }
+
+// zeroVal is used by reflect via linkname.
+//
+//go:linkname zeroVal
+var zeroVal [abi.ZeroValSize]byte