Skip to content

Commit ac7761e

Browse files
committed
cmd/compile, cmd/asm: remove Link.Plists
Link.Plists never contained more than one Plist, and sometimes none. Passing around the Plist being worked on is straightforward and makes the data flow easier to follow. Change-Id: I79cb30cb2bd3d319fdbb1dfa5d35b27fcb748e5c Reviewed-on: https://go-review.googlesource.com/37169 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent ac4a865 commit ac7761e

File tree

9 files changed

+74
-108
lines changed

9 files changed

+74
-108
lines changed

src/cmd/asm/internal/asm/endtoend_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func testEndToEnd(t *testing.T, goarch, file string) {
3030
architecture, ctxt := setArch(goarch)
3131
lexer := lex.NewLexer(input)
3232
parser := NewParser(ctxt, architecture, lexer)
33-
pList := obj.Linknewplist(ctxt)
33+
pList := new(obj.Plist)
3434
var ok bool
3535
testOut = new(bytes.Buffer) // The assembler writes test output to this buffer.
3636
ctxt.Bso = bufio.NewWriter(os.Stdout)
@@ -179,7 +179,7 @@ Diff:
179179
t.Errorf(format, args...)
180180
ok = false
181181
}
182-
obj.FlushplistNoFree(ctxt)
182+
obj.FlushplistNoFree(ctxt, pList)
183183

