riscv64: use absolute addresses for branch and jump targets

riscv64asm.GoSyntax uses the n(PC) syntax for branches and jumps,
e.g., BEQ X10, X11, 2(PC). Unfortunately, the targets of most of the
branch instructions reported by this function are incorrect, i.e.,
it reports an incorrect instruction delta. This is because it assumes
that all RISC-V instructions in Go programs are 4 bytes in length,
which is not the case and has not been since Go 1.26 introduced
compressed instruction support for RISC-V. Since Go 1.26, RISC-V Go
programs contain a mixture of 2 byte and 4 byte instructions.

There's no way for the riscv64asm package to determine the difference in
number of instructions between a jump and its target, so there is no
alternative but to fall back to printing out the targets using absolute
addresses as is done on amd64, which also has a variable size
instruction set.

Change-Id: I12bd4b40a82b156d46248670153be8e8d9524fa4
Reviewed-on: https://go-review.googlesource.com/c/arch/+/828344
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Julian Zhu <jz531210@gmail.com>
Reviewed-by: Joel Sing <joel@sing.id.au>
2 files changed
tree: 43d4652f0980a683146ec4ee51a05887c450428d
  1. arm/
  2. arm64/
  3. loong64/
  4. ppc64/
  5. riscv64/
  6. s390x/
  7. x86/
  8. .gitattributes
  9. codereview.cfg
  10. CONTRIBUTING.md
  11. go.mod
  12. go.sum
  13. LICENSE
  14. PATENTS
  15. README.md
README.md

arch

Go Reference

This repository holds machine architecture information used by the Go toolchain. The parts needed in the main Go repository are copied in.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://go.dev/doc/contribute.

The git repository is https://go.googlesource.com/arch.

The main issue tracker for the arch repository is located at https://go.dev/issues. Prefix your issue with “x/arch:” in the subject line, so it is easy to find.