Skip to content

Commit 9dde2de

Browse files
randall77gopherbot
authored andcommitted
cmd/asm: improve assembler error messages
Provide file/line numbers for errors when we have them. Make the assembler error text closer to the equivalent errors from the compiler. Abort further processing when we come across errors. Fixes #53994 Change-Id: I4d6a037d6d713c1329923fce4c1189b5609f3660 Reviewed-on: https://go-review.googlesource.com/c/go/+/455276 Reviewed-by: Keith Randall <[email protected]> Run-TryBot: Keith Randall <[email protected]> Auto-Submit: Keith Randall <[email protected]> Reviewed-by: Cherry Mui <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 0b323a3 commit 9dde2de

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ func (p *Parser) asmGlobl(operands [][]lex.Token) {
297297
}
298298

299299
// log.Printf("GLOBL %s %d, $%d", name, flag, size)
300-
p.ctxt.Globl(nameAddr.Sym, addr.Offset, int(flag))
300+
p.ctxt.GloblPos(nameAddr.Sym, addr.Offset, int(flag), p.pos())
301301
}
302302

303303
// asmPCData assembles a PCDATA pseudo-op.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ func TestGoBuildErrors(t *testing.T) {
381381
testErrors(t, "amd64", "buildtagerror")
382382
}
383383

384+
func TestGenericErrors(t *testing.T) {
385+
testErrors(t, "amd64", "duperror")
386+
}
387+
384388
func TestARMErrors(t *testing.T) {
385389
testErrors(t, "arm", "armerror")
386390
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
TEXT foo(SB), 0, $0
6+
RET
7+
TEXT foo(SB), 0, $0 // ERROR "symbol foo redeclared"
8+
RET
9+
10+
GLOBL bar(SB), 0, $8
11+
GLOBL bar(SB), 0, $8 // ERROR "symbol bar redeclared"
12+
13+
DATA bar+0(SB)/8, $0
14+
DATA bar+0(SB)/8, $0 // ERROR "overlapping DATA entry for bar"

src/cmd/internal/obj/plist.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ func Flushplist(ctxt *Link, plist *Plist, newprog ProgAlloc, myimportpath string
5858
switch p.To.Sym.Name {
5959
case "go_args_stackmap":
6060
if p.From.Type != TYPE_CONST || p.From.Offset != objabi.FUNCDATA_ArgsPointerMaps {
61-
ctxt.Diag("FUNCDATA use of go_args_stackmap(SB) without FUNCDATA_ArgsPointerMaps")
61+
ctxt.Diag("%s: FUNCDATA use of go_args_stackmap(SB) without FUNCDATA_ArgsPointerMaps", p.Pos)
6262
}
6363
p.To.Sym = ctxt.LookupDerived(curtext, curtext.Name+".args_stackmap")
6464
case "no_pointers_stackmap":
6565
if p.From.Type != TYPE_CONST || p.From.Offset != objabi.FUNCDATA_LocalsPointerMaps {
66-
ctxt.Diag("FUNCDATA use of no_pointers_stackmap(SB) without FUNCDATA_LocalsPointerMaps")
66+
ctxt.Diag("%s: FUNCDATA use of no_pointers_stackmap(SB) without FUNCDATA_LocalsPointerMaps", p.Pos)
6767
}
6868
// funcdata for functions with no local variables in frame.
6969
// Define two zero-length bitmaps, because the same index is used
@@ -166,11 +166,13 @@ func (ctxt *Link) InitTextSym(s *LSym, flag int, start src.XPos) {
166166
return
167167
}
168168
if s.Func() != nil {
169-
ctxt.Diag("InitTextSym double init for %s", s.Name)
169+
ctxt.Diag("%s: symbol %s redeclared\n\t%s: other declaration of symbol %s", ctxt.PosTable.Pos(start), s.Name, ctxt.PosTable.Pos(s.Func().Text.Pos), s.Name)
170+
return
170171
}
171172
s.NewFuncInfo()
172173
if s.OnList() {
173-
ctxt.Diag("symbol %s listed multiple times", s.Name)
174+
ctxt.Diag("%s: symbol %s redeclared", ctxt.PosTable.Pos(start), s.Name)
175+
return
174176
}
175177

176178
// startLine should be the same line number that would be displayed via
@@ -210,8 +212,12 @@ func (ctxt *Link) toFuncFlag(flag int) objabi.FuncFlag {
210212
}
211213

212214
func (ctxt *Link) Globl(s *LSym, size int64, flag int) {
215+
ctxt.GloblPos(s, size, flag, src.NoXPos)
216+
}
217+
func (ctxt *Link) GloblPos(s *LSym, size int64, flag int, pos src.XPos) {
213218
if s.OnList() {
214-
ctxt.Diag("symbol %s listed multiple times", s.Name)
219+
// TODO: print where the first declaration was.
220+
ctxt.Diag("%s: symbol %s redeclared", ctxt.PosTable.Pos(pos), s.Name)
215221
}
216222
s.Set(AttrOnList, true)
217223
ctxt.Data = append(ctxt.Data, s)

0 commit comments

Comments
 (0)