Skip to content

Basic SuperH support#762

Merged
philipc merged 5 commits intogimli-rs:masterfrom
sozud:superh
Apr 10, 2025
Merged

Basic SuperH support#762
philipc merged 5 commits intogimli-rs:masterfrom
sozud:superh

Conversation

@sozud
Copy link
Copy Markdown
Contributor

@sozud sozud commented Apr 7, 2025

I'm not sure how correct this is but this seems to be enough to allow SuperH architecture ELFs to be opened.

Copy link
Copy Markdown
Contributor

@philipc philipc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit too basic. When adding support for an ELF architecture, I prefer for there to be enough support so that it can be added to the test in

fn elf_any() {
. You'll need some basic write support and relocation support for that to pass.

@sozud
Copy link
Copy Markdown
Contributor Author

sozud commented Apr 7, 2025

Ok I've added a little reloc support so that the test passes. How do people normally develop the reloc support? I don't see a ton of info about SuperH relocs, this it the best doc I've found but it's missing a decent amount of them. https://www.st.com/resource/en/reference_manual/rm0197-sh4-generic-and-c-specific-application-binary-interface-stmicroelectronics.pdf
I need to craft some sort of object file for object-testfiles that exercises the relocs and use that as the base for a test?

@philipc
Copy link
Copy Markdown
Contributor

philipc commented Apr 8, 2025

The best way is to do it in parallel with something that uses this crate and needs the support. Usually architectures have been added here because rustc needs them to compile for that target, so the relocation support is tested as part of that. Tests that use object-testfiles are more for regression testing, and don't do much to check that you got it right in the first place. The relocation support you've added looks correct to me.

I'm not very familiar with SuperH, so I have a couple of questions. Is this support only for SH-4? Should we use that as the architecture name instead so that other SuperH variants can be added later if needed? Is big-endian the most common byte ordering that is used?

@sozud
Copy link
Copy Markdown
Contributor Author

sozud commented Apr 10, 2025

I dumped the file I'm looking at with objdump and this PR and it seems like the current implementation is good enough for the file I'm currently looking at: https://gist.github.com/sozud/b5eb8fd740810dc7b056c5de0a73d32d

So I've been looking at SH2 support for objdiff https://github.com/encounter/objdiff
I'm not sure if this would work for SH4 or not, I could try that if you think it should be checked. SuperH is bi-endian, for SH-4 it can be selected by a pin apparently. Dreamcast seems to be little-endian by default? Not super familiar with it. Saturn and 32X are big-endian.

image

image

@philipc
Copy link
Copy Markdown
Contributor

philipc commented Apr 10, 2025

After looking more, I see that SH2 vs SH4 etc is distinguished using the ELF flags (EF_SH2, EF_SH4), so this looks good to me. Maybe that could be added as a sub-architecture if someone needed it, but it's fine for now.

Copy link
Copy Markdown
Contributor

@philipc philipc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@philipc philipc merged commit bc8ae31 into gimli-rs:master Apr 10, 2025
10 checks passed
@glaubitz
Copy link
Copy Markdown
Contributor

glaubitz commented Jul 23, 2025

Is big-endian the most common byte ordering that is used?

No, the commonly used byte ordering on SuperH is little-endian. Both the Sega 32X and Saturn are rather obscure targets.

Both little- and big-endian should be supported. PowerPC is similar in this regard and it just commented out the endianess parts in tests/round_trip/mod.rs.

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.

3 participants