Currently, the compiler generates a fingerprint for each package,
which is used by the linker for index consistency check.
When building plugin or shared object, currently the linker also
generates a hash, by hashing the export data. At run time, when
a package is referenced by multiple DSOs, this hash is compared
to ensure consistency.
It would be good if we can unify this two hashes. This way, the
linker doesn't need to read the export data (which is intended
for the compiler only, and is not always available for the
linker). The export data hash is sufficient for both purposes.
It is consistent with the current hash geneated by the linker.
And the export data includes indices for exported symbols, so its
hash can be used to catch index mismatches.
Updates #33820.
Change-Id: I2bc0d74930746f54c683a10dfd695d50ea3f5a38
Reviewed-on: https://go-review.googlesource.com/c/go/+/236118
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
"cmd/compile/internal/types"
"cmd/internal/goobj2"
"cmd/internal/src"
+ "crypto/md5"
"encoding/binary"
"fmt"
"io"
hdr.uint64(dataLen)
// Flush output.
- io.Copy(out, &hdr)
- io.Copy(out, &p.strings)
- io.Copy(out, &p.data0)
+ h := md5.New()
+ wr := io.MultiWriter(out, h)
+ io.Copy(wr, &hdr)
+ io.Copy(wr, &p.strings)
+ io.Copy(wr, &p.data0)
// Add fingerprint (used by linker object file).
// Attach this to the end, so tools (e.g. gcimporter) don't care.
+ copy(Ctxt.Fingerprint[:], h.Sum(nil)[:])
out.Write(Ctxt.Fingerprint[:])
}
import (
"cmd/internal/goobj2"
"cmd/internal/objabi"
- "crypto/md5"
"fmt"
"log"
"math"
ctxt.pkgIdx[pkg] = ipkg
ipkg++
})
-
- // Compute a fingerprint of the indices, for exporting.
- if !ctxt.IsAsm {
- h := md5.New()
- for _, s := range ctxt.defs {
- h.Write([]byte(s.Name))
- }
- copy(ctxt.Fingerprint[:], h.Sum(nil)[:])
- }
}
// Returns whether s is a non-package symbol, which needs to be referenced