From ed03dab85384c156d7c222890ca13d1af3f69b4b Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 5 Jan 2016 09:27:40 -0500 Subject: [PATCH] cmd/internal/obj: separate code layout from object writing This will allow the compiler to crunch Prog lists down to code as each function is compiled, instead of waiting until the end, which should reduce the working set of the compiler. But not until Go 1.7. This also makes it easier to write some machine code output tests for the assembler, which is why it's being done now. For #13822. Change-Id: I0811123bc6e5717cebb8948f9cea18e1b9baf6f7 Reviewed-on: https://go-review.googlesource.com/18311 Reviewed-by: Ian Lance Taylor --- src/cmd/internal/obj/link.go | 6 ++++++ src/cmd/internal/obj/objfile.go | 36 +++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/cmd/internal/obj/link.go b/src/cmd/internal/obj/link.go index f7f7662ee7..bc898235c1 100644 --- a/src/cmd/internal/obj/link.go +++ b/src/cmd/internal/obj/link.go @@ -610,6 +610,12 @@ type Link struct { Version int Textp *LSym Etextp *LSym + + // state for writing objects + Text *LSym + Data *LSym + Etext *LSym + Edata *LSym } // The smallest possible offset from the hardware stack pointer to a local diff --git a/src/cmd/internal/obj/objfile.go b/src/cmd/internal/obj/objfile.go index 13930aa6c9..8d4a506843 100644 --- a/src/cmd/internal/obj/objfile.go +++ b/src/cmd/internal/obj/objfile.go @@ -111,6 +111,11 @@ import ( // out a Go object file. The linker does not call this; the linker // does not write out object files. func Writeobjdirect(ctxt *Link, b *Biobuf) { + Flushplist(ctxt) + Writeobjfile(ctxt, b) +} + +func Flushplist(ctxt *Link) { var flag int var s *LSym var p *Prog @@ -119,13 +124,11 @@ func Writeobjdirect(ctxt *Link, b *Biobuf) { // Build list of symbols, and assign instructions to lists. // Ignore ctxt->plist boundaries. There are no guarantees there, - // and the C compilers and assemblers just use one big list. - var text *LSym - + // and the assemblers just use one big list. var curtext *LSym - var data *LSym + var text *LSym var etext *LSym - var edata *LSym + for pl := ctxt.Plist; pl != nil; pl = pl.Link { for p = pl.Firstpc; p != nil; p = plink { if ctxt.Debugasm != 0 && ctxt.Debugvlog != 0 { @@ -174,10 +177,10 @@ func Writeobjdirect(ctxt *Link, b *Biobuf) { log.Fatalf("symbol %s listed multiple times", s.Name) } s.Onlist = 1 - if data == nil { - data = s + if ctxt.Data == nil { + ctxt.Data = s } else { - edata.Next = s + ctxt.Edata.Next = s } s.Next = nil s.Size = p.To.Offset @@ -195,7 +198,7 @@ func Writeobjdirect(ctxt *Link, b *Biobuf) { } else if flag&TLSBSS != 0 { s.Type = STLSBSS } - edata = s + ctxt.Edata = s continue } @@ -298,6 +301,17 @@ func Writeobjdirect(ctxt *Link, b *Biobuf) { linkpcln(ctxt, s) } + // Add to running list in ctxt. + if ctxt.Etext == nil { + ctxt.Text = text + } else { + ctxt.Etext.Next = text + } + ctxt.Etext = etext + ctxt.Plist = nil +} + +func Writeobjfile(ctxt *Link, b *Biobuf) { // Emit header. Bputc(b, 0) @@ -312,10 +326,10 @@ func Writeobjdirect(ctxt *Link, b *Biobuf) { wrstring(b, "") // Emit symbols. - for s := text; s != nil; s = s.Next { + for s := ctxt.Text; s != nil; s = s.Next { writesym(ctxt, b, s) } - for s := data; s != nil; s = s.Next { + for s := ctxt.Data; s != nil; s = s.Next { writesym(ctxt, b, s) } -- 2.48.1