diff options
| author | Matthew Dempsky <mdempsky@google.com> | 2022-03-23 12:10:02 -0700 |
|---|---|---|
| committer | Matthew Dempsky <mdempsky@google.com> | 2022-03-28 19:58:45 +0000 |
| commit | 42ca44494c6ca94c6a1f433e61bc5d95d51b2222 (patch) | |
| tree | 568d6f0c684e57e47df201664f15087d16cd09b5 /src/internal/pkgbits/decoder.go | |
| parent | 1a9972ec87de1eba7f9f71c8ed4afa88b0c122d4 (diff) | |
| download | go-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/decoder.go')
| -rw-r--r-- | src/internal/pkgbits/decoder.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/internal/pkgbits/decoder.go b/src/internal/pkgbits/decoder.go index 9c8ad446ca..5b4e8f69af 100644 --- a/src/internal/pkgbits/decoder.go +++ b/src/internal/pkgbits/decoder.go @@ -22,7 +22,7 @@ type PkgDecoder struct { elemEndsEnds [numRelocs]uint32 elemEnds []uint32 - elemData string + elemData string // last 8 bytes are fingerprint } func (pr *PkgDecoder) PkgPath() string { return pr.pkgPath } @@ -50,7 +50,7 @@ func NewPkgDecoder(pkgPath, input string) PkgDecoder { assert(err == nil) pr.elemData = input[pos:] - assert(len(pr.elemData) == int(pr.elemEnds[len(pr.elemEnds)-1])) + assert(len(pr.elemData)-8 == int(pr.elemEnds[len(pr.elemEnds)-1])) return pr } @@ -67,6 +67,12 @@ func (pr *PkgDecoder) TotalElems() int { return len(pr.elemEnds) } +func (pr *PkgDecoder) Fingerprint() [8]byte { + var fp [8]byte + copy(fp[:], pr.elemData[len(pr.elemData)-8:]) + return fp +} + func (pr *PkgDecoder) AbsIdx(k RelocKind, idx int) int { absIdx := idx if k > 0 { |
