aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2025-01-07 11:28:44 -0500
committerGopher Robot <gobot@golang.org>2025-02-13 12:34:30 -0800
commiteab8e987c067ca91ad4ed79b384d8a33494bbf39 (patch)
tree4d980ee4060c22c4e91789f455a2fe9d7d1ef6b4 /src/cmd/internal
parenta7e331e67105f1a8cc0236b7f3b1e6a3570dda27 (diff)
downloadgo-eab8e987c067ca91ad4ed79b384d8a33494bbf39.tar.xz
cmd: use cmd/internal/hash.New32 and Sum32 only
Do not use New16, New20, Sum16, Sum20 anymore. As of CL 641096, these are just wrappers around New32 and Sum32. Change call sites to use them directly. Change-Id: Icea91a77449f6839b903894997057ba404bd04e0 Reviewed-on: https://go-review.googlesource.com/c/go/+/641076 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/internal')
-rw-r--r--src/cmd/internal/hash/hash.go59
-rw-r--r--src/cmd/internal/obj/objfile.go2
-rw-r--r--src/cmd/internal/obj/sym.go2
3 files changed, 10 insertions, 53 deletions
diff --git a/src/cmd/internal/hash/hash.go b/src/cmd/internal/hash/hash.go
index a37368f50e..cdb24a2645 100644
--- a/src/cmd/internal/hash/hash.go
+++ b/src/cmd/internal/hash/hash.go
@@ -5,69 +5,26 @@
// Package hash implements hash functions used in the compiler toolchain.
package hash
-// TODO(rsc): Delete the 16 and 20 forms and use 32 at all call sites.
-
import (
"crypto/sha256"
"hash"
)
-const (
- // Size32 is the size of the 32-byte hash checksum.
- Size32 = 32
- // Size20 is the size of the 20-byte hash checksum.
- Size20 = 20
- // Size16 is the size of the 16-byte hash checksum.
- Size16 = 16
-)
-
-type shortHash struct {
- hash.Hash
- n int
-}
+// Size32 is the size of the 32-byte hash functions [New32] and [Sum32].
+const Size32 = 32
-func (h *shortHash) Sum(b []byte) []byte {
- old := b
- sum := h.Hash.Sum(b)
- return sum[:len(old)+h.n]
-}
-
-// New32 returns a new [hash.Hash] computing the 32 bytes hash checksum.
+// New32 returns a new [hash.Hash] computing the 32-byte hash checksum.
+// Note that New32 and [Sum32] compute different hashes.
func New32() hash.Hash {
h := sha256.New()
_, _ = h.Write([]byte{1}) // make this hash different from sha256
return h
}
-// New20 returns a new [hash.Hash] computing the 20 bytes hash checksum.
-func New20() hash.Hash {
- return &shortHash{New32(), 20}
-}
-
-// New16 returns a new [hash.Hash] computing the 16 bytes hash checksum.
-func New16() hash.Hash {
- return &shortHash{New32(), 16}
-}
-
-// Sum32 returns the 32 bytes checksum of the data.
-func Sum32(data []byte) [Size32]byte {
+// Sum32 returns a 32-byte checksum of the data.
+// Note that Sum32 and [New32] compute different hashes.
+func Sum32(data []byte) [32]byte {
sum := sha256.Sum256(data)
- sum[0] ^= 1 // make this hash different from sha256
+ sum[0] ^= 0xff // make this hash different from sha256
return sum
}
-
-// Sum20 returns the 20 bytes checksum of the data.
-func Sum20(data []byte) [Size20]byte {
- sum := Sum32(data)
- var short [Size20]byte
- copy(short[:], sum[4:])
- return short
-}
-
-// Sum16 returns the 16 bytes checksum of the data.
-func Sum16(data []byte) [Size16]byte {
- sum := Sum32(data)
- var short [Size16]byte
- copy(short[:], sum[8:])
- return short
-}
diff --git a/src/cmd/internal/obj/objfile.go b/src/cmd/internal/obj/objfile.go
index bc22765abc..3299fbf4e6 100644
--- a/src/cmd/internal/obj/objfile.go
+++ b/src/cmd/internal/obj/objfile.go
@@ -494,7 +494,7 @@ func contentHash64(s *LSym) goobj.Hash64Type {
// For now, we assume there is no circular dependencies among
// hashed symbols.
func (w *writer) contentHash(s *LSym) goobj.HashType {
- h := hash.New20()
+ h := hash.New32()
var tmp [14]byte
// Include the size of the symbol in the hash.
diff --git a/src/cmd/internal/obj/sym.go b/src/cmd/internal/obj/sym.go
index 8872579050..08c50ec72b 100644
--- a/src/cmd/internal/obj/sym.go
+++ b/src/cmd/internal/obj/sym.go
@@ -216,7 +216,7 @@ func (ctxt *Link) Int128Sym(hi, lo int64) *LSym {
// GCLocalsSym generates a content-addressable sym containing data.
func (ctxt *Link) GCLocalsSym(data []byte) *LSym {
- sum := hash.Sum16(data)
+ sum := hash.Sum32(data)
str := base64.StdEncoding.EncodeToString(sum[:16])
return ctxt.LookupInit(fmt.Sprintf("gclocals·%s", str), func(lsym *LSym) {
lsym.P = data