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.
// 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 {
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.
if !base.Ctxt.Flag_dynlink {
return
}
+ s := fn.Nname.Sym()
if s.IsBlank() {
return
}
// 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)