mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.regabi] cmd/compile: remove types.InitSyms
It's not types's responsibility to understand how package initialization is implemented. Instead, have gc keep track of the order that packages were imported, and then look for inittask declarations. Also, use resolve to force importing of the inittask's export data, so that we can get the appropriate linker symbol index. (This is also why this CL doesn't satisfy "toolstash -cmp".) Change-Id: I5b706497d4a8d1c4439178863b4a8dba4da0f5a9 Reviewed-on: https://go-review.googlesource.com/c/go/+/274006 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
41ad4dec99
commit
0f9f27287b
3 changed files with 15 additions and 8 deletions
|
|
@ -27,6 +27,9 @@ func renameinit() *types.Sym {
|
|||
return s
|
||||
}
|
||||
|
||||
// List of imported packages, in source code order. See #31636.
|
||||
var sourceOrderImports []*types.Pkg
|
||||
|
||||
// fninit makes an initialization record for the package.
|
||||
// See runtime/proc.go:initTask for its layout.
|
||||
// The 3 tasks for initialization are:
|
||||
|
|
@ -40,8 +43,15 @@ func fninit(n []ir.Node) {
|
|||
var fns []*obj.LSym // functions to call for package initialization
|
||||
|
||||
// Find imported packages with init tasks.
|
||||
for _, s := range types.InitSyms {
|
||||
deps = append(deps, s.Linksym())
|
||||
for _, pkg := range sourceOrderImports {
|
||||
n := resolve(ir.AsNode(pkg.Lookup(".inittask").Def))
|
||||
if n == nil {
|
||||
continue
|
||||
}
|
||||
if n.Op() != ir.ONAME || n.Class() != ir.PEXTERN {
|
||||
base.Fatalf("bad inittask: %v", n)
|
||||
}
|
||||
deps = append(deps, n.Sym().Linksym())
|
||||
}
|
||||
|
||||
// Make a function that contains all the initialization statements.
|
||||
|
|
|
|||
|
|
@ -347,6 +347,9 @@ func (p *noder) importDecl(imp *syntax.ImportDecl) {
|
|||
p.importedEmbed = true
|
||||
}
|
||||
|
||||
if !ipkg.Direct {
|
||||
sourceOrderImports = append(sourceOrderImports, ipkg)
|
||||
}
|
||||
ipkg.Direct = true
|
||||
|
||||
var my *types.Sym
|
||||
|
|
|
|||
|
|
@ -84,9 +84,6 @@ func (pkg *Pkg) Lookup(name string) *Sym {
|
|||
return s
|
||||
}
|
||||
|
||||
// List of .inittask entries in imported packages, in source code order.
|
||||
var InitSyms []*Sym
|
||||
|
||||
// LookupOK looks up name in pkg and reports whether it previously existed.
|
||||
func (pkg *Pkg) LookupOK(name string) (s *Sym, existed bool) {
|
||||
// TODO(gri) remove this check in favor of specialized lookup
|
||||
|
|
@ -101,9 +98,6 @@ func (pkg *Pkg) LookupOK(name string) (s *Sym, existed bool) {
|
|||
Name: name,
|
||||
Pkg: pkg,
|
||||
}
|
||||
if name == ".inittask" {
|
||||
InitSyms = append(InitSyms, s)
|
||||
}
|
||||
pkg.Syms[name] = s
|
||||
return s, false
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue