Skip to content

Commit f033bc1

Browse files
cuonglmgopherbot
authored andcommitted
cmd: use 20 bytes hash when possible
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 <[email protected]> Auto-Submit: Cuong Manh Le <[email protected]> Reviewed-by: Keith Randall <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 4fd73e5 commit f033bc1

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

src/cmd/compile/internal/liveness/plive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ func (lv *liveness) enableClobber() {
979979
// Clobber only functions where the hash of the function name matches a pattern.
980980
// Useful for binary searching for a miscompiled function.
981981
hstr := ""
982-
for _, b := range hash.Sum32([]byte(lv.f.Name)) {
982+
for _, b := range hash.Sum20([]byte(lv.f.Name)) {
983983
hstr += fmt.Sprintf("%08b", b)
984984
}
985985
if !strings.HasSuffix(hstr, h) {

src/cmd/internal/obj/objfile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ func contentHash64(s *LSym) goobj.Hash64Type {
494494
// For now, we assume there is no circular dependencies among
495495
// hashed symbols.
496496
func (w *writer) contentHash(s *LSym) goobj.HashType {
497-
h := hash.New32()
497+
h := hash.New20()
498498
var tmp [14]byte
499499

500500
// Include the size of the symbol in the hash.

src/cmd/link/internal/ld/elf.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,11 +1677,11 @@ func (ctxt *Link) doelf() {
16771677
sb.SetType(sym.SRODATA)
16781678
ldr.SetAttrSpecial(s, true)
16791679
sb.SetReachable(true)
1680-
sb.SetSize(hash.Size32)
1680+
sb.SetSize(hash.Size20)
16811681
slices.SortFunc(ctxt.Library, func(a, b *sym.Library) int {
16821682
return strings.Compare(a.Pkg, b.Pkg)
16831683
})
1684-
h := hash.New32()
1684+
h := hash.New20()
16851685
for _, l := range ctxt.Library {
16861686
h.Write(l.Fingerprint[:])
16871687
}

src/cmd/link/internal/ld/lib.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ func typeSymbolMangle(name string) string {
10121012
return name
10131013
}
10141014
if isType {
1015-
hb := hash.Sum32([]byte(name[5:]))
1015+
hb := hash.Sum20([]byte(name[5:]))
10161016
prefix := "type:"
10171017
if name[5] == '.' {
10181018
prefix = "type:."
@@ -1025,7 +1025,7 @@ func typeSymbolMangle(name string) string {
10251025
if j == -1 || j <= i {
10261026
j = len(name)
10271027
}
1028-
hb := hash.Sum32([]byte(name[i+1 : j]))
1028+
hb := hash.Sum20([]byte(name[i+1 : j]))
10291029
return name[:i+1] + base64.StdEncoding.EncodeToString(hb[:6]) + name[j:]
10301030
}
10311031

0 commit comments

Comments
 (0)