1
0
mirror of https://github.com/golang/go synced 2024-11-26 22:41:23 -07:00

cmd/compile: track funcsyms by ir.Name instead of types.Sym

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>
This commit is contained in:
Austin Clements 2021-03-24 14:28:18 -04:00
parent 2ba296da47
commit 33b4ffc357
2 changed files with 19 additions and 18 deletions

View File

@ -143,7 +143,7 @@ func InitLSym(f *ir.Func, hasBody bool) {
if f.LSym != nil && objabi.Experiment.RegabiWrappers { if f.LSym != nil && objabi.Experiment.RegabiWrappers {
return return
} }
staticdata.NeedFuncSym(f.Sym()) staticdata.NeedFuncSym(f)
selectLSym(f, hasBody) selectLSym(f, hasBody)
if hasBody { if hasBody {
setupTextLSym(f, 0) setupTextLSym(f, 0)

View File

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