Skip to content

Commit 26308fb

Browse files
committed
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 <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 719c7b0 commit 26308fb

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

src/cmd/internal/obj/line.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ func (ctxt *Link) AddImport(pkg string) {
7474
ctxt.Imports = append(ctxt.Imports, pkg)
7575
}
7676

77-
func linkgetlineFromPos(ctxt *Link, xpos src.XPos) (f *LSym, l int32) {
77+
func linkgetlineFromPos(ctxt *Link, xpos src.XPos) (f string, l int32) {
7878
pos := ctxt.PosTable.Pos(xpos)
7979
if !pos.IsKnown() {
8080
pos = src.Pos{}
8181
}
8282
// TODO(gri) Should this use relative or absolute line number?
83-
return Linklookup(ctxt, pos.SymFilename(), 0), int32(pos.RelLine())
83+
return pos.SymFilename(), int32(pos.RelLine())
8484
}

src/cmd/internal/obj/line_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestLinkgetlineFromPos(t *testing.T) {
3131

3232
for _, test := range tests {
3333
f, l := linkgetlineFromPos(ctxt, ctxt.PosTable.XPos(test.pos))
34-
got := fmt.Sprintf("%s:%d", f.Name, l)
34+
got := fmt.Sprintf("%s:%d", f, l)
3535
if got != src.FileSymPrefix+test.want {
3636
t.Errorf("linkgetline(%v) = %q, want %q", test.pos, got, test.want)
3737
}

src/cmd/internal/obj/link.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,8 @@ type Pcln struct {
401401
Pcdata []Pcdata
402402
Funcdata []*LSym
403403
Funcdataoff []int64
404-
File []*LSym
405-
Lastfile *LSym
404+
File []string
405+
Lastfile string
406406
Lastindex int
407407
InlTree InlTree // per-function inlining tree extracted from the global tree
408408
}

src/cmd/internal/obj/objfile.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,14 @@ func (w *objWriter) writeRefs(s *LSym) {
299299
w.writeRef(d, false)
300300
}
301301
for _, f := range pc.File {
302-
w.writeRef(f, true)
302+
fsym := Linklookup(w.ctxt, f, 0)
303+
w.writeRef(fsym, true)
303304
}
304305
for _, call := range pc.InlTree.nodes {
305306
w.writeRef(call.Func, false)
306307
f, _ := linkgetlineFromPos(w.ctxt, call.Pos)
307-
w.writeRef(f, true)
308+
fsym := Linklookup(w.ctxt, f, 0)
309+
w.writeRef(fsym, true)
308310
}
309311
}
310312
}
@@ -467,13 +469,15 @@ func (w *objWriter) writeSym(s *LSym) {
467469
}
468470
w.writeInt(int64(len(pc.File)))
469471
for _, f := range pc.File {
470-
w.writeRefIndex(f)
472+
fsym := Linklookup(ctxt, f, 0)
473+
w.writeRefIndex(fsym)
471474
}
472475
w.writeInt(int64(len(pc.InlTree.nodes)))
473476
for _, call := range pc.InlTree.nodes {
474477
w.writeInt(int64(call.Parent))
475478
f, l := linkgetlineFromPos(w.ctxt, call.Pos)
476-
w.writeRefIndex(f)
479+
fsym := Linklookup(ctxt, f, 0)
480+
w.writeRefIndex(fsym)
477481
w.writeInt(int64(l))
478482
w.writeRefIndex(call.Func)
479483
}

src/cmd/internal/obj/pcln.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,6 @@ func pctofileline(ctxt *Link, sym *LSym, oldval int32, p *Prog, phase int32, arg
131131
return oldval
132132
}
133133
f, l := linkgetlineFromPos(ctxt, p.Pos)
134-
if f == nil {
135-
// print("getline failed for %s %v\n", ctxt->cursym->name, p);
136-
return oldval
137-
}
138-
139134
if arg == nil {
140135
return l
141136
}

0 commit comments

Comments
 (0)