relinker: sfiii-ps5 (PPSA93303) companion libc.prx is refused because its function st_size values are the real libc sizes, not the stub sizes #14893

Closed
opened 2026-11-01 23:17:44 +00:00 by p3n1cillin · 0 comments
p3n1cillin commented 2026-11-01 23:17:44 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by p3n1cillin on 2026-11-01T23:17:44Z.


What happens

Converting sfiii-ps5 (PPSA93303, v1.0.0 release, PPSA93303.zip sha256 632efadfaf9f6e73316c51268813719fa42f277a482144ae3c225894259af1b2) with relinker --windows on main 0580e5c951 fails on its bundled sce_module/libc.prx:

FAIL: ...\src\sce_module\libc.prx: Unmapped or inaccessible guest address 22792

That module isn't Sony's libc.prx. It's the title's own loader companion, generated by tools/ps5/companion-exports.py from tools/ps5/libc-exports.tsv (2568 NIDs, each with a binding, kind and size). Per the README, the title runs natively on the console.

  • Function bodies: each function export is a 16-byte stub, movl $i,%eax; jmp sf3_stub (line 71). Only a few, such as setjmp, have real bodies.
  • Symbol sizes: the generator writes each symbol's st_size from the TSV (line 130). Those are the sizes of the real libc functions, not of the stubs.

The result in the shipped module:

  • The executable PT_LOAD is 0x75a2 bytes (flags=PF_X). It holds 1875 function symbols, each at its own address.
  • 1352 of them have [st_value, st_value + st_size) running past the next function's start.
  • 13 of them run past the end of the segment. 0x5908 (22792) is the first: CLT04GjI7UE, size 7598, and 0x5908 + 7598 = 0x76b6.

Where the relinker rejects it

  1. Reader: GuestImageReader.cpp:218 requires every defined function symbol's whole [value, value + max(size, 1)) to lie in one executable PT_LOAD. The Windows and macOS writers pass the same extent to GetRva (WindowsGuestModuleWriter.cpp:143, MacOsGuestModuleWriter.cpp:92).
  2. Code analysis: with only those three spots changed to use an extent of 1 for functions, conversion moves on. It then fails at CodeInstructionCollector.cpp:304 → :221, "Code analysis: function exceeds executable segment" at 0x5908, because code analysis uses each function symbol's size as a range to decode. test_tls_function_coverage.py:580 and :587 require exactly that rejection for a symbol range that overruns its segment.
  3. Truncated decode: also skipping the range, but keeping the root, for symbols whose size overruns the segment isn't enough either. The next failure is "Code analysis: Instruction truncated in immediate operand (offset 0x4b08)": a size that does fit in the segment ends in the middle of a neighbouring stub's instruction.

So converting this module needs code analysis to stop trusting function st_size here, beyond the 13 overrunning symbols.

What the loader does with st_size

In FreeBSD 11.4's rtld, the only place a symbol's st_size is read is do_copy_relocations (amd64/reloc.c:85), which copies a data object. The other st_size uses in rtld.c and map_object.c are struct stat file sizes. A function symbol's size affects nothing at load time, which fits with this module loading on the console. I don't have a measurement of what Sony's loader checks.

Question

Should the relinker accept a guest module whose function-symbol sizes don't describe its code? If so, how should code analysis find those functions? For example, when a module's function ranges overlap one another or overrun their segment, it could use the symbols only as roots and follow control flow. Or should this stay refused, and the companion's generator emit stub-sized symbols instead? I haven't opened a PR because either answer changes what test_tls_function_coverage.py pins.

