fix(relinker): load a PT_SCE_RELRO segment that no PT_LOAD covers #4542

Merged
saxopa merged 1 commit from upstream-pr/4542 into main 2026-10-12 18:32:37 +00:00
saxopa commented 2026-10-12 15:11:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by saxopa on 2026-10-12T15:11:39Z.


What

The OpenOrbis graphics sample (toolchain v0.5.4, samples/graphics) stops on current main (d592d54e) right after #4203. With --skip-sce-module --windows, and the same with --macos:

FAIL: ELF address is not contained in PT_LOAD memory (offset 0x130000)

The sample has PT_SCE_RELRO (0x61000010, R) at 0x124000–0x134000, between the code PT_LOAD and the data PT_LOAD, and no PT_LOAD covers it. It holds the PLTGOT (0x130000), the init array (0x12a620) and the TLS image (0x12a798). SegmentFilter drops the segment. Windows and macOS output then stop at the first relocation into it. Linux output finishes, but no PT_LOAD maps 0x124000–0x134000. In the synthetic test below, main puts the relinker's extra block (RWX, 340 bytes) at the address of the dropped segment, with no error.

ElfReader::ReadProgramHeaders now reports a PT_SCE_RELRO that no PT_LOAD covers as a read-write PT_LOAD, so the Linux, Windows and macOS writers load it. Relocations need to write into it.

  • A PT_SCE_RELRO inside a PT_LOAD (the PS5 layout uses PT_LOAD RW plus PT_GNU_RELRO) is still skipped.
  • One that partially overlaps a PT_LOAD throws PT_SCE_RELRO partially overlaps a PT_LOAD segment.

The segment stays writable after relocation. FreeBSD rtld makes PT_GNU_RELRO read-only after relocation, and what the console does with PT_SCE_RELRO is not checked. Both points are recorded in TechnicalDebt.

Where the sample stops with this change (--skip-sce-module, and the same with its sce_module):

main this PR
Linux output written; 0x124000–0x134000 not mapped Not enough program header slots: need 10, available 9
--windows, --macos ELF address is not contained in PT_LOAD memory (offset 0x130000) Code analysis: overlapping instruction boundaries (offset 0xde39f)
unused-filter=1 Init/fini array is not file-backed (offset 0x12a620) unchanged

On Linux the output program header table keeps the input count (9). On main the sample already needs PT_GNU_EH_FRAME dropped to fit, with the existing warning. With the segment loaded it needs 10, so it now fails with an explicit error instead of producing an image with unmapped data. Growing that table is a separate topic.

The Windows and macOS code analysis stop is the "inline jump tables" item of #3093. The unused-filter=1 and unused-filter=2 readers parse program headers themselves and are not changed here; this is recorded in TechnicalDebt.

Tested

macOS 27 (Apple Silicon), relinker-only Release build.

  • ctest: 125/125.
  • New test sce_relro. It fails on main and passes with the change.
    • A standalone PT_SCE_RELRO that holds a RELATIVE-relocated pointer, relinked for Linux, Windows and macOS. The Linux output has one RW PT_LOAD at 0x1000, size 0x1000, and the relocation (0x1000, 8, 0x210).
    • The same range covered by a RW PT_LOAD: no second PT_LOAD.
    • Partial overlap at the start and at the end throws, for Linux and Windows.
    • On Windows, the test also runs the output and expects exit code 42. That step was not run here.
  • OpenOrbis sample: results in the table above. The sce_module (libc.prx, libSceFios2.prx) converts without new errors. Not run: no x86-64 Linux or Windows host here.
  • python3 tools/check_conventions.py --base origin/main passes; git diff --check is clean.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt — none added
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source — none added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4831342381 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4542). Originally posted by [saxopa](https://github.com/saxopa) on 2026-10-12T15:11:39Z. --- ### What The OpenOrbis `graphics` sample (toolchain v0.5.4, `samples/graphics`) stops on current `main` (d592d54e) right after #4203. With `--skip-sce-module --windows`, and the same with `--macos`: ``` FAIL: ELF address is not contained in PT_LOAD memory (offset 0x130000) ``` The sample has `PT_SCE_RELRO` (0x61000010, `R`) at 0x124000–0x134000, between the code `PT_LOAD` and the data `PT_LOAD`, and no `PT_LOAD` covers it. It holds the PLTGOT (0x130000), the init array (0x12a620) and the TLS image (0x12a798). `SegmentFilter` drops the segment. Windows and macOS output then stop at the first relocation into it. Linux output finishes, but no `PT_LOAD` maps 0x124000–0x134000. In the synthetic test below, `main` puts the relinker's extra block (RWX, 340 bytes) at the address of the dropped segment, with no error. `ElfReader::ReadProgramHeaders` now reports a `PT_SCE_RELRO` that no `PT_LOAD` covers as a read-write `PT_LOAD`, so the Linux, Windows and macOS writers load it. Relocations need to write into it. - A `PT_SCE_RELRO` inside a `PT_LOAD` (the PS5 layout uses `PT_LOAD` RW plus `PT_GNU_RELRO`) is still skipped. - One that partially overlaps a `PT_LOAD` throws `PT_SCE_RELRO partially overlaps a PT_LOAD segment`. The segment stays writable after relocation. [FreeBSD rtld](https://github.com/freebsd/freebsd-src/blob/5180fce1cf7ec7430ccf2adb88358602e5ccee1e/libexec/rtld-elf/rtld.c#L6258-L6292) makes `PT_GNU_RELRO` read-only after relocation, and what the console does with `PT_SCE_RELRO` is not checked. Both points are recorded in TechnicalDebt. Where the sample stops with this change (`--skip-sce-module`, and the same with its `sce_module`): | | `main` | this PR | |---|---|---| | Linux | output written; 0x124000–0x134000 not mapped | `Not enough program header slots: need 10, available 9` | | `--windows`, `--macos` | `ELF address is not contained in PT_LOAD memory (offset 0x130000)` | `Code analysis: overlapping instruction boundaries (offset 0xde39f)` | | `unused-filter=1` | `Init/fini array is not file-backed (offset 0x12a620)` | unchanged | On Linux the output program header table keeps the input count (9). On `main` the sample already needs `PT_GNU_EH_FRAME` dropped to fit, with the existing warning. With the segment loaded it needs 10, so it now fails with an explicit error instead of producing an image with unmapped data. Growing that table is a separate topic. The Windows and macOS code analysis stop is the "inline jump tables" item of #3093. The `unused-filter=1` and `unused-filter=2` readers parse program headers themselves and are not changed here; this is recorded in TechnicalDebt. ### Tested macOS 27 (Apple Silicon), relinker-only Release build. - ctest: 125/125. - New test `sce_relro`. It fails on `main` and passes with the change. - A standalone `PT_SCE_RELRO` that holds a RELATIVE-relocated pointer, relinked for Linux, Windows and macOS. The Linux output has one RW `PT_LOAD` at 0x1000, size 0x1000, and the relocation `(0x1000, 8, 0x210)`. - The same range covered by a RW `PT_LOAD`: no second `PT_LOAD`. - Partial overlap at the start and at the end throws, for Linux and Windows. - On Windows, the test also runs the output and expects exit code 42. That step was not run here. - OpenOrbis sample: results in the table above. The `sce_module` (`libc.prx`, `libSceFios2.prx`) converts without new errors. Not run: no x86-64 Linux or Windows host here. - `python3 tools/check_conventions.py --base origin/main` passes; `git diff --check` is clean. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) — none added - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source — none added - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes (Claude Code)
Sign in to join this conversation.
No reviewers
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!4542
No description provided.