]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: write type symbols referenced in ptabs
authorDavid Crawshaw <crawshaw@golang.org>
Fri, 23 Sep 2016 22:39:31 +0000 (08:39 +1000)
committerDavid Crawshaw <crawshaw@golang.org>
Thu, 3 Nov 2016 14:07:34 +0000 (14:07 +0000)
The exported symbol for a plugin can be the only reference to a
type in a program. In particular, "var F func()" will have
the type *func(), which is uncommon.

Fixes #17140

Change-Id: Ide2104edbf087565f5377374057ae54e0c00c57e
Reviewed-on: https://go-review.googlesource.com/29692
Run-TryBot: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
misc/cgo/testplugin/src/host/host.go
misc/cgo/testplugin/src/sub/plugin1/plugin1.go
src/cmd/compile/internal/gc/reflect.go
src/cmd/link/internal/ld/deadcode.go

index 636655aa5c92d25c65e11a1a01d3e7b7e61bb6ef..477a9e63a284445ceee176547512baaf78c5da68 100644 (file)
@@ -61,6 +61,15 @@ func main() {
                log.Fatalf("plugin.Open(%q) failed: %v", subpPath, err)
        }
 
+       funcVar, err := subp.Lookup("FuncVar")
+       if err != nil {
+               log.Fatalf(`sub/plugin1.Lookup("FuncVar") failed: %v`, err)
+       }
+       called := false
+       *funcVar.(*func()) = func() {
+               called = true
+       }
+
        readFunc, err = subp.Lookup("ReadCommonX")
        if err != nil {
                log.Fatalf(`sub/plugin1.Lookup("ReadCommonX") failed: %v`, err)
@@ -68,6 +77,9 @@ func main() {
        if got := readFunc.(func() int)(); got != wantX {
                log.Fatalf("sub/plugin1.ReadCommonX()=%d, want %d", got, wantX)
        }
+       if !called {
+               log.Fatal("calling ReadCommonX did not call FuncVar")
+       }
 
        subf, err := subp.Lookup("F")
        if err != nil {
index 4ed76c7caf531fb2595477cfbd24115668e74110..cf9000c4a4e09f840ca2847656fc5bc85ff2eeef 100644 (file)
@@ -11,7 +11,10 @@ import "common"
 
 func F() int { return 17 }
 
+var FuncVar = func() {}
+
 func ReadCommonX() int {
+       FuncVar()
        return common.X
 }
 
index 26643c0250c881107bead4088f4db35882f4bcd8..14f7ab66ee32e4934ed6820e56a0ab5c83e95934 100644 (file)
@@ -1416,7 +1416,7 @@ func dumptypestructs() {
                        // }
                        nsym := dname(p.s.Name, "", nil, true)
                        ot = dsymptrOffLSym(s, ot, nsym, 0)
-                       ot = dsymptrOffLSym(s, ot, Linksym(typesym(p.t)), 0)
+                       ot = dsymptrOffLSym(s, ot, Linksym(dtypesym(p.t)), 0)
                }
                ggloblLSym(s, int32(ot), int16(obj.RODATA))
 
index ac6481322819e6840e4a4b475de3a64e4cc9172c..335d9849c9dca83c622cc47679c0dfffd122b04b 100644 (file)
@@ -290,6 +290,11 @@ func (d *deadcodepass) flood() {
                }
 
                if strings.HasPrefix(s.Name, "type.") && s.Name[5] != '.' {
+                       if len(s.P) == 0 {
+                               // Probably a bug. The undefined symbol check
+                               // later will give a better error than deadcode.
+                               continue
+                       }
                        if decodetypeKind(s)&kindMask == kindInterface {
                                for _, sig := range decodeIfaceMethods(d.ctxt.Arch, s) {
                                        if d.ctxt.Debugvlog > 1 {