Skip to content

Commit 9f33108

Browse files
committed
cmd/link: skip zero values in fingerprint check
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
1 parent 18bcc7c commit 9f33108

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

misc/cgo/testshared/shared_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,3 +1028,9 @@ func TestGeneratedHash(t *testing.T) {
10281028
goCmd(nil, "install", "-buildmode=shared", "-linkshared", "./issue30768/issue30768lib")
10291029
goCmd(nil, "test", "-linkshared", "./issue30768")
10301030
}
1031+
1032+
// Test that packages can be added not in dependency order (here a depends on b, and a adds
1033+
// before b). This could happen with e.g. go build -buildmode=shared std. See issue 39777.
1034+
func TestPackageOrder(t *testing.T) {
1035+
goCmd(t, "install", "-buildmode=shared", "-linkshared", "./issue39777/a", "./issue39777/b")
1036+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2020 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package a
6+
7+
import "testshared/issue39777/b"
8+
9+
func F() { b.F() }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2020 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package b
6+
7+
func F() {}

src/cmd/link/internal/ld/ld.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,12 @@ func addlib(ctxt *Link, src, obj, lib string, fingerprint goobj2.FingerprintType
160160
pkg := pkgname(ctxt, lib)
161161

162162
// already loaded?
163-
if l := ctxt.LibraryByPkg[pkg]; l != nil {
163+
if l := ctxt.LibraryByPkg[pkg]; l != nil && !l.Fingerprint.IsZero() {
164+
// Normally, packages are loaded in dependency order, and if l != nil
165+
// l is already loaded with the actual fingerprint. In shared build mode,
166+
// however, packages may be added not in dependency order, and it is
167+
// possible that l's fingerprint is not yet loaded -- exclude it in
168+
// checking.
164169
checkFingerprint(l, l.Fingerprint, src, fingerprint)
165170
return l
166171
}

0 commit comments

Comments
 (0)