aboutsummaryrefslogtreecommitdiff
path: root/src/internal/pkgbits/encoder.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2022-03-23 12:10:02 -0700
committerMatthew Dempsky <mdempsky@google.com>2022-03-28 19:58:45 +0000
commit42ca44494c6ca94c6a1f433e61bc5d95d51b2222 (patch)
tree568d6f0c684e57e47df201664f15087d16cd09b5 /src/internal/pkgbits/encoder.go
parent1a9972ec87de1eba7f9f71c8ed4afa88b0c122d4 (diff)
downloadgo-42ca44494c6ca94c6a1f433e61bc5d95d51b2222.tar.xz
internal/pkgbits: add fingerprints to unified IR export format
So far unified IR has been relying on the backwards-compat iexport data to supply package fingerprints for imports. To be able to drop the iexport data and natively use unified IR everywhere. This CL applies basically the same idea that iexport used: simply hash all of the export data as it's being written out, and then tack on an 8-byte hash at the end. Change-Id: Iaca5fbfd7443088bc7f422a1c58be3e762c29014 Reviewed-on: https://go-review.googlesource.com/c/go/+/396196 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/internal/pkgbits/encoder.go')
-rw-r--r--src/internal/pkgbits/encoder.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/internal/pkgbits/encoder.go b/src/internal/pkgbits/encoder.go
index 820c707940..4780f01c39 100644
--- a/src/internal/pkgbits/encoder.go
+++ b/src/internal/pkgbits/encoder.go
@@ -8,6 +8,7 @@ package pkgbits
import (
"bytes"
+ "crypto/md5"
"encoding/binary"
"go/constant"
"io"
@@ -30,7 +31,10 @@ func NewPkgEncoder(syncFrames int) PkgEncoder {
}
}
-func (pw *PkgEncoder) DumpTo(out io.Writer) {
+func (pw *PkgEncoder) DumpTo(out0 io.Writer) (fingerprint [8]byte) {
+ h := md5.New()
+ out := io.MultiWriter(out0, h)
+
writeUint32 := func(x uint32) {
assert(binary.Write(out, binary.LittleEndian, x) == nil)
}
@@ -57,6 +61,12 @@ func (pw *PkgEncoder) DumpTo(out io.Writer) {
assert(err == nil)
}
}
+
+ copy(fingerprint[:], h.Sum(nil))
+ _, err := out0.Write(fingerprint[:])
+ assert(err == nil)
+
+ return
}
func (pw *PkgEncoder) StringIdx(s string) int {