diff options
author | Cherry Zhang <cherryyz@google.com> | 2020-11-06 22:46:18 -0500 |
---|---|---|
committer | Cherry Zhang <cherryyz@google.com> | 2020-11-09 16:09:16 +0000 |
commit | a444458112e4059e73c9a5a2bc5867f53bf9faa2 (patch) | |
tree | 8bc0141a186b88074b93b7435a1db0fe451acd22 /test | |
parent | 979e1376096a4c1c7525f33dd4e76414f63c93fb (diff) | |
download | go-a444458112e4059e73c9a5a2bc5867f53bf9faa2.tar.gz go-a444458112e4059e73c9a5a2bc5867f53bf9faa2.zip |
cmd/compile: make sure linkname'd symbol is non-package
When a variable symbol is both imported (possibly through
inlining) and linkname'd, make sure its LSym is marked as
non-package for symbol indexing in the object file, so it is
resolved by name and dedup'd with the original definition.
Fixes #42401.
Change-Id: I8e90c0418c6f46a048945c5fdc06c022b77ed68d
Reviewed-on: https://go-review.googlesource.com/c/go/+/268178
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/fixedbugs/issue42401.dir/a.go | 11 | ||||
-rw-r--r-- | test/fixedbugs/issue42401.dir/b.go | 24 | ||||
-rw-r--r-- | test/fixedbugs/issue42401.go | 10 |
3 files changed, 45 insertions, 0 deletions
diff --git a/test/fixedbugs/issue42401.dir/a.go b/test/fixedbugs/issue42401.dir/a.go new file mode 100644 index 00000000000..75f8e7f91fc --- /dev/null +++ b/test/fixedbugs/issue42401.dir/a.go @@ -0,0 +1,11 @@ +// 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 + +var s string + +func init() { s = "a" } + +func Get() string { return s } diff --git a/test/fixedbugs/issue42401.dir/b.go b/test/fixedbugs/issue42401.dir/b.go new file mode 100644 index 00000000000..a834f4efe8d --- /dev/null +++ b/test/fixedbugs/issue42401.dir/b.go @@ -0,0 +1,24 @@ +// 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 main + +import ( + "./a" + _ "unsafe" +) + +//go:linkname s a.s +var s string + +func main() { + if a.Get() != "a" { + panic("FAIL") + } + + s = "b" + if a.Get() != "b" { + panic("FAIL") + } +} diff --git a/test/fixedbugs/issue42401.go b/test/fixedbugs/issue42401.go new file mode 100644 index 00000000000..794d5b01b55 --- /dev/null +++ b/test/fixedbugs/issue42401.go @@ -0,0 +1,10 @@ +// rundir + +// 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. + +// Issue 42401: linkname doesn't work correctly when a variable symbol +// is both imported (possibly through inlining) and linkname'd. + +package ignored |