Skip to content

Commit 5ca785d

Browse files
cuonglmgopherbot
authored andcommitted
cmd: use 16 bytes hash when possible
CL 402595 changes all usages of 16 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 16 bytes hash using cmd/internal/hash package. Updates #51940 Updates #64751 Change-Id: Ic015468ca4a49d0c3b1fb9fdbed93fddef3c838f Reviewed-on: https://go-review.googlesource.com/c/go/+/610598 Auto-Submit: Cuong Manh Le <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent f033bc1 commit 5ca785d

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

src/cmd/cgo/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ func main() {
388388
// we use to coordinate between gcc and ourselves.
389389
// We already put _cgo_ at the beginning, so the main
390390
// concern is other cgo wrappers for the same functions.
391-
// Use the beginning of the 32 bytes hash of the input to disambiguate.
392-
h := hash.New32()
391+
// Use the beginning of the 16 bytes hash of the input to disambiguate.
392+
h := hash.New16()
393393
io.WriteString(h, *importPath)
394394
var once sync.Once
395395
var wg sync.WaitGroup

src/cmd/compile/internal/types/fmt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ func SplitVargenSuffix(name string) (base, suffix string) {
644644
func TypeHash(t *Type) uint32 {
645645
p := t.LinkString()
646646

647-
// Using 32 bytes hash is overkill, but reduces accidental collisions.
648-
h := hash.Sum32([]byte(p))
647+
// Using 16 bytes hash is overkill, but reduces accidental collisions.
648+
h := hash.Sum16([]byte(p))
649649
return binary.LittleEndian.Uint32(h[:4])
650650
}

src/cmd/internal/obj/sym.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func (ctxt *Link) Int128Sym(hi, lo int64) *LSym {
207207

208208
// GCLocalsSym generates a content-addressable sym containing data.
209209
func (ctxt *Link) GCLocalsSym(data []byte) *LSym {
210-
sum := hash.Sum32(data)
210+
sum := hash.Sum16(data)
211211
str := base64.StdEncoding.EncodeToString(sum[:16])
212212
return ctxt.LookupInit(fmt.Sprintf("gclocals·%s", str), func(lsym *LSym) {
213213
lsym.P = data

src/cmd/objdump/objdump_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func testDisasm(t *testing.T, srcfname string, printCode bool, printGnuAsm bool,
126126
goarch = f[1]
127127
}
128128

129-
hash := hash.Sum32([]byte(fmt.Sprintf("%v-%v-%v-%v", srcfname, flags, printCode, printGnuAsm)))
129+
hash := hash.Sum16([]byte(fmt.Sprintf("%v-%v-%v-%v", srcfname, flags, printCode, printGnuAsm)))
130130
tmp := t.TempDir()
131131
hello := filepath.Join(tmp, fmt.Sprintf("hello-%x.exe", hash))
132132
args := []string{"build", "-o", hello}

0 commit comments

Comments
 (0)