]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: track funcsyms by ir.Name instead of types.Sym
authorAustin Clements <austin@google.com>
Wed, 24 Mar 2021 18:28:18 +0000 (14:28 -0400)
committerAustin Clements <austin@google.com>
Mon, 29 Mar 2021 18:46:27 +0000 (18:46 +0000)
This is a cleanup to bring funcsym tracking a little closer to the
ir.Func. (I thought I needed this for a later change. That turned out
not to be the case, but it's a nice cleanup.)

Change-Id: I53e692f5d7ba4be56d42d8e0aefc06284cea0661
Reviewed-on: https://go-review.googlesource.com/c/go/+/305270
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/compile/internal/ssagen/abi.go
src/cmd/compile/internal/staticdata/data.go

index 6d391ed9f7d9f62ad56e1f63e26efb704817b656..b6137756d40703917359b5e64a148938e3f65c15 100644 (file)
@@ -143,7 +143,7 @@ func InitLSym(f *ir.Func, hasBody bool) {
        if f.LSym != nil && objabi.Experiment.RegabiWrappers {
                return
        }
-       staticdata.NeedFuncSym(f.Sym())
+       staticdata.NeedFuncSym(f)
        selectLSym(f, hasBody)
        if hasBody {
                setupTextLSym(f, 0)
index b06fd7aa4b246394177890ce8052488ff63ab792..fca2a63eb4b601720b0a7335ff6de51279833fab 100644 (file)
@@ -214,11 +214,16 @@ func dstringdata(s *obj.LSym, off int, t string, pos src.XPos, what string) int
 
 var (
        funcsymsmu sync.Mutex // protects funcsyms and associated package lookups (see func funcsym)
-       funcsyms   []*types.Sym
+       funcsyms   []*ir.Name // functions that need function value symbols
 )
 
-// FuncSym returns s·f.
-func FuncSym(s *types.Sym) *types.Sym {
+// FuncLinksym returns n·f, the function value symbol for n.
+func FuncLinksym(n *ir.Name) *obj.LSym {
+       if n.Op() != ir.ONAME || n.Class != ir.PFUNC {
+               base.Fatalf("expected func name: %v", n)
+       }
+       s := n.Sym()
+
        // funcsymsmu here serves to protect not just mutations of funcsyms (below),
        // but also the package lookup of the func sym name,
        // since this function gets called concurrently from the backend.
@@ -235,17 +240,11 @@ func FuncSym(s *types.Sym) *types.Sym {
        // symbols will be created explicitly with NeedFuncSym.
        // See the NeedFuncSym comment for details.
        if !base.Ctxt.Flag_dynlink && !existed {
-               funcsyms = append(funcsyms, s)
+               funcsyms = append(funcsyms, n)
        }
        funcsymsmu.Unlock()
-       return sf
-}
 
-func FuncLinksym(n *ir.Name) *obj.LSym {
-       if n.Op() != ir.ONAME || n.Class != ir.PFUNC {
-               base.Fatalf("expected func name: %v", n)
-       }
-       return FuncSym(n.Sym()).Linksym()
+       return sf.Linksym()
 }
 
 func GlobalLinksym(n *ir.Name) *obj.LSym {
@@ -255,16 +254,16 @@ func GlobalLinksym(n *ir.Name) *obj.LSym {
        return n.Linksym()
 }
 
-// NeedFuncSym ensures that s·f is exported, if needed.
+// NeedFuncSym ensures that fn·f is exported, if needed.
 // It is only used with -dynlink.
 // When not compiling for dynamic linking,
 // the funcsyms are created as needed by
 // the packages that use them.
-// Normally we emit the s·f stubs as DUPOK syms,
+// Normally we emit the fn·f stubs as DUPOK syms,
 // but DUPOK doesn't work across shared library boundaries.
 // So instead, when dynamic linking, we only create
-// the s·f stubs in s's package.
-func NeedFuncSym(s *types.Sym) {
+// the fn·f stubs in fn's package.
+func NeedFuncSym(fn *ir.Func) {
        if base.Ctxt.InParallel {
                // The append below probably just needs to lock
                // funcsymsmu, like in FuncSym.
@@ -273,6 +272,7 @@ func NeedFuncSym(s *types.Sym) {
        if !base.Ctxt.Flag_dynlink {
                return
        }
+       s := fn.Nname.Sym()
        if s.IsBlank() {
                return
        }
@@ -282,14 +282,15 @@ func NeedFuncSym(s *types.Sym) {
                // get funcsyms.
                return
        }
-       funcsyms = append(funcsyms, s)
+       funcsyms = append(funcsyms, fn.Nname)
 }
 
 func WriteFuncSyms() {
        sort.Slice(funcsyms, func(i, j int) bool {
                return funcsyms[i].Linksym().Name < funcsyms[j].Linksym().Name
        })
-       for _, s := range funcsyms {
+       for _, nam := range funcsyms {
+               s := nam.Sym()
                sf := s.Pkg.Lookup(ir.FuncSymName(s)).Linksym()
                objw.SymPtr(sf, 0, s.Linksym(), 0)
                objw.Global(sf, int32(types.PtrSize), obj.DUPOK|obj.RODATA)