From dd2ba0c7a78d333da340bcf00995162252febad7 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Mon, 14 Mar 2016 21:51:09 -0700 Subject: [PATCH] cmd/internal/obj: remove LSym.Next Instead, use a slice. Passes toolstash -cmp. Change-Id: I889fdb4ae997416f907522f549b96506be13bec7 Reviewed-on: https://go-review.googlesource.com/20699 Reviewed-by: Brad Fitzpatrick Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot --- src/cmd/internal/obj/link.go | 7 ++--- src/cmd/internal/obj/objfile.go | 40 ++++++++--------------------- src/cmd/internal/obj/sizeof_test.go | 2 +- 3 files changed, 14 insertions(+), 35 deletions(-) diff --git a/src/cmd/internal/obj/link.go b/src/cmd/internal/obj/link.go index 2e305478eb..835890d601 100644 --- a/src/cmd/internal/obj/link.go +++ b/src/cmd/internal/obj/link.go @@ -334,7 +334,6 @@ type LSym struct { Args int32 Locals int32 Size int64 - Next *LSym Gotype *LSym Autom *Auto Text *Prog @@ -652,10 +651,8 @@ type Link struct { RefsWritten int // Number of symbol references already written to object file. // state for writing objects - Text *LSym - Data *LSym - Etext *LSym - Edata *LSym + Text []*LSym + Data []*LSym // Cache of Progs allocIdx int diff --git a/src/cmd/internal/obj/objfile.go b/src/cmd/internal/obj/objfile.go index dc64dad6cd..70c2d9d5f9 100644 --- a/src/cmd/internal/obj/objfile.go +++ b/src/cmd/internal/obj/objfile.go @@ -130,7 +130,8 @@ func flushplist(ctxt *Link, freeProgs bool) { // Build list of symbols, and assign instructions to lists. // Ignore ctxt->plist boundaries. There are no guarantees there, // and the assemblers just use one big list. - var curtext, text, etext *LSym + var curtext *LSym + var text []*LSym for pl := ctxt.Plist; pl != nil; pl = pl.Link { var plink *Prog @@ -180,12 +181,7 @@ func flushplist(ctxt *Link, freeProgs bool) { log.Fatalf("symbol %s listed multiple times", s.Name) } s.Onlist = 1 - if ctxt.Data == nil { - ctxt.Data = s - } else { - ctxt.Edata.Next = s - } - s.Next = nil + ctxt.Data = append(ctxt.Data, s) s.Size = p.To.Offset if s.Type == 0 || s.Type == SXREF { s.Type = SBSS @@ -201,7 +197,6 @@ func flushplist(ctxt *Link, freeProgs bool) { } else if flag&TLSBSS != 0 { s.Type = STLSBSS } - ctxt.Edata = s continue case ATEXT: @@ -220,12 +215,7 @@ func flushplist(ctxt *Link, freeProgs bool) { log.Fatalf("symbol %s listed multiple times", s.Name) } s.Onlist = 1 - if text == nil { - text = s - } else { - etext.Next = s - } - etext = s + text = append(text, s) flag := int(p.From3Offset()) if flag&DUPOK != 0 { s.Dupok = 1 @@ -236,7 +226,6 @@ func flushplist(ctxt *Link, freeProgs bool) { if flag&REFLECTMETHOD != 0 { s.ReflectMethod = true } - s.Next = nil s.Type = STEXT s.Text = p s.Etext = p @@ -267,7 +256,7 @@ func flushplist(ctxt *Link, freeProgs bool) { } // Add reference to Go arguments for C or assembly functions without them. - for s := text; s != nil; s = s.Next { + for _, s := range text { if !strings.HasPrefix(s.Name, "\"\".") { continue } @@ -292,7 +281,7 @@ func flushplist(ctxt *Link, freeProgs bool) { } // Turn functions into machine code images. - for s := text; s != nil; s = s.Next { + for _, s := range text { mkfwd(s) linkpatch(ctxt, s) if ctxt.Flag_optimize { @@ -309,14 +298,7 @@ func flushplist(ctxt *Link, freeProgs bool) { } // Add to running list in ctxt. - if text != nil { - if ctxt.Text == nil { - ctxt.Text = text - } else { - ctxt.Etext.Next = text - } - ctxt.Etext = etext - } + ctxt.Text = append(ctxt.Text, text...) ctxt.Plist = nil ctxt.Plast = nil ctxt.Curp = nil @@ -340,19 +322,19 @@ func Writeobjfile(ctxt *Link, b *Biobuf) { wrstring(b, "") // Emit symbol references. - for s := ctxt.Text; s != nil; s = s.Next { + for _, s := range ctxt.Text { writerefs(ctxt, b, s) } - for s := ctxt.Data; s != nil; s = s.Next { + for _, s := range ctxt.Data { writerefs(ctxt, b, s) } Bputc(b, 0xff) // Emit symbols. - for s := ctxt.Text; s != nil; s = s.Next { + for _, s := range ctxt.Text { writesym(ctxt, b, s) } - for s := ctxt.Data; s != nil; s = s.Next { + for _, s := range ctxt.Data { writesym(ctxt, b, s) } diff --git a/src/cmd/internal/obj/sizeof_test.go b/src/cmd/internal/obj/sizeof_test.go index 1c72a1e22a..28dbba888d 100644 --- a/src/cmd/internal/obj/sizeof_test.go +++ b/src/cmd/internal/obj/sizeof_test.go @@ -23,7 +23,7 @@ func TestSizeof(t *testing.T) { _64bit uintptr // size on 64bit platforms }{ {Addr{}, 52, 80}, - {LSym{}, 92, 160}, + {LSym{}, 88, 152}, {Prog{}, 196, 288}, } -- 2.48.1