Skip to content

Commit cd5b74d

Browse files
committed
[dev.regabi] cmd/compile: call NeedFuncSym in InitLSym
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 <[email protected]> TryBot-Result: Go Bot <[email protected]> Trust: Matthew Dempsky <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 95acd81 commit cd5b74d

File tree

5 files changed

+12
-19
lines changed

5 files changed

+12
-19
lines changed

src/cmd/compile/internal/gc/main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"cmd/compile/internal/reflectdata"
2121
"cmd/compile/internal/ssa"
2222
"cmd/compile/internal/ssagen"
23-
"cmd/compile/internal/staticdata"
2423
"cmd/compile/internal/typecheck"
2524
"cmd/compile/internal/types"
2625
"cmd/compile/internal/walk"
@@ -194,7 +193,6 @@ func Main(archInit func(*ssagen.ArchInfo)) {
194193

195194
typecheck.Target = new(ir.Package)
196195

197-
typecheck.NeedFuncSym = staticdata.NeedFuncSym
198196
typecheck.NeedITab = func(t, iface *types.Type) { reflectdata.ITabAddr(t, iface) }
199197
typecheck.NeedRuntimeType = reflectdata.NeedRuntimeType // TODO(rsc): typenamesym for lock?
200198

src/cmd/compile/internal/ssagen/abi.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"cmd/compile/internal/base"
1515
"cmd/compile/internal/escape"
1616
"cmd/compile/internal/ir"
17+
"cmd/compile/internal/staticdata"
1718
"cmd/compile/internal/typecheck"
1819
"cmd/compile/internal/types"
1920
"cmd/internal/obj"
@@ -137,6 +138,8 @@ func ReadSymABIs(file, myimportpath string) {
137138
// For body-less functions, we only create the LSym; for functions
138139
// with bodies call a helper to setup up / populate the LSym.
139140
func InitLSym(f *ir.Func, hasBody bool) {
141+
staticdata.NeedFuncSym(f.Sym())
142+
140143
// FIXME: for new-style ABI wrappers, we set up the lsym at the
141144
// point the wrapper is created.
142145
if f.LSym != nil && base.Flag.ABIWrap {
@@ -152,7 +155,7 @@ func InitLSym(f *ir.Func, hasBody bool) {
152155
// makes calls to helpers to create ABI wrappers if needed.
153156
func selectLSym(f *ir.Func, hasBody bool) {
154157
if f.LSym != nil {
155-
base.Fatalf("Func.initLSym called twice")
158+
base.FatalfAt(f.Pos(), "Func.initLSym called twice on %v", f)
156159
}
157160

158161
if nam := f.Nname; !ir.IsBlank(nam) {

src/cmd/compile/internal/staticdata/data.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func FuncLinksym(n *ir.Name) *obj.LSym {
265265
return FuncSym(n.Sym()).Linksym()
266266
}
267267

268-
// NeedFuncSym ensures that s·f is exported.
268+
// NeedFuncSym ensures that s·f is exported, if needed.
269269
// It is only used with -dynlink.
270270
// When not compiling for dynamic linking,
271271
// the funcsyms are created as needed by
@@ -275,8 +275,13 @@ func FuncLinksym(n *ir.Name) *obj.LSym {
275275
// So instead, when dynamic linking, we only create
276276
// the s·f stubs in s's package.
277277
func NeedFuncSym(s *types.Sym) {
278+
if base.Ctxt.InParallel {
279+
// The append below probably just needs to lock
280+
// funcsymsmu, like in FuncSym.
281+
base.Fatalf("NeedFuncSym must be called in serial")
282+
}
278283
if !base.Ctxt.Flag_dynlink {
279-
base.Fatalf("NeedFuncSym: dynlink")
284+
return
280285
}
281286
if s.IsBlank() {
282287
return
@@ -287,9 +292,7 @@ func NeedFuncSym(s *types.Sym) {
287292
// get funcsyms.
288293
return
289294
}
290-
if _, existed := s.Pkg.LookupOK(ir.FuncSymName(s)); !existed {
291-
funcsyms = append(funcsyms, s)
292-
}
295+
funcsyms = append(funcsyms, s)
293296
}
294297

295298
func WriteFuncSyms() {

src/cmd/compile/internal/typecheck/func.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,6 @@ func tcFunc(n *ir.Func) {
364364
n.Nname.SetSym(ir.MethodSym(rcvr.Type, n.Shortname))
365365
Declare(n.Nname, ir.PFUNC)
366366
}
367-
368-
if base.Ctxt.Flag_dynlink && !inimport && n.Nname != nil {
369-
NeedFuncSym(n.Sym())
370-
}
371367
}
372368

373369
// tcCall typechecks an OCALL node.

src/cmd/compile/internal/typecheck/typecheck.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ var inimport bool // set during import
2424
var TypecheckAllowed bool
2525

2626
var (
27-
NeedFuncSym = func(*types.Sym) {}
2827
NeedITab = func(t, itype *types.Type) {}
2928
NeedRuntimeType = func(*types.Type) {}
3029
)
@@ -1140,12 +1139,6 @@ func typecheckMethodExpr(n *ir.SelectorExpr) (res ir.Node) {
11401139
n.SetOp(ir.OMETHEXPR)
11411140
n.Selection = m
11421141
n.SetType(NewMethodType(m.Type, n.X.Type()))
1143-
1144-
// Issue 25065. Make sure that we emit the symbol for a local method.
1145-
if base.Ctxt.Flag_dynlink && !inimport && (t.Sym() == nil || t.Sym().Pkg == types.LocalPkg) {
1146-
NeedFuncSym(n.FuncName().Sym())
1147-
}
1148-
11491142
return n
11501143
}
11511144

0 commit comments

Comments
 (0)