]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: call NeedFuncSym in InitLSym
authorMatthew Dempsky <mdempsky@google.com>
Tue, 12 Jan 2021 19:34:00 +0000 (11:34 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 12 Jan 2021 23:21:58 +0000 (23:21 +0000)
InitLSym is where we're now generating ABI wrappers, so it seems as
good a place as any to make sure we're generating the degenerate
closure wrappers for declared functions and methods.

Change-Id: I097f34bbcee65dee87a97f9ed6f3f38e4cf2e2b5
Reviewed-on: https://go-review.googlesource.com/c/go/+/283312
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/main.go
src/cmd/compile/internal/ssagen/abi.go
src/cmd/compile/internal/staticdata/data.go
src/cmd/compile/internal/typecheck/func.go
src/cmd/compile/internal/typecheck/typecheck.go

index c3756309ea55b6e499348b6069b542fba07b213d..1541bc4285f21702c3d6748ae618f315917a854d 100644 (file)
@@ -20,7 +20,6 @@ import (
        "cmd/compile/internal/reflectdata"
        "cmd/compile/internal/ssa"
        "cmd/compile/internal/ssagen"
-       "cmd/compile/internal/staticdata"
        "cmd/compile/internal/typecheck"
        "cmd/compile/internal/types"
        "cmd/compile/internal/walk"
@@ -194,7 +193,6 @@ func Main(archInit func(*ssagen.ArchInfo)) {
 
        typecheck.Target = new(ir.Package)
 
-       typecheck.NeedFuncSym = staticdata.NeedFuncSym
        typecheck.NeedITab = func(t, iface *types.Type) { reflectdata.ITabAddr(t, iface) }
        typecheck.NeedRuntimeType = reflectdata.NeedRuntimeType // TODO(rsc): typenamesym for lock?
 
index 1c013dd2d87579091290ed6a8b5dba21d9e76989..dc27ec3a29f47801f41cfaf054ace1b713e483d9 100644 (file)
@@ -14,6 +14,7 @@ import (
        "cmd/compile/internal/base"
        "cmd/compile/internal/escape"
        "cmd/compile/internal/ir"
+       "cmd/compile/internal/staticdata"
        "cmd/compile/internal/typecheck"
        "cmd/compile/internal/types"
        "cmd/internal/obj"
@@ -137,6 +138,8 @@ func ReadSymABIs(file, myimportpath string) {
 // For body-less functions, we only create the LSym; for functions
 // with bodies call a helper to setup up / populate the LSym.
 func InitLSym(f *ir.Func, hasBody bool) {
+       staticdata.NeedFuncSym(f.Sym())
+
        // FIXME: for new-style ABI wrappers, we set up the lsym at the
        // point the wrapper is created.
        if f.LSym != nil && base.Flag.ABIWrap {
@@ -152,7 +155,7 @@ func InitLSym(f *ir.Func, hasBody bool) {
 // makes calls to helpers to create ABI wrappers if needed.
 func selectLSym(f *ir.Func, hasBody bool) {
        if f.LSym != nil {
-               base.Fatalf("Func.initLSym called twice")
+               base.FatalfAt(f.Pos(), "Func.initLSym called twice on %v", f)
        }
 
        if nam := f.Nname; !ir.IsBlank(nam) {
index a2a844f94025e38fc86c574cdfdb65b6a18aef4e..4b12590fde4e7e4bf1f2521a2b2d3af155a2c049 100644 (file)
@@ -265,7 +265,7 @@ func FuncLinksym(n *ir.Name) *obj.LSym {
        return FuncSym(n.Sym()).Linksym()
 }
 
-// NeedFuncSym ensures that s·f is exported.
+// NeedFuncSym ensures that s·f is exported, if needed.
 // It is only used with -dynlink.
 // When not compiling for dynamic linking,
 // the funcsyms are created as needed by
@@ -275,8 +275,13 @@ func FuncLinksym(n *ir.Name) *obj.LSym {
 // So instead, when dynamic linking, we only create
 // the s·f stubs in s's package.
 func NeedFuncSym(s *types.Sym) {
+       if base.Ctxt.InParallel {
+               // The append below probably just needs to lock
+               // funcsymsmu, like in FuncSym.
+               base.Fatalf("NeedFuncSym must be called in serial")
+       }
        if !base.Ctxt.Flag_dynlink {
-               base.Fatalf("NeedFuncSym: dynlink")
+               return
        }
        if s.IsBlank() {
                return
@@ -287,9 +292,7 @@ func NeedFuncSym(s *types.Sym) {
                // get funcsyms.
                return
        }
-       if _, existed := s.Pkg.LookupOK(ir.FuncSymName(s)); !existed {
-               funcsyms = append(funcsyms, s)
-       }
+       funcsyms = append(funcsyms, s)
 }
 
 func WriteFuncSyms() {
index 12762f7ee8f55b2224a15cf3505a58b39c640a71..8f7411daecee7dca53af9357798abf826395a0d0 100644 (file)
@@ -364,10 +364,6 @@ func tcFunc(n *ir.Func) {
                n.Nname.SetSym(ir.MethodSym(rcvr.Type, n.Shortname))
                Declare(n.Nname, ir.PFUNC)
        }
-
-       if base.Ctxt.Flag_dynlink && !inimport && n.Nname != nil {
-               NeedFuncSym(n.Sym())
-       }
 }
 
 // tcCall typechecks an OCALL node.
index 3fc077b00cb180a9292ddba4a8127da101696999..814af59772b1222c3c34db6f544f47569955a79f 100644 (file)
@@ -24,7 +24,6 @@ var inimport bool // set during import
 var TypecheckAllowed bool
 
 var (
-       NeedFuncSym     = func(*types.Sym) {}
        NeedITab        = func(t, itype *types.Type) {}
        NeedRuntimeType = func(*types.Type) {}
 )
@@ -1140,12 +1139,6 @@ func typecheckMethodExpr(n *ir.SelectorExpr) (res ir.Node) {
        n.SetOp(ir.OMETHEXPR)
        n.Selection = m
        n.SetType(NewMethodType(m.Type, n.X.Type()))
-
-       // Issue 25065. Make sure that we emit the symbol for a local method.
-       if base.Ctxt.Flag_dynlink && !inimport && (t.Sym() == nil || t.Sym().Pkg == types.LocalPkg) {
-               NeedFuncSym(n.FuncName().Sym())
-       }
-
        return n
 }