]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/asm: improve assembler error messages
authorKeith Randall <khr@golang.org>
Mon, 5 Dec 2022 19:19:51 +0000 (11:19 -0800)
committerGopher Robot <gobot@golang.org>
Mon, 5 Dec 2022 23:21:07 +0000 (23:21 +0000)
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 <khr@google.com>
Run-TryBot: Keith Randall <khr@google.com>
Auto-Submit: Keith Randall <khr@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/asm/internal/asm/asm.go
src/cmd/asm/internal/asm/endtoend_test.go
src/cmd/asm/internal/asm/testdata/duperror.s [new file with mode: 0644]
src/cmd/internal/obj/plist.go

index 117670b8b8aadb26b8f7de4f54e731ddbaf70208..00fb7f417f062a18605c298784c409f56aeb2ad0 100644 (file)
@@ -297,7 +297,7 @@ func (p *Parser) asmGlobl(operands [][]lex.Token) {
        }
 
        // log.Printf("GLOBL %s %d, $%d", name, flag, size)
-       p.ctxt.Globl(nameAddr.Sym, addr.Offset, int(flag))
+       p.ctxt.GloblPos(nameAddr.Sym, addr.Offset, int(flag), p.pos())
 }
 
 // asmPCData assembles a PCDATA pseudo-op.
index 8af4db6ee4f241d7c3ea7991c6c0ed7e75767cc3..3928e364ab8436af3aca92aa4df9ee1356e43f24 100644 (file)
@@ -381,6 +381,10 @@ func TestGoBuildErrors(t *testing.T) {
        testErrors(t, "amd64", "buildtagerror")
 }
 
+func TestGenericErrors(t *testing.T) {
+       testErrors(t, "amd64", "duperror")
+}
+
 func TestARMErrors(t *testing.T) {
        testErrors(t, "arm", "armerror")
 }
diff --git a/src/cmd/asm/internal/asm/testdata/duperror.s b/src/cmd/asm/internal/asm/testdata/duperror.s
new file mode 100644 (file)
index 0000000..cd5934b
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright 2022 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+TEXT foo(SB), 0, $0
+       RET
+TEXT foo(SB), 0, $0 // ERROR "symbol foo redeclared"
+       RET
+
+GLOBL bar(SB), 0, $8
+GLOBL bar(SB), 0, $8 // ERROR "symbol bar redeclared"
+
+DATA bar+0(SB)/8, $0
+DATA bar+0(SB)/8, $0 // ERROR "overlapping DATA entry for bar"
index 751d231100a64d425557a461581bc00a64e7c8b1..fe9d2e1fb7401f4e16e2072f49318b21acb36166 100644 (file)
@@ -58,12 +58,12 @@ func Flushplist(ctxt *Link, plist *Plist, newprog ProgAlloc, myimportpath string
                        switch p.To.Sym.Name {
                        case "go_args_stackmap":
                                if p.From.Type != TYPE_CONST || p.From.Offset != objabi.FUNCDATA_ArgsPointerMaps {
-                                       ctxt.Diag("FUNCDATA use of go_args_stackmap(SB) without FUNCDATA_ArgsPointerMaps")
+                                       ctxt.Diag("%s: FUNCDATA use of go_args_stackmap(SB) without FUNCDATA_ArgsPointerMaps", p.Pos)
                                }
                                p.To.Sym = ctxt.LookupDerived(curtext, curtext.Name+".args_stackmap")
                        case "no_pointers_stackmap":
                                if p.From.Type != TYPE_CONST || p.From.Offset != objabi.FUNCDATA_LocalsPointerMaps {
-                                       ctxt.Diag("FUNCDATA use of no_pointers_stackmap(SB) without FUNCDATA_LocalsPointerMaps")
+                                       ctxt.Diag("%s: FUNCDATA use of no_pointers_stackmap(SB) without FUNCDATA_LocalsPointerMaps", p.Pos)
                                }
                                // funcdata for functions with no local variables in frame.
                                // 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) {
                return
        }
        if s.Func() != nil {
-               ctxt.Diag("InitTextSym double init for %s", s.Name)
+               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)
+               return
        }
        s.NewFuncInfo()
        if s.OnList() {
-               ctxt.Diag("symbol %s listed multiple times", s.Name)
+               ctxt.Diag("%s: symbol %s redeclared", ctxt.PosTable.Pos(start), s.Name)
+               return
        }
 
        // startLine should be the same line number that would be displayed via
@@ -210,8 +212,12 @@ func (ctxt *Link) toFuncFlag(flag int) objabi.FuncFlag {
 }
 
 func (ctxt *Link) Globl(s *LSym, size int64, flag int) {
+       ctxt.GloblPos(s, size, flag, src.NoXPos)
+}
+func (ctxt *Link) GloblPos(s *LSym, size int64, flag int, pos src.XPos) {
        if s.OnList() {
-               ctxt.Diag("symbol %s listed multiple times", s.Name)
+               // TODO: print where the first declaration was.
+               ctxt.Diag("%s: symbol %s redeclared", ctxt.PosTable.Pos(pos), s.Name)
        }
        s.Set(AttrOnList, true)
        ctxt.Data = append(ctxt.Data, s)