diff options
| author | Joel Sing <joel@sing.id.au> | 2025-01-04 03:44:40 +1100 |
|---|---|---|
| committer | Joel Sing <joel@sing.id.au> | 2025-01-06 23:43:06 -0800 |
| commit | d8ad4af78bba1f4bf2bb1ce1ace2b62bc86540fd (patch) | |
| tree | 059e61ef771d10c4b9f2bcb3d9221771daf9b5d1 /src/cmd/internal | |
| parent | a76cc5a4ecb004616404cac5bb756da293818469 (diff) | |
| download | go-d8ad4af78bba1f4bf2bb1ce1ace2b62bc86540fd.tar.xz | |
cmd/internal/disasm: correct instruction length handling for riscv64
disasm_riscv64 currently always returns an instruction length of four,
which is not correct if compressed instructions are in use. Return the
length of the decoded instruction, defaulting to two bytes if the
instruction is unknown.
With this change it is possible to correctly objdump a binary that is
written in C and includes compressed instructions:
$ go tool objdump ./hello
TEXT _start(SB)
:0 0x5b0 ef002002 CALL 8(PC)
:0 0x5b4 aa87 ADD X10, X0, X15
:0 0x5b6 17250000 AUIPC $2, X10
:0 0x5ba 033525a3 MOV -1486(X10), X10
:0 0x5be 8265 MOV (X2), X11
:0 0x5c0 3000 ADDI $8, X2, X12
...
Fixes #71102
Change-Id: Ia99eb114a98c6d535de872ce8a526cd5e6203fff
Reviewed-on: https://go-review.googlesource.com/c/go/+/639995
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Jorropo <jorropo.pgm@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/cmd/internal')
| -rw-r--r-- | src/cmd/internal/disasm/disasm.go | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/cmd/internal/disasm/disasm.go b/src/cmd/internal/disasm/disasm.go index c317effa90..3ae8989b38 100644 --- a/src/cmd/internal/disasm/disasm.go +++ b/src/cmd/internal/disasm/disasm.go @@ -410,14 +410,16 @@ func disasm_ppc64(code []byte, pc uint64, lookup lookupFunc, byteOrder binary.By func disasm_riscv64(code []byte, pc uint64, lookup lookupFunc, byteOrder binary.ByteOrder, gnuAsm bool) (string, int) { inst, err := riscv64asm.Decode(code) var text string + size := inst.Len if err != nil || inst.Op == 0 { + size = 2 text = "?" } else if gnuAsm { text = fmt.Sprintf("%-36s // %s", riscv64asm.GoSyntax(inst, pc, lookup, textReader{code, pc}), riscv64asm.GNUSyntax(inst)) } else { text = riscv64asm.GoSyntax(inst, pc, lookup, textReader{code, pc}) } - return text, 4 + return text, size } func disasm_s390x(code []byte, pc uint64, lookup lookupFunc, _ binary.ByteOrder, gnuAsm bool) (string, int) { |
