fix(relinker): read SCE dynamic tables from PT_SCE_DYNLIBDATA #3141

Merged
MarcZX10 merged 2 commits from upstream-pr/3141 into main 2026-10-11 07:15:56 +00:00
MarcZX10 commented 2026-10-10 22:58:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T22:58:48Z.


What

Read DT_SCE_* dynamic-table values relative to PT_SCE_DYNLIBDATA when that PS4 segment is present, while preserving the current file-offset behavior for executables without it. The parser rejects a table range that extends beyond the input file and rejects duplicate PT_SCE_DYNLIBDATA segments instead of silently choosing the last base.

Carried Get-fix's issue-linked commit from fix/relinker-sce-dynamic-tables; the original commit author is preserved. The unused-filter=1 and unused-filter=2 readers remain documented as follow-up work.

Tested

Linux, GCC 12.2, Release: the relinker-only build and all 105 CTests pass, including the arithmetic overflow, out-of-file table, and duplicate-segment cases. Conventions and git diff --check pass.

Windows 11, WinLibs GCC 15.2, Release, on updated head 16adcd48 merged onto current main: string_table_bounds, elf_header, elf_offsets, windows_import_modules, and guest_elf_phdr_match pass. The non-GPU suite is 420/421; guest_filesystem also fails on plain main on that host because it lacks symlink privilege (#3169).

Checklist

  • Based on current main; no other open pull request implements this PS4 table handling
  • One topic per pull request
  • Conventions and diff checks pass; no code comments added
  • No silent stubs added
  • No investigation files or images added
  • No third-party code added
  • Generic behavior gated on PT_SCE_DYNLIBDATA
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4815040803 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3141). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T22:58:48Z. --- ### What Read `DT_SCE_*` dynamic-table values relative to `PT_SCE_DYNLIBDATA` when that PS4 segment is present, while preserving the current file-offset behavior for executables without it. The parser rejects a table range that extends beyond the input file and rejects duplicate `PT_SCE_DYNLIBDATA` segments instead of silently choosing the last base. Carried Get-fix's issue-linked commit from `fix/relinker-sce-dynamic-tables`; the original commit author is preserved. The `unused-filter=1` and `unused-filter=2` readers remain documented as follow-up work. ### Tested Linux, GCC 12.2, Release: the relinker-only build and all 105 CTests pass, including the arithmetic overflow, out-of-file table, and duplicate-segment cases. Conventions and `git diff --check` pass. Windows 11, WinLibs GCC 15.2, Release, on updated head `16adcd48` merged onto current `main`: `string_table_bounds`, `elf_header`, `elf_offsets`, `windows_import_modules`, and `guest_elf_phdr_match` pass. The non-GPU suite is 420/421; `guest_filesystem` also fails on plain `main` on that host because it lacks symlink privilege (#3169). ### Checklist - [x] Based on current `main`; no other open pull request implements this PS4 table handling - [x] One topic per pull request - [x] Conventions and diff checks pass; no code comments added - [x] No silent stubs added - [x] No investigation files or images added - [x] No third-party code added - [x] Generic behavior gated on `PT_SCE_DYNLIBDATA` - [x] Depends on: none - [x] AI-assisted: yes
Dextroid17 commented 2026-10-10 23:19:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-10T23:19:00Z.

Review: COMMENTED


Two PRs from one carried branch, both about the same thing: what PT_SCE_DYNLIBDATA means for a PS4 executable. Read together they are one idea — that segment defines a block whose offsets are relative to it — applied to the dynamic-table base and to the code scan.

#3141, the table base. Reading DT_SCE_* relative to PT_SCE_DYNLIBDATA when the segment is present, and keeping file offsets when it is not, is the difference between a PS4 executable's tables resolving and everything downstream resolving to the wrong place, so the shape is right. Guarding the addition against overflow is the correct check to have first, and the range checks further down (Dynamic string table is out of bounds and its siblings) still bound the result against the file, so between them they cover both halves. The one thing I would change is the message: "outside the file" is only what the overflow path tests, and naming the arithmetic it actually guards would read truer. Also, the base is taken from the last PT_SCE_DYNLIBDATA seen; if more than one is legal, a uniqueness requirement would match the requireExactlyOneOf shape used elsewhere in this file.

