]> Cypherpunks repositories - gostls13.git/commitdiff
cmd: use 16 bytes hash when possible
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 4 Sep 2024 11:45:17 +0000 (18:45 +0700)
committerGopher Robot <gobot@golang.org>
Wed, 4 Sep 2024 18:27:07 +0000 (18:27 +0000)
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 <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/cgo/main.go
src/cmd/compile/internal/types/fmt.go
src/cmd/internal/obj/sym.go
src/cmd/objdump/objdump_test.go

index 946245bbe74fc773b5478cb57a9eaf7212945222..7a78cd270d49df310dddba75ef5203dd93f0d9ce 100644 (file)
@@ -388,8 +388,8 @@ func main() {
        // we use to coordinate between gcc and ourselves.
        // We already put _cgo_ at the beginning, so the main
        // concern is other cgo wrappers for the same functions.
-       // Use the beginning of the 32 bytes hash of the input to disambiguate.
-       h := hash.New32()
+       // Use the beginning of the 16 bytes hash of the input to disambiguate.
+       h := hash.New16()
        io.WriteString(h, *importPath)
        var once sync.Once
        var wg sync.WaitGroup
index f316a23b900f6dc6ee586a99ccb271fe5c12d83c..96c63528ec9eaf1b932fdf76c666955a3c9ee15c 100644 (file)
@@ -644,7 +644,7 @@ func SplitVargenSuffix(name string) (base, suffix string) {
 func TypeHash(t *Type) uint32 {
        p := t.LinkString()
 
-       // Using 32 bytes hash is overkill, but reduces accidental collisions.
-       h := hash.Sum32([]byte(p))
+       // Using 16 bytes hash is overkill, but reduces accidental collisions.
+       h := hash.Sum16([]byte(p))
        return binary.LittleEndian.Uint32(h[:4])
 }
index 0fd0eb7f0fb1980a18e71402562ce0883e96b876..ac43a812b91c7323498cf5f118d3a2f134b34e8d 100644 (file)
@@ -207,7 +207,7 @@ func (ctxt *Link) Int128Sym(hi, lo int64) *LSym {
 
 // GCLocalsSym generates a content-addressable sym containing data.
 func (ctxt *Link) GCLocalsSym(data []byte) *LSym {
-       sum := hash.Sum32(data)
+       sum := hash.Sum16(data)
        str := base64.StdEncoding.EncodeToString(sum[:16])
        return ctxt.LookupInit(fmt.Sprintf("gclocals·%s", str), func(lsym *LSym) {
                lsym.P = data
index 103517641ed70203b18ef0931ddee9da9d3ebd26..e78f2d3f961e948f6b8e14cccc69639461021259 100644 (file)
@@ -126,7 +126,7 @@ func testDisasm(t *testing.T, srcfname string, printCode bool, printGnuAsm bool,
                goarch = f[1]
        }
 
-       hash := hash.Sum32([]byte(fmt.Sprintf("%v-%v-%v-%v", srcfname, flags, printCode, printGnuAsm)))
+       hash := hash.Sum16([]byte(fmt.Sprintf("%v-%v-%v-%v", srcfname, flags, printCode, printGnuAsm)))
        tmp := t.TempDir()
        hello := filepath.Join(tmp, fmt.Sprintf("hello-%x.exe", hash))
        args := []string{"build", "-o", hello}