From: Cherry Zhang Date: Mon, 20 Jul 2020 23:03:33 +0000 (-0400) Subject: [dev.link] cmd/internal/obj: trim trailing zeros for content hashing X-Git-Tag: go1.16beta1~1378^2~29 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b3e3c339ff02ccd1cf76eb07513e4f9051a55333;p=gostls13.git [dev.link] cmd/internal/obj: trim trailing zeros for content hashing The symbol's data in the object file (sym.P) may already not contain trailing zeros (e,g, for [10]int{1}), but sometimes it does (e.g. for [10]int{1,0}). The linker can already handle this case. We just always trim the trailing zeros for content hashing, so it can deduplicate [10]int{1} and [10]int{1,0}. Note: in theory we could just trim the zeros in the symbol data as well. But currently the linker depends on reading symbol data for certain symbols (e.g. type symbol decoding), and trimming will complicates things in the linker. Change-Id: I9e90e41e6ac808b36855b0713a85e61c33bf093a Reviewed-on: https://go-review.googlesource.com/c/go/+/245717 Run-TryBot: Cherry Zhang Reviewed-by: Jeremy Faller --- diff --git a/src/cmd/internal/obj/objfile2.go b/src/cmd/internal/obj/objfile2.go index 6a5f3726f8..6cf82779e4 100644 --- a/src/cmd/internal/obj/objfile2.go +++ b/src/cmd/internal/obj/objfile2.go @@ -373,7 +373,9 @@ func contentHash64(s *LSym) goobj2.Hash64Type { // hashed symbols. func (w *writer) contentHash(s *LSym) goobj2.HashType { h := sha1.New() - h.Write(s.P) + // The compiler trims trailing zeros _sometimes_. We just do + // it always. + h.Write(bytes.TrimRight(s.P, "\x00")) var tmp [14]byte for i := range s.R { r := &s.R[i]