#3142, the code scan. Limiting the scan by the .eh_frame function extents and finding the PLT by its actual bytes is the honest version of this: the pattern you look for — ff 35 … ff 25 with the two displacements landing at GOT+8 and GOT+16 — is the real PLT0/PLT1 pair, and bounding the search to size - 16 keeps the whole 16-byte header in range. Requiring a located PLT when relocations need one, rather than guessing at an extent, is the part I would single out: a wrong scan boundary is silent, and an error is not.

On the test result both descriptions mention. The single failing test, import_audit, expects a source_commit stamp that already exists on main, and it fails when git cannot resolve HEAD for the audited root — so it is an environment difference rather than anything in these branches, which is what both descriptions say and the right reason to give. The mutation and byte-identical conversion checks are attributed in both bodies to the source author in #3093, which is also the right place for them.

And the provenance is handled properly in both — Get-fix's issue-linked commits carried with authorship intact, and the remaining limitations in --to-intel and the unused-filter readers left documented rather than quietly widened by the new scan boundary.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5481161949 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3141#pullrequestreview-5481161949). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-10T23:19:00Z. **Review:** COMMENTED --- Two PRs from one carried branch, both about the same thing: what `PT_SCE_DYNLIBDATA` means for a PS4 executable. Read together they are one idea — that segment defines a block whose offsets are relative to it — applied to the dynamic-table base and to the code scan. **#3141, the table base.** Reading `DT_SCE_*` relative to `PT_SCE_DYNLIBDATA` when the segment is present, and keeping file offsets when it is not, is the difference between a PS4 executable's tables resolving and everything downstream resolving to the wrong place, so the shape is right. Guarding the addition against overflow is the correct check to have first, and the range checks further down (`Dynamic string table is out of bounds` and its siblings) still bound the result against the file, so between them they cover both halves. The one thing I would change is the message: "outside the file" is only what the overflow path tests, and naming the arithmetic it actually guards would read truer. Also, the base is taken from the last `PT_SCE_DYNLIBDATA` seen; if more than one is legal, a uniqueness requirement would match the `requireExactlyOneOf` shape used elsewhere in this file. **#3142, the code scan.** Limiting the scan by the `.eh_frame` function extents and finding the PLT by its actual bytes is the honest version of this: the pattern you look for — `ff 35` … `ff 25` with the two displacements landing at GOT+8 and GOT+16 — is the real PLT0/PLT1 pair, and bounding the search to `size - 16` keeps the whole 16-byte header in range. Requiring a located PLT when relocations need one, rather than guessing at an extent, is the part I would single out: a wrong scan boundary is silent, and an error is not. **On the test result both descriptions mention.** The single failing test, `import_audit`, expects a `source_commit` stamp that already exists on `main`, and it fails when git cannot resolve `HEAD` for the audited root — so it is an environment difference rather than anything in these branches, which is what both descriptions say and the right reason to give. The mutation and byte-identical conversion checks are attributed in both bodies to the source author in #3093, which is also the right place for them. **And the provenance is handled properly in both** — Get-fix's issue-linked commits carried with authorship intact, and the remaining limitations in `--to-intel` and the `unused-filter` readers left documented rather than quietly widened by the new scan boundary. Written with AI assistance.
Silverash-i8 commented 2026-10-11 01:51:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T01:51:18Z.


