]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/internal/obj: trim trailing zeros for content hashing
authorCherry Zhang <cherryyz@google.com>
Mon, 20 Jul 2020 23:03:33 +0000 (19:03 -0400)
committerCherry Zhang <cherryyz@google.com>
Thu, 30 Jul 2020 18:37:08 +0000 (18:37 +0000)
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 <cherryyz@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
src/cmd/internal/obj/objfile2.go

index 6a5f3726f8a50549f360ad3d63a80921f4947fe6..6cf82779e440ed71520aa495dad3a08c54927082 100644 (file)
@@ -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]