]> Cypherpunks.ru repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: remove types.InitSyms
authorMatthew Dempsky <mdempsky@google.com>
Mon, 30 Nov 2020 08:01:26 +0000 (00:01 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 1 Dec 2020 01:26:28 +0000 (01:26 +0000)
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>
src/cmd/compile/internal/gc/init.go
src/cmd/compile/internal/gc/noder.go
src/cmd/compile/internal/types/pkg.go

index ed0218c0e2363730ea5b9d7fe017d2d564aab567..b5fd2e7c758d20838765a7f9064247ed72b074ec 100644 (file)
@@ -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.
index 98a09f40069a3fab61eef322ff94eed03d5b07a2..6a5afe7687f00936d858cc64ed2e6640bf2ff6b4 100644 (file)
@@ -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
index bcc67895095812f79dd3482684f3c80bb0c28894..bf90570b537b35dbe7be32b2a864fb7b1591870b 100644 (file)
@@ -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
 }