Commit 26308fb4 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

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 <josharian@gmail.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 719c7b03
...@@ -74,11 +74,11 @@ func (ctxt *Link) AddImport(pkg string) { ...@@ -74,11 +74,11 @@ func (ctxt *Link) AddImport(pkg string) {
ctxt.Imports = append(ctxt.Imports, pkg) 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) pos := ctxt.PosTable.Pos(xpos)
if !pos.IsKnown() { if !pos.IsKnown() {
pos = src.Pos{} pos = src.Pos{}
} }
// TODO(gri) Should this use relative or absolute line number? // 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())
} }
...@@ -31,7 +31,7 @@ func TestLinkgetlineFromPos(t *testing.T) { ...@@ -31,7 +31,7 @@ func TestLinkgetlineFromPos(t *testing.T) {
for _, test := range tests { for _, test := range tests {
f, l := linkgetlineFromPos(ctxt, ctxt.PosTable.XPos(test.pos)) 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 { if got != src.FileSymPrefix+test.want {
t.Errorf("linkgetline(%v) = %q, want %q", test.pos, got, test.want) t.Errorf("linkgetline(%v) = %q, want %q", test.pos, got, test.want)
} }
......
...@@ -401,8 +401,8 @@ type Pcln struct { ...@@ -401,8 +401,8 @@ type Pcln struct {
Pcdata []Pcdata Pcdata []Pcdata
Funcdata []*LSym Funcdata []*LSym
Funcdataoff []int64 Funcdataoff []int64
File []*LSym File []string
Lastfile *LSym Lastfile string
Lastindex int Lastindex int
InlTree InlTree // per-function inlining tree extracted from the global tree InlTree InlTree // per-function inlining tree extracted from the global tree
} }
......
...@@ -299,12 +299,14 @@ func (w *objWriter) writeRefs(s *LSym) { ...@@ -299,12 +299,14 @@ func (w *objWriter) writeRefs(s *LSym) {
w.writeRef(d, false) w.writeRef(d, false)
} }
for _, f := range pc.File { 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 { for _, call := range pc.InlTree.nodes {
w.writeRef(call.Func, false) w.writeRef(call.Func, false)
f, _ := linkgetlineFromPos(w.ctxt, call.Pos) 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) { ...@@ -467,13 +469,15 @@ func (w *objWriter) writeSym(s *LSym) {
} }
w.writeInt(int64(len(pc.File))) w.writeInt(int64(len(pc.File)))
for _, f := range 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))) w.writeInt(int64(len(pc.InlTree.nodes)))
for _, call := range pc.InlTree.nodes { for _, call := range pc.InlTree.nodes {
w.writeInt(int64(call.Parent)) w.writeInt(int64(call.Parent))
f, l := linkgetlineFromPos(w.ctxt, call.Pos) f, l := linkgetlineFromPos(w.ctxt, call.Pos)
w.writeRefIndex(f) fsym := Linklookup(ctxt, f, 0)
w.writeRefIndex(fsym)
w.writeInt(int64(l)) w.writeInt(int64(l))
w.writeRefIndex(call.Func) w.writeRefIndex(call.Func)
} }
......
...@@ -131,11 +131,6 @@ func pctofileline(ctxt *Link, sym *LSym, oldval int32, p *Prog, phase int32, arg ...@@ -131,11 +131,6 @@ func pctofileline(ctxt *Link, sym *LSym, oldval int32, p *Prog, phase int32, arg
return oldval return oldval
} }
f, l := linkgetlineFromPos(ctxt, p.Pos) 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 { if arg == nil {
return l return l
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment