Skip to content

[iop]: run srxfixup with --rb during link to convert relative branches (fixes J/JAL reloc incompatibilities)#814

Merged
uyjulian merged 1 commit intops2dev:masterfrom
fjtrujy:srxfixup_relative-branch
Mar 6, 2026
Merged

[iop]: run srxfixup with --rb during link to convert relative branches (fixes J/JAL reloc incompatibilities)#814
uyjulian merged 1 commit intops2dev:masterfrom
fjtrujy:srxfixup_relative-branch

Conversation

@fjtrujy
Copy link
Copy Markdown
Member

@fjtrujy fjtrujy commented Mar 6, 2026

Summary

Run srxfixup with the --rb / --relative-branch option in the IOP link pipeline so eligible J/JAL instructions are rewritten to PC-relative branches and their R_MIPS_26 relocations removed. This prevents loader/relocation incompatibilities introduced by modern toolchains.

Problem

Modern GCC/binutils can emit R_MIPS_26 relocations for J/JAL instructions (absolute jump relocs). The PS2 loader / IRX format has limited/fragile handling for those relocations, which can lead to:

  • relocations that the loader cannot resolve correctly,
  • modules that fail to load, or
  • incorrect runtime behavior (wrong jump targets).

This is more likely with newer toolchains and certain optimizations.

Solution

When --rb is enabled, srxfixup:

  • scans relocation sections for R_MIPS_26 entries,
  • for jumps targeting local symbols whose offsets fit the PC-relative branch range, replaces the J/JAL instruction with an equivalent PC-relative branch instruction,
  • marks and removes the corresponding relocation entries (compacts the relocation table).

… builds

R_MIPS_NONE is a valid no-op relocation type that newer toolchains emit
(e.g. as padding between real relocations). srxfixup's fixlocation_an_rel()
had no case for it and would fall through to the default unhandled-relocation
path, causing srxfixup to abort when building any IRX that contained one.

Enable --relative-branch (--rb) in iop/Rules.make so that all IOP IRX
binaries have their R_MIPS_26 absolute-jump relocations converted to
position-independent relative branches. Without this, a module loaded at a
different address than it was linked for will execute the wrong jal target.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the IOP module link pipeline to proactively eliminate problematic R_MIPS_26 relocations by enabling srxfixup’s relative-branch conversion, and ensures the relocation-applier logic tolerates R_MIPS_NONE entries created by that conversion.

Changes:

  • Add R_MIPS_NONE handling in srxgen.c relocation fixup switch to avoid treating it as an unknown relocation type.
  • Enable srxfixup --rb in the IOP .irx build rule so eligible J/JAL are rewritten to PC-relative branches and their R_MIPS_26 relocs removed.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tools/srxfixup/src/srxgen.c Treats R_MIPS_NONE as a no-op relocation during fixlocation processing (prevents abort on type 0).
iop/Rules.make Adds --rb to the IOP srxfixup invocation to avoid loader-incompatible R_MIPS_26 relocs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Member

@uyjulian uyjulian left a comment

Choose a reason for hiding this comment

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

Lgtm, nice fix

@uyjulian uyjulian merged commit 8f8386b into ps2dev:master Mar 6, 2026
15 checks passed
@fjtrujy fjtrujy deleted the srxfixup_relative-branch branch March 6, 2026 14:28
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