Windows run, since the PR has no Windows results yet: Windows 11, WinLibs GCC 15.2.0 r7, Release, merged onto main d31b57a4 in one build with #3213, #3159, #3158, #3142, #3141 and #2977, on an RTX 5060 Laptop and the Arrow Lake iGPU (ANYPS5_GPU=Intel).

  • string_table_bounds and sce_code_extent pass on Windows (they don't use the GPU).

In the full ctest of that build, the only failure not also on plain main is agc_driver_dcc_keys_first_write, which I bisected to #3158 alone (reported there).

AI-assisted (Claude Code); I ran this on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104356492 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3141#issuecomment-6104356492). Originally posted by [Silverash-i8](https://github.com/Silverash-i8) on 2026-10-11T01:51:18Z. --- Windows run, since the PR has no Windows results yet: Windows 11, WinLibs GCC 15.2.0 r7, Release, merged onto `main` d31b57a4 in one build with #3213, #3159, #3158, #3142, #3141 and #2977, on an RTX 5060 Laptop and the Arrow Lake iGPU (`ANYPS5_GPU=Intel`). - `string_table_bounds` and `sce_code_extent` pass on Windows (they don't use the GPU). In the full `ctest` of that build, the only failure not also on plain `main` is `agc_driver_dcc_keys_first_write`, which I bisected to #3158 alone (reported there). AI-assisted (Claude Code); I ran this on my machine.
MarcZX10 commented 2026-10-11 03:30:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T03:30:52Z.


I addressed both review suggestions in 16adcd487 (fix(relinker): validate SCE dynamic data segment). The offset error now names the arithmetic it checks, and the tests distinguish addition overflow from a non-overflowing out-of-file table. The parser also rejects a second PT_SCE_DYNLIBDATA instead of silently replacing the first base; the documented PS4 ELF layout lists a single segment. The relinker-only Release build and all 105 CTests pass on current main, including the new overflow and duplicate-segment cases. Conventions and git diff --check pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6105040209 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3141#issuecomment-6105040209). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T03:30:52Z. --- I addressed both review suggestions in `16adcd487` (`fix(relinker): validate SCE dynamic data segment`). The offset error now names the arithmetic it checks, and the tests distinguish addition overflow from a non-overflowing out-of-file table. The parser also rejects a second `PT_SCE_DYNLIBDATA` instead of silently replacing the first base; the documented PS4 ELF layout lists a single segment. The relinker-only Release build and all 105 CTests pass on current `main`, including the new overflow and duplicate-segment cases. Conventions and `git diff --check` pass.
Silverash-i8 commented 2026-10-11 03:37:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T03:37:56Z.


Windows check of the updated head 16adcd48 (merged onto current main, Windows 11, WinLibs GCC 15.2.0 r7, Release): string_table_bounds passes with the new overflow and duplicate-segment cases, along with elf_header, elf_offsets, windows_import_modules and guest_elf_phdr_match.

The whole non-GPU suite (ctest -E "^agc_") is 420/421; the one failure is guest_filesystem, which needs the symlink privilege on Windows (#3169) and fails the same way on main here.

AI-assisted (Claude Code); I ran this on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6105088500 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3141#issuecomment-6105088500). Originally posted by [Silverash-i8](https://github.com/Silverash-i8) on 2026-10-11T03:37:56Z. --- Windows check of the updated head `16adcd48` (merged onto current `main`, Windows 11, WinLibs GCC 15.2.0 r7, Release): `string_table_bounds` passes with the new overflow and duplicate-segment cases, along with `elf_header`, `elf_offsets`, `windows_import_modules` and `guest_elf_phdr_match`. The whole non-GPU suite (`ctest -E "^agc_"`) is 420/421; the one failure is `guest_filesystem`, which needs the symlink privilege on Windows (#3169) and fails the same way on `main` here. AI-assisted (Claude Code); I ran this on my machine.
MarcZX10 commented 2026-10-11 03:44:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T03:44:15Z.


Thanks for rerunning the updated head on Windows and for separating the unrelated symlink-privilege failure from this change. I added the passing string_table_bounds and adjacent ELF checks, plus the 420/421 non-GPU suite result and its plain-main guest_filesystem limitation, to the Tested section.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6105131395 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3141#issuecomment-6105131395). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T03:44:15Z. --- Thanks for rerunning the updated head on Windows and for separating the unrelated symlink-privilege failure from this change. I added the passing `string_table_bounds` and adjacent ELF checks, plus the 420/421 non-GPU suite result and its plain-main `guest_filesystem` limitation, to the Tested section.
adriadam10 commented 2026-10-11 07:15:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:15:53Z.


Checked the new string_table_bounds cases (tables in the SCE block, addition overflow, out-of-file table, duplicate segment); they fail without the change and pass with it. The relinker build and ctest are green locally, and Windows was confirmed by @Silverash-i8; merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106584173 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3141#issuecomment-6106584173). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T07:15:53Z. --- Checked the new `string_table_bounds` cases (tables in the SCE block, addition overflow, out-of-file table, duplicate segment); they fail without the change and pass with it. The relinker build and ctest are green locally, and Windows was confirmed by @Silverash-i8; merging once CI 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!3141
No description provided.