aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile
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
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')
-rw-r--r--src/cmd/compile/internal/liveness/plive.go4
-rw-r--r--src/cmd/compile/internal/noder/reader.go4
-rw-r--r--src/cmd/compile/internal/ssa/print.go6
-rw-r--r--src/cmd/compile/internal/staticdata/data.go22
-rw-r--r--src/cmd/compile/internal/types/fmt.go6
5 files changed, 21 insertions, 21 deletions
diff --git a/src/cmd/compile/internal/liveness/plive.go b/src/cmd/compile/internal/liveness/plive.go
index a38ea776f9..09af864b69 100644
--- a/src/cmd/compile/internal/liveness/plive.go
+++ b/src/cmd/compile/internal/liveness/plive.go
@@ -29,7 +29,7 @@ import (
"cmd/compile/internal/ssa"
"cmd/compile/internal/typebits"
"cmd/compile/internal/types"
- "cmd/internal/notsha256"
+ "cmd/internal/hash"
"cmd/internal/obj"
"cmd/internal/src"
@@ -979,7 +979,7 @@ func (lv *liveness) enableClobber() {
// Clobber only functions where the hash of the function name matches a pattern.
// Useful for binary searching for a miscompiled function.
hstr := ""
- for _, b := range notsha256.Sum256([]byte(lv.f.Name)) {
+ for _, b := range hash.Sum32([]byte(lv.f.Name)) {
hstr += fmt.Sprintf("%08b", b)
}
if !strings.HasSuffix(hstr, h) {
diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go
index 98ae60d51e..1dae4da167 100644
--- a/src/cmd/compile/internal/noder/reader.go
+++ b/src/cmd/compile/internal/noder/reader.go
@@ -23,7 +23,7 @@ import (
"cmd/compile/internal/staticinit"
"cmd/compile/internal/typecheck"
"cmd/compile/internal/types"
- "cmd/internal/notsha256"
+ "cmd/internal/hash"
"cmd/internal/obj"
"cmd/internal/objabi"
"cmd/internal/src"
@@ -940,7 +940,7 @@ func shapify(targ *types.Type, basic bool) *types.Type {
uls := under.LinkString()
if base.Debug.MaxShapeLen != 0 &&
len(uls) > base.Debug.MaxShapeLen {
- h := notsha256.Sum256([]byte(uls))
+ h := hash.Sum32([]byte(uls))
uls = hex.EncodeToString(h[:])
}
diff --git a/src/cmd/compile/internal/ssa/print.go b/src/cmd/compile/internal/ssa/print.go
index 0d3b5d9e34..ed7f154249 100644
--- a/src/cmd/compile/internal/ssa/print.go
+++ b/src/cmd/compile/internal/ssa/print.go
@@ -9,7 +9,7 @@ import (
"io"
"strings"
- "cmd/internal/notsha256"
+ "cmd/internal/hash"
"cmd/internal/src"
)
@@ -18,7 +18,7 @@ func printFunc(f *Func) {
}
func hashFunc(f *Func) []byte {
- h := notsha256.New()
+ h := hash.New32()
p := stringFuncPrinter{w: h, printDead: true}
fprintFunc(p, f)
return h.Sum(nil)
@@ -33,7 +33,7 @@ func (f *Func) String() string {
// rewriteHash returns a hash of f suitable for detecting rewrite cycles.
func (f *Func) rewriteHash() string {
- h := notsha256.New()
+ h := hash.New32()
p := stringFuncPrinter{w: h, printDead: false}
fprintFunc(p, f)
return fmt.Sprintf("%x", h.Sum(nil))
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
diff --git a/src/cmd/compile/internal/types/fmt.go b/src/cmd/compile/internal/types/fmt.go
index d6cc2483a6..f316a23b90 100644
--- a/src/cmd/compile/internal/types/fmt.go
+++ b/src/cmd/compile/internal/types/fmt.go
@@ -12,7 +12,7 @@ import (
"sync"
"cmd/compile/internal/base"
- "cmd/internal/notsha256"
+ "cmd/internal/hash"
)
// BuiltinPkg is a fake package that declares the universe block.
@@ -644,7 +644,7 @@ func SplitVargenSuffix(name string) (base, suffix string) {
func TypeHash(t *Type) uint32 {
p := t.LinkString()
- // Using SHA256 is overkill, but reduces accidental collisions.
- h := notsha256.Sum256([]byte(p))
+ // Using 32 bytes hash is overkill, but reduces accidental collisions.
+ h := hash.Sum32([]byte(p))
return binary.LittleEndian.Uint32(h[:4])
}