fix(relinker): map standalone RELRO in unused import filtering #4717

Merged
Ondra97 merged 1 commit from upstream-pr/4717 into main 2026-10-14 03:05:02 +00:00
Ondra97 commented 2026-10-12 19:42:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-12T19:42:20Z.


What

unused-filter=1 could not read relocation tables or lifecycle arrays placed in a standalone PT_SCE_RELRO segment, even though the executable reader already maps that segment as a load segment. Reuse ElfReader::ReadProgramHeaders() in the relative relocation index and entry-point collector, so filtering uses the same mappings as conversion. Remove the obsolete filter limitation from technical debt.

Initialize e_version=1 and e_ehsize=64 in the separate relative-relocation bounds fixture. After #4441 added these header checks, that hand-built fixture still left both fields zero; using the shared reader exposed it before its positive bounds assertions. Keep the production header validation and all existing relocation-boundary assertions unchanged.

Tested

Windows, MinGW-w64 GCC 15.2.0, Release, relinker-only, main 2a2a3dc65. Full build exits 0 and all 140 CTests pass in 24.40 s, including strict_nid_filter, elf_header, elf_reader_bounds, sce_relro, unused_filter_indirect and init_array_roots.

The review-reported failure was reproduced before correcting the fixture: strict_nid_filter exited 1 with Unsupported ELF object version: expected 1. The original 135-test Windows run included strict_nid_filter, but its base predates #4441's new object-version and header-size guards. Linux execution was not run locally.

Before the RELRO mapping fix, the added relocation and lifecycle cases failed with unmapped-address errors. The regressions cover standalone and already-covered RELRO, relocation tables, init arrays and filters 0, 1 and 2; retained imports are checked through the registry. git diff --check and committed branch/PR conventions pass. No game or console was run; no performance improvement is claimed.

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 under Silent stubs in their library's technical debt file
  • 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
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes. — Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4834195739 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4717). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-10-12T19:42:20Z. --- ### What `unused-filter=1` could not read relocation tables or lifecycle arrays placed in a standalone `PT_SCE_RELRO` segment, even though the executable reader already maps that segment as a load segment. Reuse `ElfReader::ReadProgramHeaders()` in the relative relocation index and entry-point collector, so filtering uses the same mappings as conversion. Remove the obsolete filter limitation from technical debt. Initialize `e_version=1` and `e_ehsize=64` in the separate relative-relocation bounds fixture. After #4441 added these header checks, that hand-built fixture still left both fields zero; using the shared reader exposed it before its positive bounds assertions. Keep the production header validation and all existing relocation-boundary assertions unchanged. ### Tested Windows, MinGW-w64 GCC 15.2.0, Release, relinker-only, main 2a2a3dc65. Full build exits 0 and all 140 CTests pass in 24.40 s, including strict_nid_filter, elf_header, elf_reader_bounds, sce_relro, unused_filter_indirect and init_array_roots. The review-reported failure was reproduced before correcting the fixture: strict_nid_filter exited 1 with `Unsupported ELF object version: expected 1`. The original 135-test Windows run included strict_nid_filter, but its base predates #4441's new object-version and header-size guards. Linux execution was not run locally. Before the RELRO mapping fix, the added relocation and lifecycle cases failed with unmapped-address errors. The regressions cover standalone and already-covered RELRO, relocation tables, init arrays and filters 0, 1 and 2; retained imports are checked through the registry. `git diff --check` and committed branch/PR conventions pass. No game or console was run; no performance improvement is claimed. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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 - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes. — Codex
nicolasfalesy commented 2026-10-13 08:28:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-13T08:28:01Z.


Linux test (Arch, GCC 16.2.1, Release), this PR's head merged alone onto main 7e181fcc3 (clean merge): strict_nid_filter fails. Its last case prints Unsupported ELF object version: expected 1 after the two passing reachability cases. It passes on main on the same machine. The Windows run above was a relinker-only build; this test may not have been part of it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6141505237 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4717#issuecomment-6141505237). Originally posted by [nicolasfalesy](https://github.com/nicolasfalesy) on 2026-10-13T08:28:01Z. --- Linux test (Arch, GCC 16.2.1, Release), this PR's head merged alone onto `main` 7e181fcc3 (clean merge): `strict_nid_filter` fails. Its last case prints `Unsupported ELF object version: expected 1` after the two passing reachability cases. It passes on `main` on the same machine. The Windows run above was a relinker-only build; this test may not have been part of it.
Ondra97 commented 2026-10-13 09:25:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-13T09:25:14Z.


Thanks for catching this. I reproduced the failure after rebasing onto current main. The relative-relocation bounds fixture left e_version and e_ehsize at zero, which became invalid after #4441 added those checks.

Fixed in bde680c85 by initializing both fields. Production validation and the existing bounds assertions remain unchanged. The full Windows relinker build and all 140 CTests now pass. I have not run Linux locally.

The earlier 135-test run did include strict_nid_filter, but its base predated those new header checks.

AI-assisted: yes. — Codex

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6142475003 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4717#issuecomment-6142475003). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-10-13T09:25:14Z. --- Thanks for catching this. I reproduced the failure after rebasing onto current main. The relative-relocation bounds fixture left `e_version` and `e_ehsize` at zero, which became invalid after #4441 added those checks. Fixed in bde680c85 by initializing both fields. Production validation and the existing bounds assertions remain unchanged. The full Windows relinker build and all 140 CTests now pass. I have not run Linux locally. The earlier 135-test run did include `strict_nid_filter`, but its base predated those new header checks. AI-assisted: yes. — Codex
adriadam10 commented 2026-10-13 15:12:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T15:12:28Z.


Checked on this head merged onto current main: relinker build and tests pass (124/124 in scope). With the production changes reverted, sce_relro fails (the new filter cases hit unmapped addresses) and passes with them; strict_nid_filter passes with the fixture fix, as expected. Relinker CI is green on Linux, Windows and macOS. Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148756260 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4717#issuecomment-6148756260). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T15:12:28Z. --- Checked on this head merged onto current `main`: relinker build and tests pass (124/124 in scope). With the production changes reverted, `sce_relro` fails (the new filter cases hit unmapped addresses) and passes with them; `strict_nid_filter` passes with the fixture fix, as expected. Relinker CI is green on Linux, Windows and macOS. Merging once the full Build is green.
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!4717
No description provided.