]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: skip zero values in fingerprint check
authorCherry Zhang <cherryyz@google.com>
Tue, 23 Jun 2020 16:02:54 +0000 (12:02 -0400)
committerCherry Zhang <cherryyz@google.com>
Tue, 23 Jun 2020 18:38:32 +0000 (18:38 +0000)
Normally, packages are loaded in dependency order, and if a
Library object is not nil, it is already loaded with the actual
fingerprint. In shared build mode, however, packages may be added
not in dependency order (e.g. go install -buildmode=shared std
adds all std packages before loading them), and it is possible
that a Library's fingerprint is not yet loaded. Skip the check
in this case (when the fingerprint is the zero value).

Fixes #39777.

Change-Id: I66208e92bf687c8778963ba8e33e9bd948f82f3a
Reviewed-on: https://go-review.googlesource.com/c/go/+/239517
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
misc/cgo/testshared/shared_test.go
misc/cgo/testshared/testdata/issue39777/a/a.go [new file with mode: 0644]
misc/cgo/testshared/testdata/issue39777/b/b.go [new file with mode: 0644]
src/cmd/link/internal/ld/ld.go

index acae1b2c212c0efe4e989bb1992957c91cc4c3ba..fda3d2ce76fc15a583f4c76bc7be384589ec9257 100644 (file)
@@ -1028,3 +1028,9 @@ func TestGeneratedHash(t *testing.T) {
        goCmd(nil, "install", "-buildmode=shared", "-linkshared", "./issue30768/issue30768lib")
        goCmd(nil, "test", "-linkshared", "./issue30768")
 }
+
+// Test that packages can be added not in dependency order (here a depends on b, and a adds
+// before b). This could happen with e.g. go build -buildmode=shared std. See issue 39777.
+func TestPackageOrder(t *testing.T) {
+       goCmd(t, "install", "-buildmode=shared", "-linkshared", "./issue39777/a", "./issue39777/b")
+}
diff --git a/misc/cgo/testshared/testdata/issue39777/a/a.go b/misc/cgo/testshared/testdata/issue39777/a/a.go
new file mode 100644 (file)
index 0000000..c7bf835
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package a
+
+import "testshared/issue39777/b"
+
+func F() { b.F() }
diff --git a/misc/cgo/testshared/testdata/issue39777/b/b.go b/misc/cgo/testshared/testdata/issue39777/b/b.go
new file mode 100644 (file)
index 0000000..4e68196
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package b
+
+func F() {}
index 71f388b5a0668fc07c0169822ab2ab73837bb8d7..e56a6690fbcceef6cca937522a62d307f73f2100 100644 (file)
@@ -160,7 +160,12 @@ func addlib(ctxt *Link, src, obj, lib string, fingerprint goobj2.FingerprintType
        pkg := pkgname(ctxt, lib)
 
        // already loaded?
-       if l := ctxt.LibraryByPkg[pkg]; l != nil {
+       if l := ctxt.LibraryByPkg[pkg]; l != nil && !l.Fingerprint.IsZero() {
+               // Normally, packages are loaded in dependency order, and if l != nil
+               // l is already loaded with the actual fingerprint. In shared build mode,
+               // however, packages may be added not in dependency order, and it is
+               // possible that l's fingerprint is not yet loaded -- exclude it in
+               // checking.
                checkFingerprint(l, l.Fingerprint, src, fingerprint)
                return l
        }