aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/staticdata
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2024-09-04 18:30:35 +0700
committerGopher Robot <gobot@golang.org>2024-09-04 18:23:49 +0000
commit4fd73e5d4ca8c87efa127ee7a3290b1d0fdae313 (patch)
tree454d18c4074ce87ae00638fb9e61f7058eb13cf8 /src/cmd/compile/internal/staticdata
parentad8b5f7fe91bdb0afc9dad72a0ba3ac46ce0167c (diff)
downloadgo-4fd73e5d4ca8c87efa127ee7a3290b1d0fdae313.tar.xz
cmd: do not use notsha256
CL 402595 used notsha256 to prevent the compiler from depending on cgo-based implementations of sha1 and sha256. However, since CL 454836, cmd is built with CGO_ENABLED=0, which will disable boringcrypto. Thus all usages of notsha256 is not necessary anymore. Updates #51940 Updates #64751 Change-Id: I503090f7a2efb5723e8a79523b143dc7cdb4edd0 Reviewed-on: https://go-review.googlesource.com/c/go/+/610596 Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/staticdata')
-rw-r--r--src/cmd/compile/internal/staticdata/data.go22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/cmd/compile/internal/staticdata/data.go b/src/cmd/compile/internal/staticdata/data.go
index 78c332eeb8..b6ca615c6e 100644
--- a/src/cmd/compile/internal/staticdata/data.go
+++ b/src/cmd/compile/internal/staticdata/data.go
@@ -18,7 +18,7 @@ import (
"cmd/compile/internal/ir"
"cmd/compile/internal/objw"
"cmd/compile/internal/types"
- "cmd/internal/notsha256"
+ "cmd/internal/hash"
"cmd/internal/obj"
"cmd/internal/objabi"
"cmd/internal/src"
@@ -78,7 +78,7 @@ func StringSym(pos src.XPos, s string) (data *obj.LSym) {
// Indulge in some paranoia by writing the length of s, too,
// as protection against length extension attacks.
// Same pattern is known to fileStringSym below.
- h := notsha256.New()
+ h := hash.New32()
io.WriteString(h, s)
symname = fmt.Sprintf(stringSymPattern, len(s), shortHashString(h.Sum(nil)))
} else {
@@ -115,9 +115,9 @@ const maxFileSize = int64(2e9)
// or other file with the same content and is placed in a read-only section.
// If readonly is false, the symbol is a read-write copy separate from any other,
// for use as the backing store of a []byte.
-// The content hash of file is copied into hash. (If hash is nil, nothing is copied.)
+// The content hash of file is copied into hashBytes. (If hash is nil, nothing is copied.)
// The returned symbol contains the data itself, not a string header.
-func fileStringSym(pos src.XPos, file string, readonly bool, hash []byte) (*obj.LSym, int64, error) {
+func fileStringSym(pos src.XPos, file string, readonly bool, hashBytes []byte) (*obj.LSym, int64, error) {
f, err := os.Open(file)
if err != nil {
return nil, 0, err
@@ -145,9 +145,9 @@ func fileStringSym(pos src.XPos, file string, readonly bool, hash []byte) (*obj.
} else {
sym = slicedata(pos, string(data))
}
- if len(hash) > 0 {
- sum := notsha256.Sum256(data)
- copy(hash, sum[:])
+ if len(hashBytes) > 0 {
+ sum := hash.Sum32(data)
+ copy(hashBytes, sum[:])
}
return sym, size, nil
}
@@ -160,10 +160,10 @@ func fileStringSym(pos src.XPos, file string, readonly bool, hash []byte) (*obj.
}
// File is too big to read and keep in memory.
- // Compute hash if needed for read-only content hashing or if the caller wants it.
+ // Compute hashBytes if needed for read-only content hashing or if the caller wants it.
var sum []byte
- if readonly || len(hash) > 0 {
- h := notsha256.New()
+ if readonly || len(hashBytes) > 0 {
+ h := hash.New32()
n, err := io.Copy(h, f)
if err != nil {
return nil, 0, err
@@ -172,7 +172,7 @@ func fileStringSym(pos src.XPos, file string, readonly bool, hash []byte) (*obj.
return nil, 0, fmt.Errorf("file changed between reads")
}
sum = h.Sum(nil)
- copy(hash, sum)
+ copy(hashBytes, sum)
}
var symdata *obj.LSym