]> Cypherpunks repositories - gostls13.git/commit
cmd/internal/obj/riscv: prevent duplicate error reports
authorMark Ryan <markdryan@rivosinc.com>
Tue, 10 Dec 2024 16:02:26 +0000 (17:02 +0100)
committerMeng Zhuo <mengzhuo1203@gmail.com>
Wed, 19 Mar 2025 01:36:01 +0000 (18:36 -0700)
commit24b395119b4df7f16915b9f01a6aded647b79bbd
tree34ae96b697b4557a707289997482987e1c4d70ab
parent2e749a645a6d03c7ac11bb172c4591564061b29e
cmd/internal/obj/riscv: prevent duplicate error reports

The riscv64 Go assembler can output certain errors, ones produced by
instructionsForProg, multiple times.  These errors are guaranteed to
be output at least twice and can appear three or more times if a
rescan is needed to recompute branch addresses.  For example, the
syntactically incorrect instruction

MOV (X10), $1

will generate at least two identical errors

asm: 86076 (asm.s:21524) MOV (X10), $1: unsupported MOV
asm: 86076 (asm.s:21524) MOV (X10), $1: unsupported MOV
asm: assembly failed

In addition to confusing the user, these duplicate errors make it
difficult to write negative tests for certain types of instructions,
e.g., branches, whose duplicate errors are not always identical,
and so not ignored by endtoend_test.go.

We fix the issue by returning from preprocess if any errors have been
generated by the time we reach the end of the rescan loop. One
implication of this change is that validation errors will no longer
be reported if an error is generated earlier in the preprocess stage.
Negative test cases for validation errors are therefore moved to
their own file as the existing riscv64error.s file contains errors
generated by instructionsForProg that will now suppress the
validation errors.

Change-Id: Iffacdbefce28f44970dd5dda44990b822b8a23d4
Reviewed-on: https://go-review.googlesource.com/c/go/+/637315
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Joel Sing <joel@sing.id.au>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/cmd/asm/internal/asm/endtoend_test.go
src/cmd/asm/internal/asm/testdata/riscv64error.s
src/cmd/asm/internal/asm/testdata/riscv64validation.s [new file with mode: 0644]
src/cmd/internal/obj/riscv/obj.go