Skip to content

srxfixup: detect and fix function symbols at .text offset 0#816

Merged
fjtrujy merged 2 commits intops2dev:masterfrom
fjtrujy:srxfixup_zero_text_dectection
Mar 6, 2026
Merged

srxfixup: detect and fix function symbols at .text offset 0#816
fjtrujy merged 2 commits intops2dev:masterfrom
fjtrujy:srxfixup_zero_text_dectection

Conversation

@fjtrujy
Copy link
Copy Markdown
Member

@fjtrujy fjtrujy commented Mar 6, 2026

Problem

When an IOP module's export table dispatches a function call, it uses jal <address>. If a function symbol ends up at .text offset 0, any zeroed or uninitialized export entry becomes an accidental jal 0x0 — silently calling real code instead of faulting. This is a latent bug that's hard to diagnose at runtime.

Solution

1. Detection in srxfixup
Added check_zero_text_symbols() that scans the ELF symbol table for STT_FUNC or STT_NOTYPE symbols at .text value 0. If found, srxfixup prints a descriptive error and exits with failure. _start and _ftext are excluded since they are entry points / linker labels that are never dispatched via export tables.

A new --allow-zero-text flag bypasses the check for modules where it's safe (see below).

2. Fixes for modules with export tables (Makefiles + exports.tab)
Reordered IOP_OBJS so exports.o is linked first. This places the irx_export_table struct (STT_OBJECT) at .text offset 0 instead of function code.
Moved _retonly definitions after DECLARE_EXPORT_TABLE in exports.tab files so the function body doesn't land before the table struct within exports.o.

Affected modules: sbus, acatad, accdvd, acdev, acdev9, cdvdfsv, cdvdman, cdvdstm, ioptrap, sior, pvrdrv, devfs, mcman, mcserv, smap, libsd, dmacman, intrman, mtapman, siftoo, stdio, timrman, tcpip, netman, udptty, romdrv, tcpip-netman.

3. Automatic --allow-zero-text for modules without export tables Rules.make
Modules that have no exports.o in IOP_OBJS don't have export tables, so jal 0x0 is not a hazard. Rules.make now detects this with $(filter) and automatically passes --allow-zero-text to srxfixup.

This avoids the need to create fake/dummy export tables for modules like smap-none and smap-ps2ip that intentionally have no exports.

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

This PR hardens IRX generation by detecting a dangerous layout case where function symbols can land at .text offset 0 (making zeroed export entries effectively jal 0x0), and updates module build/link ordering so export tables occupy .text+0 instead of executable code.

Changes:

  • Add --allow-zero-text and a .text+0 function-symbol detection pass to srxfixup.
  • Reorder many IOP module IOP_OBJS lists so exports.o is linked first; move _retonly definitions after export table declarations in several exports.tab files.
  • Update iop/Rules.make to automatically add --allow-zero-text for modules that do not link exports.o.

Reviewed changes

Copilot reviewed 34 out of 34 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tools/srxfixup/src/srxfixup.c Adds --allow-zero-text flag and a symbol-table scan to detect functions at .text offset 0.
tools/srxfixup/README.md Documents the new zero-.text symbol check and the bypass flag.
iop/tcpip/tcpip/src/exports.tab Moves _retonly definition after export table to avoid code at .text+0.
iop/tcpip/tcpip/Makefile Links exports.o first to place export table at .text+0.
iop/tcpip/tcpip-netman/src/exports.tab Moves _retonly definition after export table to avoid code at .text+0.
iop/system/timrman/Makefile Links exports.o first to place export table at .text+0.
iop/system/stdio/Makefile Links exports.o first to place export table at .text+0.
iop/system/siftoo/Makefile Links exports.o first to place export table at .text+0.
iop/system/mtapman/Makefile Links exports.o first to place export table at .text+0.
iop/system/intrman/Makefile Links exports.o first to place export table at .text+0.
iop/system/dmacman/Makefile Links exports.o first to place export table at .text+0.
iop/sound/libsd/Makefile Links exports.o first to place export table at .text+0.
iop/network/udptty/src/exports.tab Moves _retonly definition after export table to avoid code at .text+0.
iop/network/smap/src/exports.tab Moves _retonly definition after export tables to avoid code at .text+0.
iop/network/smap/Makefile Ensures exports.o is first (and makes IOP_OBJS override-friendly for variants).
iop/network/smap-ps2ip/Makefile Defines an IOP_OBJS list that omits exports.o (no export table variant).
iop/network/smap-none/Makefile Defines an IOP_OBJS list that omits exports.o (no export table variant).
iop/network/netman/src/exports.tab Moves _retonly definition after export table to avoid code at .text+0.
iop/memorycard/mcserv/Makefile Links exports.o first to place export table at .text+0.
iop/memorycard/mcman/Makefile Links exports.o first to place export table at .text+0.
iop/fs/romdrv/src/exports.tab Moves _retonly definition after export tables to avoid code at .text+0.
iop/fs/devfs/Makefile Links exports.o first to place export table at .text+0.
iop/dev9/pvrdrv/Makefile Links exports.o first to place export table at .text+0.
iop/debug/sior/Makefile Links exports.o first to place export table at .text+0.
iop/debug/ioptrap/Makefile Links exports.o first to place export table at .text+0.
iop/cdvd/cdvdstm/Makefile Links exports.o first to place export table at .text+0.
iop/cdvd/cdvdman/Makefile Links exports.o first to place export table at .text+0.
iop/cdvd/cdvdfsv/Makefile Links exports.o first to place export table at .text+0.
iop/arcade/acdev9/Makefile Links exports.o first to place export table at .text+0.
iop/arcade/acdev/Makefile Links exports.o first to place export table at .text+0.
iop/arcade/accdvd/Makefile Links exports.o first to place export table at .text+0.
iop/arcade/acatad/Makefile Links exports.o first to place export table at .text+0.
iop/Rules.make Automatically adds --allow-zero-text when exports.o is not part of IOP_OBJS.
common/sbus/Makefile Links exports.o first to place export table at .text+0.

💡 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.

The srxfixup changes and the export table reorder LGTM

fjtrujy added 2 commits March 6, 2026 23:08
Add a check for STT_FUNC/STT_NOTYPE symbols at .text value 0, which
can become unintended targets of jal 0x0 when called through an
export table.

New --allow-zero-text flag to bypass the check for modules that
have no export table (where jal 0x0 is not a hazard).
_start and _ftext are excluded (entry point / linker label, never
dispatched via export table).
Document the check and flag in README.md.
For modules with export tables, reorder IOP_OBJS so exports.o is
linked first and move _retonly definitions after DECLARE_EXPORT_TABLE
in exports.tab, ensuring the export struct (STT_OBJECT) occupies
.text offset 0 instead of function code.

For modules without export tables (smap-none, smap-ps2ip, and others),
automatically pass --allow-zero-text to srxfixup via Rules.make when
no exports.o is present in IOP_OBJS.
@fjtrujy fjtrujy force-pushed the srxfixup_zero_text_dectection branch from cdf0d5a to 1527c2b Compare March 6, 2026 22:08
@fjtrujy fjtrujy requested a review from Copilot March 6, 2026 22:13
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

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


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

@fjtrujy fjtrujy merged commit 20d0fe9 into ps2dev:master Mar 6, 2026
15 checks passed
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