Skip to content

Commit 43001a0

Browse files
committed
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 #31252 Change-Id: I7026eebabe562cb159b8b6046cf656afd336ba25 Reviewed-on: https://go-review.googlesource.com/c/go/+/171464 Run-TryBot: Keith Randall <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent d1f43cc commit 43001a0

File tree

7 files changed

+72
-2
lines changed

7 files changed

+72
-2
lines changed

src/cmd/compile/internal/gc/obj.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func addGCLocals() {
287287
}
288288
}
289289
if x := s.Func.StackObjects; x != nil {
290-
ggloblsym(x, int32(len(x.P)), obj.RODATA|obj.LOCAL)
290+
ggloblsym(x, int32(len(x.P)), obj.RODATA|obj.DUPOK)
291291
}
292292
}
293293
}

src/cmd/compile/internal/gc/pgen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func compile(fn *Node) {
266266
// Also make sure we allocate a linker symbol
267267
// for the stack object data, for the same reason.
268268
if fn.Func.lsym.Func.StackObjects == nil {
269-
fn.Func.lsym.Func.StackObjects = lookup(fmt.Sprintf("%s.stkobj", fn.funcname())).Linksym()
269+
fn.Func.lsym.Func.StackObjects = Ctxt.Lookup(fn.Func.lsym.Name + ".stkobj")
270270
}
271271
}
272272
}

test/fixedbugs/issue31252.dir/a.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2019 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 "fmt"
8+
9+
type IndexController struct{}
10+
11+
func (this *IndexController) Index(m *string) {
12+
fmt.Println(m)
13+
}

test/fixedbugs/issue31252.dir/b.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2019 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+
import "fmt"
8+
9+
type IndexController struct{}
10+
11+
func (this *IndexController) Index(m *string) {
12+
fmt.Println(m)
13+
}

test/fixedbugs/issue31252.dir/c.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2019 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 c
6+
7+
import (
8+
"a"
9+
"b"
10+
)
11+
12+
type HandlerFunc func(*string)
13+
14+
func RouterInit() {
15+
//home API
16+
homeIndex := &a.IndexController{}
17+
GET("/home/index/index", homeIndex.Index)
18+
//admin API
19+
adminIndex := &b.IndexController{}
20+
GET("/admin/index/index", adminIndex.Index)
21+
return
22+
}
23+
24+
func GET(path string, handlers ...HandlerFunc) {
25+
return
26+
}

test/fixedbugs/issue31252.dir/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2019 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 main
6+
7+
import "c"
8+
9+
func main() {
10+
c.RouterInit()
11+
}

test/fixedbugs/issue31252.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// compiledir
2+
3+
// Copyright 2019 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package ignored

0 commit comments

Comments
 (0)