Skip to content

SuperH: read code in the object's byte order - #438

Open
spriteice wants to merge 1 commit into
encounter:mainfrom
spriteice:superh-byte-order
Open

spriteice wants to merge 1 commit into
encounter:mainfrom
spriteice:superh-byte-order

Conversation

@spriteice

Copy link
Copy Markdown

Requested by spriteice · project thread

I have been using claude in a dreamcast decompilation. It found the following:

objdiff-core's SuperH backend reads every opcode, and the literal pool values it shows after mov.w and mov.l, with from_be_bytes. That suits the Saturn, but Dreamcast (SH-4) code is little-endian, so on a little-endian object every instruction comes out wrong: rts (0b 00 in memory) shows as .word 0x0B00.

ArchSuperH now keeps the object's endianness, as the ARM and MIPS backends do, and reads opcodes and pool values with it. The existing SuperH tests construct the arch as big-endian. A new test checks that the same function and literal pool, written in either byte order, scan to the same instructions (branch destination included) and display the same.

Checked:

  • cargo test --release --all-features -p objdiff-core, cargo +nightly fmt --all --check and cargo +nightly clippy --all-targets --all-features -p objdiff-core -- -D warnings pass.
  • On little-endian SH-4 objects (Hitachi SHC output converted to ELF, Metrowerks CodeWarrior objects, and the code of a retail Dreamcast game, about 1.65 million instructions), every instruction the patched objdiff decodes agrees with capstone's decoding of the same bytes. Before the change, most did not.

Not in this pull request: the decoder covers the SH-2's instructions, so the SH-4's floating-point, cache and control-register instructions still show as .word, as does mova (0xC7xx).

🤖 Generated with Claude Code

The SuperH backend read every opcode, and the literal pool values shown
after mov.w and mov.l, as big-endian. That suits the Saturn, but Dreamcast
(SH-4) objects are little-endian, so every instruction was decoded wrongly.
Take the byte order from the object, as the ARM and MIPS backends do, and
test both orders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant