aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Randall <keithr@alum.mit.edu>2019-04-10 16:44:46 -0700
committerAndrew Bonventre <andybons@golang.org>2019-05-06 18:53:43 +0000
commita17d091120c26c982ca0cde3ac590f49b08fd196 (patch)
treeb78b4bfc79defcd224754d789a213adceaae52c5
parentdc6db5f4340675a6c05d03382728d739208d7a3c (diff)
downloadgo-a17d091120c26c982ca0cde3ac590f49b08fd196.tar.gz
go-a17d091120c26c982ca0cde3ac590f49b08fd196.zip
[release-branch.go1.12] cmd/compile: use correct package name for stack object symbol
Stack object generation code was always using the local package name for its symbol. Normally that doesn't matter, as we usually only compile functions in the local package. But for wrappers, the compiler generates functions which live in other packages. When there are two other packages with identical functions to wrap, the same name appears twice, and the compiler goes boom. Fixes #31396 Change-Id: I7026eebabe562cb159b8b6046cf656afd336ba25 Reviewed-on: https://go-review.googlesource.com/c/go/+/171464 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> (cherry picked from commit 43001a0dc96a29f662f2782c5fb3ca998eadd623) Reviewed-on: https://go-review.googlesource.com/c/go/+/173317 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
-rw-r--r--src/cmd/compile/internal/gc/obj.go2
-rw-r--r--src/cmd/compile/internal/gc/pgen.go2
-rw-r--r--test/fixedbugs/issue31252.dir/a.go13
-rw-r--r--test/fixedbugs/issue31252.dir/b.go13
-rw-r--r--test/fixedbugs/issue31252.dir/c.go26
-rw-r--r--test/fixedbugs/issue31252.dir/main.go11
-rw-r--r--test/fixedbugs/issue31252.go7
7 files changed, 72 insertions, 2 deletions
diff --git a/src/cmd/compile/internal/gc/obj.go b/src/cmd/compile/internal/gc/obj.go
index 5630e12ace..86d52f5084 100644
--- a/src/cmd/compile/internal/gc/obj.go
+++ b/src/cmd/compile/internal/gc/obj.go
@@ -287,7 +287,7 @@ func addGCLocals() {
}
}
if x := s.Func.StackObjects; x != nil {
- ggloblsym(x, int32(len(x.P)), obj.RODATA|obj.LOCAL)
+ ggloblsym(x, int32(len(x.P)), obj.RODATA|obj.DUPOK)
}
}
}
diff --git a/src/cmd/compile/internal/gc/pgen.go b/src/cmd/compile/internal/gc/pgen.go
index 28143dee29..5636ccd1db 100644
--- a/src/cmd/compile/internal/gc/pgen.go
+++ b/src/cmd/compile/internal/gc/pgen.go
@@ -267,7 +267,7 @@ func compile(fn *Node) {
// Also make sure we allocate a linker symbol
// for the stack object data, for the same reason.
if fn.Func.lsym.Func.StackObjects == nil {
- fn.Func.lsym.Func.StackObjects = lookup(fmt.Sprintf("%s.stkobj", fn.funcname())).Linksym()
+ fn.Func.lsym.Func.StackObjects = Ctxt.Lookup(fn.Func.lsym.Name + ".stkobj")
}
}
}
diff --git a/test/fixedbugs/issue31252.dir/a.go b/test/fixedbugs/issue31252.dir/a.go
new file mode 100644
index 0000000000..fa431502c0
--- /dev/null
+++ b/test/fixedbugs/issue31252.dir/a.go
@@ -0,0 +1,13 @@
+// Copyright 2019 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 "fmt"
+
+type IndexController struct{}
+
+func (this *IndexController) Index(m *string) {
+ fmt.Println(m)
+}
diff --git a/test/fixedbugs/issue31252.dir/b.go b/test/fixedbugs/issue31252.dir/b.go
new file mode 100644
index 0000000000..9bfc0ff92e
--- /dev/null
+++ b/test/fixedbugs/issue31252.dir/b.go
@@ -0,0 +1,13 @@
+// Copyright 2019 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
+
+import "fmt"
+
+type IndexController struct{}
+
+func (this *IndexController) Index(m *string) {
+ fmt.Println(m)
+}
diff --git a/test/fixedbugs/issue31252.dir/c.go b/test/fixedbugs/issue31252.dir/c.go
new file mode 100644
index 0000000000..928c8eee1c
--- /dev/null
+++ b/test/fixedbugs/issue31252.dir/c.go
@@ -0,0 +1,26 @@
+// Copyright 2019 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 c
+
+import (
+ "a"
+ "b"
+)
+
+type HandlerFunc func(*string)
+
+func RouterInit() {
+ //home API
+ homeIndex := &a.IndexController{}
+ GET("/home/index/index", homeIndex.Index)
+ //admin API
+ adminIndex := &b.IndexController{}
+ GET("/admin/index/index", adminIndex.Index)
+ return
+}
+
+func GET(path string, handlers ...HandlerFunc) {
+ return
+}
diff --git a/test/fixedbugs/issue31252.dir/main.go b/test/fixedbugs/issue31252.dir/main.go
new file mode 100644
index 0000000000..25a7548668
--- /dev/null
+++ b/test/fixedbugs/issue31252.dir/main.go
@@ -0,0 +1,11 @@
+// Copyright 2019 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 "c"
+
+func main() {
+ c.RouterInit()
+}
diff --git a/test/fixedbugs/issue31252.go b/test/fixedbugs/issue31252.go
new file mode 100644
index 0000000000..973ae1dcef
--- /dev/null
+++ b/test/fixedbugs/issue31252.go
@@ -0,0 +1,7 @@
+// compiledir
+
+// Copyright 2019 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 ignored