From bd229936cf3873c552ab087232030780dc432067 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Thu, 17 Oct 2019 01:17:42 -0400 Subject: [PATCH] [dev.link] cmd/link: restore export data hash With the previous CL, the export data will not change whether it is compiled with -dynlink flag or not. Restore the export data hash, and reenable plugin version check. TODO: it may be still better to just generate a fingerprint for each package at compile time. Change-Id: I1f298ac97c3ab9b8d05d1c95e8be74d10ca7cd0e Reviewed-on: https://go-review.googlesource.com/c/go/+/201720 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot Reviewed-by: Than McIntosh --- misc/cgo/testplugin/testdata/host/host.go | 13 ++++++------- src/cmd/link/internal/ld/lib.go | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/misc/cgo/testplugin/testdata/host/host.go b/misc/cgo/testplugin/testdata/host/host.go index d836523da8..a3799328cd 100644 --- a/misc/cgo/testplugin/testdata/host/host.go +++ b/misc/cgo/testplugin/testdata/host/host.go @@ -145,13 +145,12 @@ func main() { } _, err = plugin.Open("plugin-mismatch.so") - // TODO: newobj - //if err == nil { - // log.Fatal(`plugin.Open("plugin-mismatch.so"): should have failed`) - //} - //if s := err.Error(); !strings.Contains(s, "different version") { - // log.Fatalf(`plugin.Open("plugin-mismatch.so"): error does not mention "different version": %v`, s) - //} + if err == nil { + log.Fatal(`plugin.Open("plugin-mismatch.so"): should have failed`) + } + if s := err.Error(); !strings.Contains(s, "different version") { + log.Fatalf(`plugin.Open("plugin-mismatch.so"): error does not mention "different version": %v`, s) + } _, err = plugin.Open("plugin2-dup.so") if err == nil { diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 063bdded0c..63dcb22d98 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -816,7 +816,7 @@ func genhash(ctxt *Link, lib *sym.Library) { return } h.Write(pkgDefBytes[0:firstEOL]) - //h.Write(pkgDefBytes[firstDoubleDollar : firstDoubleDollar+secondDoubleDollar]) // TODO: newobj: -dynlink may change symbol numbering? which will make the export data differ + h.Write(pkgDefBytes[firstDoubleDollar : firstDoubleDollar+secondDoubleDollar]) lib.Hash = hex.EncodeToString(h.Sum(nil)) } -- 2.48.1