184184
for p := top; p != nil; p = p.Link {
185185
if p.As == obj.ATEXT {
@@ -267,7 +267,7 @@ func testErrors(t *testing.T, goarch, file string) {
267267
architecture, ctxt := setArch(goarch)
268268
lexer := lex.NewLexer(input)
269269
parser := NewParser(ctxt, architecture, lexer)
270-
pList := obj.Linknewplist(ctxt)
270+
pList := new(obj.Plist)
271271
var ok bool
272272
testOut = new(bytes.Buffer) // The assembler writes test output to this buffer.
273273
ctxt.Bso = bufio.NewWriter(os.Stdout)
@@ -283,7 +283,7 @@ func testErrors(t *testing.T, goarch, file string) {
283283
errBuf.WriteString(s)
284284
}
285285
pList.Firstpc, ok = parser.Parse()
286-
obj.Flushplist(ctxt)
286+
obj.Flushplist(ctxt, pList)
287287
if ok && !failed {
288288
t.Errorf("asm: %s had no errors", goarch)
289289
}

src/cmd/asm/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,17 @@ func main() {
6262
diag = true
6363
log.Printf(format, args...)
6464
}
65-
pList := obj.Linknewplist(ctxt)
65+
pList := new(obj.Plist)
6666
pList.Firstpc, ok = parser.Parse()
6767
if !ok {
6868
failedFile = f
6969
break
7070
}
71+
// reports errors to parser.Errorf
72+
obj.Flushplist(ctxt, pList)
7173
}
7274
if ok {
73-
// reports errors to parser.Errorf
74-
obj.Writeobjdirect(ctxt, buf)
75+
obj.WriteObjFile(ctxt, buf)
7576
}
7677
if !ok || diag {
7778
if failedFile != "" {

src/cmd/compile/internal/gc/dcl.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package gc
66

77
import (
8-
"cmd/internal/obj"
98
"cmd/internal/src"
109
"fmt"
1110
"sort"
@@ -1228,11 +1227,6 @@ func funccompile(n *Node) {
12281227
pc = nil
12291228
funcdepth = 0
12301229
dclcontext = PEXTERN
1231-
if nerrors != 0 {
1232-
// If we have compile errors, ignore any assembler/linker errors.
1233-
Ctxt.DiagFunc = func(string, ...interface{}) {}
1234-
}
1235-
obj.Flushplist(Ctxt) // convert from Prog list to machine code
12361230
}
12371231

12381232
func funcsym(s *Sym) *Sym {

src/cmd/compile/internal/gc/gsubr.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,6 @@ func Addrconst(a *obj.Addr, v int64) {
161161
a.Offset = v
162162
}
163163

164-
func newplist() *obj.Plist {
165-
pl := obj.Linknewplist(Ctxt)
166-
167-
pc = Ctxt.NewProg()
168-
Clearp(pc)
169-
pl.Firstpc = pc
170-
171-
return pl
172-
}
173-
174164
// nodarg returns a Node for the function argument denoted by t,
175165
// which is either the entire function argument or result struct (t is a struct *Type)
176166
// or a specific argument (t is a *Field within a struct *Type).

src/cmd/compile/internal/gc/obj.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func dumpobj1(outfile string, mode int) {
151151
ggloblsym(zero, int32(zerosize), obj.DUPOK|obj.RODATA)
152152
}
153153

154-
obj.Writeobjdirect(Ctxt, bout.Writer)
154+
obj.WriteObjFile(Ctxt, bout.Writer)
155155

156156
if writearchive {
157157
bout.Flush()

src/cmd/compile/internal/gc/pgen.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,10 @@ func compile(fn *Node) {
368368
return
369369
}
370370

371-
newplist()
371+
plist := new(obj.Plist)
372+
pc = Ctxt.NewProg()
373+
Clearp(pc)
374+
plist.Firstpc = pc
372375

373376
setlineno(Curfn)
374377

@@ -430,6 +433,7 @@ func compile(fn *Node) {
430433

431434
genssa(ssafn, ptxt, gcargs, gclocals)
432435
ssafn.Free()
436+
obj.Flushplist(Ctxt, plist) // convert from Prog list to machine code
433437
}
434438

435439
func gendebug(fn *obj.LSym, decls []*Node) {

src/cmd/internal/obj/link.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,6 @@ type Link struct {
729729
Hash map[SymVer]*LSym
730730
PosTable src.PosTable
731731
Imports []string
732-
Plists []*Plist
733732
Sym_div *LSym
734733
Sym_divu *LSym
735734
Sym_mod *LSym

src/cmd/internal/obj/objfile.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,6 @@ import (
119119
"sort"
120120
)
121121

122-
// The Go and C compilers, and the assembler, call writeobj to write
123-
// out a Go object file. The linker does not call this; the linker
124-
// does not write out object files.
125-
func Writeobjdirect(ctxt *Link, b *bufio.Writer) {
126-
Flushplist(ctxt)
127-
WriteObjFile(ctxt, b)
128-
}
129-
130122
// objWriter writes Go object files.
131123
type objWriter struct {
132124
wr *bufio.Writer

src/cmd/internal/obj/plist.go

Lines changed: 60 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -14,96 +14,83 @@ type Plist struct {
1414
Firstpc *Prog
1515
}
1616

17-
/*
18-
* start a new Prog list.
19-
*/
20-
func Linknewplist(ctxt *Link) *Plist {
21-
pl := new(Plist)
22-
ctxt.Plists = append(ctxt.Plists, pl)
23-
return pl
17+
func Flushplist(ctxt *Link, plist *Plist) {
18+
flushplist(ctxt, plist, ctxt.Debugasm == 0)
2419
}
25-
26-
func Flushplist(ctxt *Link) {
27-
flushplist(ctxt, ctxt.Debugasm == 0)
28-
}
29-
func FlushplistNoFree(ctxt *Link) {
30-
flushplist(ctxt, false)
20+
func FlushplistNoFree(ctxt *Link, plist *Plist) {
21+
flushplist(ctxt, plist, false)
3122
}
32-
func flushplist(ctxt *Link, freeProgs bool) {
23+
func flushplist(ctxt *Link, plist *Plist, freeProgs bool) {
3324
// Build list of symbols, and assign instructions to lists.
34-
// Ignore ctxt->plist boundaries. There are no guarantees there,
35-
// and the assemblers just use one big list.
3625
var curtext *LSym
3726
var etext *Prog
3827
var text []*LSym
3928

40-
for _, pl := range ctxt.Plists {
41-
var plink *Prog
42-
for p := pl.Firstpc; p != nil; p = plink {
43-
if ctxt.Debugasm != 0 && ctxt.Debugvlog != 0 {
44-
fmt.Printf("obj: %v\n", p)
45-
}
46-
plink = p.Link
47-
p.Link = nil
48-
49-
switch p.As {
50-
case AEND:
51-
continue
29+
var plink *Prog
30+
for p := plist.Firstpc; p != nil; p = plink {
31+
if ctxt.Debugasm != 0 && ctxt.Debugvlog != 0 {
32+
fmt.Printf("obj: %v\n", p)
33+
}
34+
plink = p.Link
35+
p.Link = nil
5236

53-
case ATEXT:
54-
s := p.From.Sym
55-
if s == nil {
56-
// func _() { }
57-
curtext = nil
37+
switch p.As {
38+
case AEND:
39+
continue
5840

59-
continue
60-
}
41+
case ATEXT:
42+
s := p.From.Sym
43+
if s == nil {
44+
// func _() { }
45+
curtext = nil
6146

62-
if s.Text != nil {
63-
log.Fatalf("duplicate TEXT for %s", s.Name)
64-
}
65-
if s.OnList() {
66-
log.Fatalf("symbol %s listed multiple times", s.Name)
67-
}
68-
s.Set(AttrOnList, true)
69-
text = append(text, s)
70-
flag := int(p.From3Offset())
71-
if flag&DUPOK != 0 {
72-
s.Set(AttrDuplicateOK, true)
73-
}
74-
if flag&NOSPLIT != 0 {
75-
s.Set(AttrNoSplit, true)
76-
}
77-
if flag&REFLECTMETHOD != 0 {
78-
s.Set(AttrReflectMethod, true)
79-
}
80-
s.Type = STEXT
81-
s.Text = p
82-
etext = p
83-
curtext = s
8447
continue
48+
}
8549

86-
case AFUNCDATA:
87-
// Rewrite reference to go_args_stackmap(SB) to the Go-provided declaration information.
88-
if curtext == nil { // func _() {}
89-
continue
90-
}
91-
if p.To.Sym.Name == "go_args_stackmap" {
92-
if p.From.Type != TYPE_CONST || p.From.Offset != FUNCDATA_ArgsPointerMaps {
93-
ctxt.Diag("FUNCDATA use of go_args_stackmap(SB) without FUNCDATA_ArgsPointerMaps")
94-
}
95-
p.To.Sym = Linklookup(ctxt, fmt.Sprintf("%s.args_stackmap", curtext.Name), int(curtext.Version))
96-
}
97-
50+
if s.Text != nil {
51+
log.Fatalf("duplicate TEXT for %s", s.Name)
52+
}
53+
if s.OnList() {
54+
log.Fatalf("symbol %s listed multiple times", s.Name)
55+
}
56+
s.Set(AttrOnList, true)
57+
text = append(text, s)
58+
flag := int(p.From3Offset())
59+
if flag&DUPOK != 0 {
60+
s.Set(AttrDuplicateOK, true)
9861
}
62+
if flag&NOSPLIT != 0 {
63+
s.Set(AttrNoSplit, true)
64+
}
65+
if flag&REFLECTMETHOD != 0 {
66+
s.Set(AttrReflectMethod, true)
67+
}
68+
s.Type = STEXT
69+
s.Text = p
70+
etext = p
71+
curtext = s
72+
continue
9973

100-
if curtext == nil {
101-
etext = nil
74+
case AFUNCDATA:
75+
// Rewrite reference to go_args_stackmap(SB) to the Go-provided declaration information.
76+
if curtext == nil { // func _() {}
10277
continue
10378
}
104-
etext.Link = p
105-
etext = p
79+
if p.To.Sym.Name == "go_args_stackmap" {
80+
if p.From.Type != TYPE_CONST || p.From.Offset != FUNCDATA_ArgsPointerMaps {
81+
ctxt.Diag("FUNCDATA use of go_args_stackmap(SB) without FUNCDATA_ArgsPointerMaps")
82+
}
83+
p.To.Sym = Linklookup(ctxt, fmt.Sprintf("%s.args_stackmap", curtext.Name), int(curtext.Version))
84+
}
85+
86+
}
87+
88+
if curtext == nil {
89+
etext = nil
90+
continue
10691
}
92+
etext.Link = p
93+
etext = p
10794
}
10895

10996
// Add reference to Go arguments for C or assembly functions without them.
@@ -147,7 +134,6 @@ func flushplist(ctxt *Link, freeProgs bool) {
147134
// Add to running list in ctxt.
148135
ctxt.Text = append(ctxt.Text, text...)
149136
ctxt.Data = append(ctxt.Data, gendwarf(ctxt, text)...)
150-
ctxt.Plists = nil
151137
ctxt.Curp = nil
152138
if freeProgs {
153139
ctxt.freeProgs()

0 commit comments

Comments
 (0)