From: Josh Bleecher Snyder Date: Mon, 3 Apr 2017 14:50:56 +0000 (-0700) Subject: cmd/internal/obj: use string instead of LSym in Pcln X-Git-Tag: go1.9beta1~849 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=26308fb4813377def1391ad4ea383f9178c2d16a;p=gostls13.git cmd/internal/obj: use string instead of LSym in Pcln In a concurrent backend, Ctxt.Lookup will need some form of concurrency protection, which will make it more expensive. This CL changes the pcln table builder to track filenames as strings rather than LSyms. Those strings are then converted into LSyms at the last moment, for writing the object file. This CL removes over 85% of the calls to Ctxt.Lookup in a run of make.bash. Passes toolstash-check. Updates #15756 Change-Id: I3c53deff6f16f2643169f3bdfcc7aca2ca58b0a4 Reviewed-on: https://go-review.googlesource.com/39291 Run-TryBot: Josh Bleecher Snyder Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/cmd/internal/obj/line.go b/src/cmd/internal/obj/line.go index a601b00787..0fb915ba30 100644 --- a/src/cmd/internal/obj/line.go +++ b/src/cmd/internal/obj/line.go @@ -74,11 +74,11 @@ func (ctxt *Link) AddImport(pkg string) { ctxt.Imports = append(ctxt.Imports, pkg) } -func linkgetlineFromPos(ctxt *Link, xpos src.XPos) (f *LSym, l int32) { +func linkgetlineFromPos(ctxt *Link, xpos src.XPos) (f string, l int32) { pos := ctxt.PosTable.Pos(xpos) if !pos.IsKnown() { pos = src.Pos{} } // TODO(gri) Should this use relative or absolute line number? - return Linklookup(ctxt, pos.SymFilename(), 0), int32(pos.RelLine()) + return pos.SymFilename(), int32(pos.RelLine()) } diff --git a/src/cmd/internal/obj/line_test.go b/src/cmd/internal/obj/line_test.go index 63cc29587c..af595fd6a6 100644 --- a/src/cmd/internal/obj/line_test.go +++ b/src/cmd/internal/obj/line_test.go @@ -31,7 +31,7 @@ func TestLinkgetlineFromPos(t *testing.T) { for _, test := range tests { f, l := linkgetlineFromPos(ctxt, ctxt.PosTable.XPos(test.pos)) - got := fmt.Sprintf("%s:%d", f.Name, l) + got := fmt.Sprintf("%s:%d", f, l) if got != src.FileSymPrefix+test.want { t.Errorf("linkgetline(%v) = %q, want %q", test.pos, got, test.want) } diff --git a/src/cmd/internal/obj/link.go b/src/cmd/internal/obj/link.go index de12c1321f..648c7d98a7 100644 --- a/src/cmd/internal/obj/link.go +++ b/src/cmd/internal/obj/link.go @@ -401,8 +401,8 @@ type Pcln struct { Pcdata []Pcdata Funcdata []*LSym Funcdataoff []int64 - File []*LSym - Lastfile *LSym + File []string + Lastfile string Lastindex int InlTree InlTree // per-function inlining tree extracted from the global tree } diff --git a/src/cmd/internal/obj/objfile.go b/src/cmd/internal/obj/objfile.go index 5bef20ad37..ccc71efd6c 100644 --- a/src/cmd/internal/obj/objfile.go +++ b/src/cmd/internal/obj/objfile.go @@ -299,12 +299,14 @@ func (w *objWriter) writeRefs(s *LSym) { w.writeRef(d, false) } for _, f := range pc.File { - w.writeRef(f, true) + fsym := Linklookup(w.ctxt, f, 0) + w.writeRef(fsym, true) } for _, call := range pc.InlTree.nodes { w.writeRef(call.Func, false) f, _ := linkgetlineFromPos(w.ctxt, call.Pos) - w.writeRef(f, true) + fsym := Linklookup(w.ctxt, f, 0) + w.writeRef(fsym, true) } } } @@ -467,13 +469,15 @@ func (w *objWriter) writeSym(s *LSym) { } w.writeInt(int64(len(pc.File))) for _, f := range pc.File { - w.writeRefIndex(f) + fsym := Linklookup(ctxt, f, 0) + w.writeRefIndex(fsym) } w.writeInt(int64(len(pc.InlTree.nodes))) for _, call := range pc.InlTree.nodes { w.writeInt(int64(call.Parent)) f, l := linkgetlineFromPos(w.ctxt, call.Pos) - w.writeRefIndex(f) + fsym := Linklookup(ctxt, f, 0) + w.writeRefIndex(fsym) w.writeInt(int64(l)) w.writeRefIndex(call.Func) } diff --git a/src/cmd/internal/obj/pcln.go b/src/cmd/internal/obj/pcln.go index ca8d1b7484..04cef4fe56 100644 --- a/src/cmd/internal/obj/pcln.go +++ b/src/cmd/internal/obj/pcln.go @@ -131,11 +131,6 @@ func pctofileline(ctxt *Link, sym *LSym, oldval int32, p *Prog, phase int32, arg return oldval } f, l := linkgetlineFromPos(ctxt, p.Pos) - if f == nil { - // print("getline failed for %s %v\n", ctxt->cursym->name, p); - return oldval - } - if arg == nil { return l }