]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: separate exportsym more cleanly
authorRuss Cox <rsc@golang.org>
Mon, 21 Dec 2020 14:11:12 +0000 (09:11 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 21 Dec 2020 19:23:29 +0000 (19:23 +0000)
Clean up a TODO (and make the package gc split easier)
by moving the exportsym walk out of iexport proper.

Also move exportsym call out of fninit.

Change-Id: Ie5887a68d325f7154201f4a35b9b4be4bf4b48dd
Reviewed-on: https://go-review.googlesource.com/c/go/+/279298
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/export.go
src/cmd/compile/internal/gc/iexport.go
src/cmd/compile/internal/gc/init.go
src/cmd/compile/internal/gc/main.go

index 42e0db2b206834c4747cfef9a2a54f58201301bf..d26dd9af5d2b8c27dbe9bd5dac283d21a85626a3 100644 (file)
@@ -60,6 +60,11 @@ func autoexport(n *ir.Name, ctxt ir.Class) {
 }
 
 func dumpexport(bout *bio.Writer) {
+       p := &exporter{marked: make(map[*types.Type]bool)}
+       for _, n := range Target.Exports {
+               p.markObject(n)
+       }
+
        // The linker also looks for the $$ marker - use char after $$ to distinguish format.
        exportf(bout, "\n$$B\n") // indicate binary export format
        off := bout.Offset()
index 969f6bc3b294f816526bf035a1f4f6a717abe854..c03445044df424bec80ac8767d1d6dcc90e24da7 100644 (file)
@@ -246,16 +246,6 @@ const (
 )
 
 func iexport(out *bufio.Writer) {
-       // Mark inline bodies that are reachable through exported objects.
-       // (Phase 0 of bexport.go.)
-       {
-               // TODO(mdempsky): Separate from bexport logic.
-               p := &exporter{marked: make(map[*types.Type]bool)}
-               for _, n := range Target.Exports {
-                       p.markObject(n)
-               }
-       }
-
        p := iexporter{
                allPkgs:     map[*types.Pkg]bool{},
                stringIndex: map[string]uint64{},
index f1398f8644fa208c23984562cee95dcdfcca64e2..1c15ce131838d9538c843266104f4aa354294371 100644 (file)
@@ -27,21 +27,21 @@ func renameinit() *types.Sym {
        return s
 }
 
-// fninit makes an initialization record for the package.
+// fninit makes and returns an initialization record for the package.
 // See runtime/proc.go:initTask for its layout.
 // The 3 tasks for initialization are:
 //   1) Initialize all of the packages the current package depends on.
 //   2) Initialize all the variables that have initializers.
 //   3) Run any init functions.
-func fninit(n []ir.Node) {
-       nf := initOrder(n)
+func fninit() *ir.Name {
+       nf := initOrder(Target.Decls)
 
        var deps []*obj.LSym // initTask records for packages the current package depends on
        var fns []*obj.LSym  // functions to call for package initialization
 
        // Find imported packages with init tasks.
        for _, pkg := range Target.Imports {
-               n := resolve(oldname(pkg.Lookup(".inittask")))
+               n := resolve(ir.NewIdent(base.Pos, pkg.Lookup(".inittask")))
                if n.Op() == ir.ONONAME {
                        continue
                }
@@ -92,16 +92,15 @@ func fninit(n []ir.Node) {
        }
 
        if len(deps) == 0 && len(fns) == 0 && types.LocalPkg.Name != "main" && types.LocalPkg.Name != "runtime" {
-               return // nothing to initialize
+               return nil // nothing to initialize
        }
 
        // Make an .inittask structure.
        sym := lookup(".inittask")
-       nn := NewName(sym)
-       nn.SetType(types.Types[types.TUINT8]) // fake type
-       nn.SetClass(ir.PEXTERN)
-       sym.Def = nn
-       exportsym(nn)
+       task := NewName(sym)
+       task.SetType(types.Types[types.TUINT8]) // fake type
+       task.SetClass(ir.PEXTERN)
+       sym.Def = task
        lsym := sym.Linksym()
        ot := 0
        ot = duintptr(lsym, ot, 0) // state: not initialized yet
@@ -116,4 +115,5 @@ func fninit(n []ir.Node) {
        // An initTask has pointers, but none into the Go heap.
        // It's not quite read only, the state field must be modifiable.
        ggloblsym(lsym, int32(ot), obj.NOPTR)
+       return task
 }
index 2c598a2329bf02cfbfccab3e32997cc4fef84779..545491daa1a671d4af3ce40221e9f4b79134eb1b 100644 (file)
@@ -306,7 +306,9 @@ func Main(archInit func(*Arch)) {
 
        timings.AddEvent(fcount, "funcs")
 
-       fninit(Target.Decls)
+       if initTask := fninit(); initTask != nil {
+               exportsym(initTask)
+       }
 
        // Phase 4: Decide how to capture closed variables.
        // This needs to run before escape analysis,