Not run: the title itself, since it doesn't convert. Even once it does, it needs the player's own disc images to get past its launcher.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6153303747 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/14893). Originally posted by [p3n1cillin](https://github.com/p3n1cillin) on 2026-11-01T23:17:44Z. --- ## What happens Converting sfiii-ps5 (`PPSA93303`, [v1.0.0 release](https://github.com/damiantw/sfiii-ps5/releases/tag/v1.0.0), `PPSA93303.zip` sha256 `632efadfaf9f6e73316c51268813719fa42f277a482144ae3c225894259af1b2`) with `relinker --windows` on `main` `0580e5c951` fails on its bundled `sce_module/libc.prx`: ``` FAIL: ...\src\sce_module\libc.prx: Unmapped or inaccessible guest address 22792 ``` That module isn't Sony's `libc.prx`. It's the title's own loader companion, generated by [`tools/ps5/companion-exports.py`](https://github.com/damiantw/sfiii-ps5/blob/fd155163463a181a9fa66fa17d023f7ea0c403f5/tools/ps5/companion-exports.py) from [`tools/ps5/libc-exports.tsv`](https://github.com/damiantw/sfiii-ps5/blob/fd155163463a181a9fa66fa17d023f7ea0c403f5/tools/ps5/libc-exports.tsv) (2568 NIDs, each with a binding, kind and size). Per the [README](https://github.com/damiantw/sfiii-ps5/blob/fd155163463a181a9fa66fa17d023f7ea0c403f5/README.md), the title runs natively on the console. - **Function bodies:** each function export is a 16-byte stub, `movl $i,%eax; jmp sf3_stub` ([line 71](https://github.com/damiantw/sfiii-ps5/blob/fd155163463a181a9fa66fa17d023f7ea0c403f5/tools/ps5/companion-exports.py#L71)). Only a few, such as `setjmp`, have real bodies. - **Symbol sizes:** the generator writes each symbol's `st_size` from the TSV ([line 130](https://github.com/damiantw/sfiii-ps5/blob/fd155163463a181a9fa66fa17d023f7ea0c403f5/tools/ps5/companion-exports.py#L130)). Those are the sizes of the real libc functions, not of the stubs. The result in the shipped module: - The executable `PT_LOAD` is 0x75a2 bytes (`flags=PF_X`). It holds 1875 function symbols, each at its own address. - **1352 of them** have `[st_value, st_value + st_size)` running past the next function's start. - **13 of them** run past the end of the segment. 0x5908 (22792) is the first: `CLT04GjI7UE`, size 7598, and 0x5908 + 7598 = 0x76b6. ## Where the relinker rejects it 1. **Reader:** `GuestImageReader.cpp:218` requires every defined function symbol's whole `[value, value + max(size, 1))` to lie in one executable `PT_LOAD`. The Windows and macOS writers pass the same extent to `GetRva` (`WindowsGuestModuleWriter.cpp:143`, `MacOsGuestModuleWriter.cpp:92`). 2. **Code analysis:** with only those three spots changed to use an extent of 1 for functions, conversion moves on. It then fails at `CodeInstructionCollector.cpp:304` → `:221`, "Code analysis: function exceeds executable segment" at 0x5908, because code analysis uses each function symbol's size as a range to decode. `test_tls_function_coverage.py:580` and `:587` require exactly that rejection for a symbol range that overruns its segment. 3. **Truncated decode:** also skipping the range, but keeping the root, for symbols whose size overruns the segment isn't enough either. The next failure is "Code analysis: Instruction truncated in immediate operand (offset 0x4b08)": a size that does fit in the segment ends in the middle of a neighbouring stub's instruction. So converting this module needs code analysis to stop trusting function `st_size` here, beyond the 13 overrunning symbols. ## What the loader does with `st_size` In FreeBSD 11.4's rtld, the only place a symbol's `st_size` is read is `do_copy_relocations` ([`amd64/reloc.c:85`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/libexec/rtld-elf/amd64/reloc.c#L85)), which copies a data object. The other `st_size` uses in `rtld.c` and `map_object.c` are `struct stat` file sizes. A function symbol's size affects nothing at load time, which fits with this module loading on the console. I don't have a measurement of what Sony's loader checks. ## Question Should the relinker accept a guest module whose function-symbol sizes don't describe its code? If so, how should code analysis find those functions? For example, when a module's function ranges overlap one another or overrun their segment, it could use the symbols only as roots and follow control flow. Or should this stay refused, and the companion's generator emit stub-sized symbols instead? I haven't opened a PR because either answer changes what `test_tls_function_coverage.py` pins. Not run: the title itself, since it doesn't convert. Even once it does, it needs the player's own disc images to get past its launcher. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#14893
No description provided.