From 85ce6ecfe3c54075c7bc53538940f0319b57068b Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 21 Dec 2020 09:11:12 -0500 Subject: [PATCH] [dev.regabi] cmd/compile: separate exportsym more cleanly 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 Run-TryBot: Russ Cox TryBot-Result: Go Bot Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/export.go | 5 +++++ src/cmd/compile/internal/gc/iexport.go | 10 ---------- src/cmd/compile/internal/gc/init.go | 20 ++++++++++---------- src/cmd/compile/internal/gc/main.go | 4 +++- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/cmd/compile/internal/gc/export.go b/src/cmd/compile/internal/gc/export.go index 42e0db2b20..d26dd9af5d 100644 --- a/src/cmd/compile/internal/gc/export.go +++ b/src/cmd/compile/internal/gc/export.go @@ -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() diff --git a/src/cmd/compile/internal/gc/iexport.go b/src/cmd/compile/internal/gc/iexport.go index 969f6bc3b2..c03445044d 100644 --- a/src/cmd/compile/internal/gc/iexport.go +++ b/src/cmd/compile/internal/gc/iexport.go @@ -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{}, diff --git a/src/cmd/compile/internal/gc/init.go b/src/cmd/compile/internal/gc/init.go index f1398f8644..1c15ce1318 100644 --- a/src/cmd/compile/internal/gc/init.go +++ b/src/cmd/compile/internal/gc/init.go @@ -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 } diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go index 2c598a2329..545491daa1 100644 --- a/src/cmd/compile/internal/gc/main.go +++ b/src/cmd/compile/internal/gc/main.go @@ -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, -- 2.50.0