]> Cypherpunks repositories - gostls13.git/commitdiff
cmd: use 20 bytes hash when possible
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 4 Sep 2024 11:39:52 +0000 (18:39 +0700)
committerGopher Robot <gobot@golang.org>
Wed, 4 Sep 2024 18:25:21 +0000 (18:25 +0000)
CL 402595 changes all usages of 20 bytes hash to 32 bytes hash by using
notsha256.

However, since CL 454836, notsha256 is not necessary anymore, so this CL
reverts those changes to 20 bytes hash using cmd/internal/hash package.

Updates #51940
Updates #64751

Change-Id: Icb08d5a0d8032a3c4d050ff7b2298d31c483b88b
Reviewed-on: https://go-review.googlesource.com/c/go/+/610597
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/liveness/plive.go
src/cmd/internal/obj/objfile.go
src/cmd/link/internal/ld/elf.go
src/cmd/link/internal/ld/lib.go

index 09af864b698810df7406515b8a8eae51b6bc135b..2ee007f4a656ea0ebf7794e0272d5d0ba6ba602c 100644 (file)
@@ -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 hash.Sum32([]byte(lv.f.Name)) {
+               for _, b := range hash.Sum20([]byte(lv.f.Name)) {
                        hstr += fmt.Sprintf("%08b", b)
                }
                if !strings.HasSuffix(hstr, h) {
index 6aa208a1c0f78200c4f47caef49c65cbbe7d6ec8..5ac15b82285052e0d2019831c91df333e1062b40 100644 (file)
@@ -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.New32()
+       h := hash.New20()
        var tmp [14]byte
 
        // Include the size of the symbol in the hash.
index f6f957a3339350e7eab6a82ac3c4675fe32fc321..6bdd544a1637c92f38934f3b20e8b0232a7f1cd7 100644 (file)
@@ -1677,11 +1677,11 @@ func (ctxt *Link) doelf() {
                sb.SetType(sym.SRODATA)
                ldr.SetAttrSpecial(s, true)
                sb.SetReachable(true)
-               sb.SetSize(hash.Size32)
+               sb.SetSize(hash.Size20)
                slices.SortFunc(ctxt.Library, func(a, b *sym.Library) int {
                        return strings.Compare(a.Pkg, b.Pkg)
                })
-               h := hash.New32()
+               h := hash.New20()
                for _, l := range ctxt.Library {
                        h.Write(l.Fingerprint[:])
                }
index 61bca491764956d69bf4d831c688e9b0d924bfbc..643356d602417cf132999a51fe7b2e7304ce62cf 100644 (file)
@@ -1012,7 +1012,7 @@ func typeSymbolMangle(name string) string {
                return name
        }
        if isType {
-               hb := hash.Sum32([]byte(name[5:]))
+               hb := hash.Sum20([]byte(name[5:]))
                prefix := "type:"
                if name[5] == '.' {
                        prefix = "type:."
@@ -1025,7 +1025,7 @@ func typeSymbolMangle(name string) string {
        if j == -1 || j <= i {
                j = len(name)
        }
-       hb := hash.Sum32([]byte(name[i+1 : j]))
+       hb := hash.Sum20([]byte(name[i+1 : j]))
        return name[:i+1] + base64.StdEncoding.EncodeToString(hb[:6]) + name[j:]
 }