fix(relinker): mask embedded data tables in inter-FDE gaps #8076

Merged
brainiac91 merged 8 commits from upstream-pr/8076 into main 2026-10-26 07:36:59 +00:00
brainiac91 commented 2026-10-19 20:09:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by brainiac91 on 2026-10-19T20:09:58Z.


What

Resolves #7547 ([Relinker] Crash in CodeInstructionCollector during PRX relinking on ubiservices.prx).

Compilers place constant data tables, such as the OpenSSL Whirlpool table in ubiservices.prx, in inter-FDE gaps after function code and reference them with a RIP-relative LEA. FindRelativeJumpTables treated that LEA target as gap code, so the syscall scan decoded the table bytes and CodeInstructionCollector added them as CFG roots; 0F 78 is not a valid opcode, so conversion failed.

  • Detect a table only when the bytes from the function end to the LEA target are padding, no direct branch targets it, and its linear decoding fails; mask it with 0x90 in the scan buffer in RelinkerPipeline and GuestModuleBuilder, and keep it out of the CFG roots in CodeInstructionCollector.
  • Bound the mask: it ends before a gap block that holds a syscall, or that ends where the gap turns into padding, so a stub followed by non-padding data is still scanned and refused. Chains of table bytes that only decode to a return or a jump do not end the mask.
  • Merge the unwind ranges once and binary-search them for each pending gap target instead of walking every function.
  • Read unwind records from PT_GNU_EH_FRAME as well as PT_SCE_DYNLIBDATA to locate those gaps, but keep the syscall and call-site scan ranges PT_SCE_DYNLIBDATA-only, so images without it stay strict.
  • GapAnalysis caches the per-byte padding, trailing-code and syscall state in one backward pass per gap, so the analysis is linear in gap size.

Supersedes and replaces #8042.

Tested

  • Rebased onto main 1f68b1f77; linear history, 8 commits.
  • Windows 11 host, MinGW 16.2, relinker-only build.
  • ctest --test-dir build-relinker: 301/301 passed.
  • Targeted control_flow_graph, sce_code_extent, sce_module_code_extent, executable_segments: 4/4.
  • CheckLargeZeroGaps (32 gaps of 64 KiB, 2 MiB) and the decoded-padding-suffix and stub-before-data regressions were verified to fail when their fixes are reverted. A 2 KiB table with 00/cc/90 runs and mov rax,rax; ret chains after them masks whole, and fails against the earlier terminator rule.
  • The real 2 KiB Whirlpool C0 table (constants from Linux crypto/wp512.c, public domain) in a scratch harness on this head: with the reported 0F 78 33 1E at the LEA target the mask covers all 2048 table bytes and the syscall scan finds nothing in them, while a mov eax,9; syscall; ret stub behind the table is still seen and refused; C0 on its own decodes linearly to +2046 with no 0F 05/0F 34/0F 07/CD 80 pair, so it is left unmasked.
  • Synthetic 1.2 MiB executable with 20,000 functions and 20,000 gap branch targets, same machine, median of five runs: relink 2.159 s before the binary search and 0.228 s after; the helper alone over 40,000 functions and targets takes 6.935 s and 0.190 s.
  • tools/check_conventions.py --base origin/main and git diff --check: clean.
  • The timed title comparison (PPSA21564, PPSA99420) is still outstanding: the build machine has no title inputs.

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
  • Fixes: #7547
  • Unblocks: PPSA28155 #7547
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4926753551 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8076). Originally posted by [brainiac91](https://github.com/brainiac91) on 2026-10-19T20:09:58Z. --- ### What Resolves #7547 (*[Relinker] Crash in CodeInstructionCollector during PRX relinking on ubiservices.prx*). Compilers place constant data tables, such as the OpenSSL Whirlpool table in `ubiservices.prx`, in inter-FDE gaps after function code and reference them with a RIP-relative `LEA`. `FindRelativeJumpTables` treated that `LEA` target as gap code, so the syscall scan decoded the table bytes and `CodeInstructionCollector` added them as CFG roots; `0F 78` is not a valid opcode, so conversion failed. - Detect a table only when the bytes from the function end to the `LEA` target are padding, no direct branch targets it, and its linear decoding fails; mask it with `0x90` in the scan buffer in `RelinkerPipeline` and `GuestModuleBuilder`, and keep it out of the CFG roots in `CodeInstructionCollector`. - Bound the mask: it ends before a gap block that holds a syscall, or that ends where the gap turns into padding, so a stub followed by non-padding data is still scanned and refused. Chains of table bytes that only decode to a return or a jump do not end the mask. - Merge the unwind ranges once and binary-search them for each pending gap target instead of walking every function. - Read unwind records from `PT_GNU_EH_FRAME` as well as `PT_SCE_DYNLIBDATA` to locate those gaps, but keep the syscall and call-site scan ranges `PT_SCE_DYNLIBDATA`-only, so images without it stay strict. - `GapAnalysis` caches the per-byte padding, trailing-code and syscall state in one backward pass per gap, so the analysis is linear in gap size. Supersedes and replaces #8042. ### Tested - Rebased onto `main` `1f68b1f77`; linear history, 8 commits. - Windows 11 host, MinGW 16.2, relinker-only build. - `ctest --test-dir build-relinker`: 301/301 passed. - Targeted `control_flow_graph`, `sce_code_extent`, `sce_module_code_extent`, `executable_segments`: 4/4. - `CheckLargeZeroGaps` (32 gaps of 64 KiB, 2 MiB) and the decoded-padding-suffix and stub-before-data regressions were verified to fail when their fixes are reverted. A 2 KiB table with `00`/`cc`/`90` runs and `mov rax,rax; ret` chains after them masks whole, and fails against the earlier terminator rule. - The real 2 KiB Whirlpool `C0` table (constants from Linux `crypto/wp512.c`, public domain) in a scratch harness on this head: with the reported `0F 78 33 1E` at the `LEA` target the mask covers all 2048 table bytes and the syscall scan finds nothing in them, while a `mov eax,9; syscall; ret` stub behind the table is still seen and refused; `C0` on its own decodes linearly to +2046 with no `0F 05`/`0F 34`/`0F 07`/`CD 80` pair, so it is left unmasked. - Synthetic 1.2 MiB executable with 20,000 functions and 20,000 gap branch targets, same machine, median of five runs: relink 2.159 s before the binary search and 0.228 s after; the helper alone over 40,000 functions and targets takes 6.935 s and 0.190 s. - `tools/check_conventions.py --base origin/main` and `git diff --check`: clean. - The timed title comparison (PPSA21564, PPSA99420) is still outstanding: the build machine has no title inputs. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical 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] Fixes: #7547 - [x] Unblocks: PPSA28155 #7547 - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-19 23:16:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T23:16:24Z.


I checked current head 17feca5cf4 on Ubuntu Linux with GCC 12.2 in Release relinker-only mode. Build passed for relinker, control_flow_graph_tests, and relinker_conversion_tests. Focused CTest passed 4/4: control_flow_graph, sce_code_extent, sce_module_code_extent, and executable_segments. In particular, executable_segments passes here, including the truncated rex-syscall tail that still fails on #8042. I have not run the full suite or the reported title binary, so this is focused Linux validation only.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6279456929 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8076#issuecomment-6279456929). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-19T23:16:24Z. --- I checked current head `17feca5cf4` on Ubuntu Linux with GCC 12.2 in Release relinker-only mode. Build passed for `relinker`, `control_flow_graph_tests`, and `relinker_conversion_tests`. Focused CTest passed 4/4: `control_flow_graph`, `sce_code_extent`, `sce_module_code_extent`, and `executable_segments`. In particular, `executable_segments` passes here, including the truncated `rex-syscall` tail that still fails on #8042. I have not run the full suite or the reported title binary, so this is focused Linux validation only.
wachi35676 commented 2026-10-19 23:17:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T23:17:53Z.


Verdict: defect. The mask runs past the data table into decodable code, so a forbidden syscall there is no longer refused.

For an embedded data table, FindRelativeJumpTables returns {function, table start, inspectEnd}, where inspectEnd is the next unwind function. The syscall scan masks that whole range with 0x90. HasUndecodableBytes only requires one undecodable byte in the range, so decodable code that follows the data in the same gap is masked too. That contradicts the debt line ("gaps with ... valid instructions are preserved as code and undergo strict scanning").

Probe image: make_image("register", "unwind", body=c3) from test_tls_function_coverage.py, extended to three FDEs (0x1200, 0x1300 with size 8, 0x1400 with size 1):

0x1300  48 8d 0d 09 00 00 00 c3        lea rcx,[rip+0x1310]; ret   (FDE 2)
0x1308  cc x8
0x1310  0f 78 11 22 33 44              data
0x1316  cc x10
0x1320  b8 3b 00 00 00 0f 05 c3        mov eax,59; syscall; ret    (no FDE)
0x1400  c3                             (FDE 3)
image main this PR (merged onto main 9127ea36d)
as above rc 2 Cannot decode instruction: Unsupported 0F 78 opcode without SSE4A prefix (offset 0x1310) rc 0; the output still contains b8 3b 00 00 00 0f 05
data replaced by 90 x6 (control) rc 2 Forbidden syscall instruction at code offset 0x1325: syscall number 59 rc 2, same

Both results are the same for the Linux default and --windows. Ending the masked range where the decodable code resumes, instead of at inspectEnd, would keep the refusal.

Other results:

  • Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs GCC 15.2.0 r7, relinker-only Release: ctest 212/212. Two load timeouts under -j4 (performance_compare, guest_none_relocations), which also time out on main, passed on a serial rerun. WSL Ubuntu 24.04, GCC 13.3: 216/217. The one failure, shader_cache_runtime_sources, fails intermittently on main too.
  • Negative control: with RelativeJumpTables.cpp reverted to main, control_flow_graph and sce_code_extent fail. With only the GuestModuleBuilder.cpp, RelinkerPipeline.cpp and CodeInstructionCollector.cpp changes reverted, both still pass. No test covers the PT_GNU_EH_FRAME unwind ranges, the guest-module masking, or the sceBase || !functions.empty() change.
  • The PS5 homebrew I have (PPSA99005, PPSA47402, PPSA99581, and PPSA99995 with 16 Wine modules) all have PT_GNU_EH_FRAME and no PT_SCE_DYNLIBDATA, so the new unwind-range path is active for them. Relinked with --windows --to-intel, --macos --to-rosetta and Linux --to-intel, all 12 output sets are byte-identical to main. I can't check ubiservices.prx (#7547) myself.
  • With #8042 also merged (the description says this PR supersedes it), executable_segments fails on Windows and Linux because of #8042's resync. The data probe without an LEA-referenced table then converts with a forbidden syscall left in place (see my comment on #8042). If this PR replaces #8042, closing #8042 avoids landing both.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6279477974 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8076#issuecomment-6279477974). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-19T23:17:53Z. --- Verdict: defect. The mask runs past the data table into decodable code, so a forbidden syscall there is no longer refused. For an embedded data table, `FindRelativeJumpTables` returns `{function, table start, inspectEnd}`, where `inspectEnd` is the next unwind function. The syscall scan masks that whole range with `0x90`. `HasUndecodableBytes` only requires one undecodable byte in the range, so decodable code that follows the data in the same gap is masked too. That contradicts the debt line ("gaps with ... valid instructions are preserved as code and undergo strict scanning"). Probe image: `make_image("register", "unwind", body=c3)` from `test_tls_function_coverage.py`, extended to three FDEs (0x1200, 0x1300 with size 8, 0x1400 with size 1): ``` 0x1300 48 8d 0d 09 00 00 00 c3 lea rcx,[rip+0x1310]; ret (FDE 2) 0x1308 cc x8 0x1310 0f 78 11 22 33 44 data 0x1316 cc x10 0x1320 b8 3b 00 00 00 0f 05 c3 mov eax,59; syscall; ret (no FDE) 0x1400 c3 (FDE 3) ``` | image | `main` | this PR (merged onto `main` 9127ea36d) | |---|---|---| | as above | rc 2 `Cannot decode instruction: Unsupported 0F 78 opcode without SSE4A prefix (offset 0x1310)` | rc 0; the output still contains `b8 3b 00 00 00 0f 05` | | data replaced by `90` x6 (control) | rc 2 `Forbidden syscall instruction at code offset 0x1325: syscall number 59` | rc 2, same | Both results are the same for the Linux default and `--windows`. Ending the masked range where the decodable code resumes, instead of at `inspectEnd`, would keep the refusal. Other results: - Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs GCC 15.2.0 r7, relinker-only Release: `ctest` 212/212. Two load timeouts under `-j4` (`performance_compare`, `guest_none_relocations`), which also time out on `main`, passed on a serial rerun. WSL Ubuntu 24.04, GCC 13.3: 216/217. The one failure, `shader_cache_runtime_sources`, fails intermittently on `main` too. - Negative control: with `RelativeJumpTables.cpp` reverted to `main`, `control_flow_graph` and `sce_code_extent` fail. With only the `GuestModuleBuilder.cpp`, `RelinkerPipeline.cpp` and `CodeInstructionCollector.cpp` changes reverted, both still pass. No test covers the `PT_GNU_EH_FRAME` unwind ranges, the guest-module masking, or the `sceBase || !functions.empty()` change. - The PS5 homebrew I have (PPSA99005, PPSA47402, PPSA99581, and PPSA99995 with 16 Wine modules) all have `PT_GNU_EH_FRAME` and no `PT_SCE_DYNLIBDATA`, so the new unwind-range path is active for them. Relinked with `--windows --to-intel`, `--macos --to-rosetta` and Linux `--to-intel`, all 12 output sets are byte-identical to `main`. I can't check `ubiservices.prx` (#7547) myself. - With #8042 also merged (the description says this PR supersedes it), `executable_segments` fails on Windows and Linux because of #8042's resync. The data probe without an LEA-referenced table then converts with a forbidden syscall left in place (see my comment on #8042). If this PR replaces #8042, closing #8042 avoids landing both. AI-assisted: yes (Claude Code); results above were run on this machine.
MarcZX10 commented 2026-10-19 23:20:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T23:20:03Z.


Follow-up full Linux validation on unchanged head 17feca5cf4: Release relinker-only build completed successfully, then ctest --test-dir build-relinker --output-on-failure passed 217/217. This includes the new control_flow_graph test and the executable_segments truncated-tail regression. Environment: Ubuntu Linux, GCC 12.2. I have not run the target title binary or native Windows/macOS builds.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6279506706 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8076#issuecomment-6279506706). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-19T23:20:03Z. --- Follow-up full Linux validation on unchanged head `17feca5cf4`: Release relinker-only build completed successfully, then `ctest --test-dir build-relinker --output-on-failure` passed **217/217**. This includes the new `control_flow_graph` test and the `executable_segments` truncated-tail regression. Environment: Ubuntu Linux, GCC 12.2. I have not run the target title binary or native Windows/macOS builds.
MarcZX10 commented 2026-10-19 23:21:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T23:21:25Z.


I checked this against the current head 17feca5cf4: FindRelativeJumpTables can return the data-table start with End=inspectEnd, and both scan paths fill the entire [Begin, End) interval with NOPs before calling SyscallScanner. Since the candidate is accepted when the range contains any undecodable bytes, valid code later in that same gap is hidden from the forbidden-syscall scan. Your probe demonstrates the consequence.

Please limit masking to the confirmed table bytes and preserve scanning after the table, with a regression fixture containing an embedded undecodable table followed by decodable code with a forbidden syscall before the next FDE.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6279525476 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8076#issuecomment-6279525476). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-19T23:21:25Z. --- I checked this against the current head `17feca5cf4`: `FindRelativeJumpTables` can return the data-table start with `End=inspectEnd`, and both scan paths fill the entire `[Begin, End)` interval with NOPs before calling `SyscallScanner`. Since the candidate is accepted when the range contains any undecodable bytes, valid code later in that same gap is hidden from the forbidden-syscall scan. Your probe demonstrates the consequence. Please limit masking to the confirmed table bytes and preserve scanning after the table, with a regression fixture containing an embedded undecodable table followed by decodable code with a forbidden syscall before the next FDE.
oneandonlydean commented 2026-10-20 01:22:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T01:22:10Z.


Adding one case to @wachi35676's finding, because ending the mask where decodable code resumes doesn't cover it.

On main, any instruction the decoder can't handle inside scanned code is fatal (Cannot decode instruction, rc 2). With this PR, the classification itself rests on that failure: a gap region is treated as a data table when the preceding function takes its address with a RIP-relative lea, only padding precedes it, nothing branches into it directly, and HasUndecodableBytes finds one undecodable byte anywhere before the next padding run.

A callback routine without an FDE fits all four: its address is taken with lea (that's how callbacks are passed), nothing calls it directly, it follows padding, and the decoder only needs to miss one instruction in it (any extension we don't decode yet). Today that relink fails loudly. With the PR it converts, and the whole routine, including any syscall, is skipped by SyscallScanner, which is the only check that refuses forbidden syscalls.

Could the mask cover only bytes that actually fail to decode from the table start, i.e. stop at the first offset where linear decoding succeeds through to padding or a decodable instruction run, and keep a region whose first bytes decode as code in the strict scan? A test with a lea-referenced routine that contains a syscall plus one undecodable instruction after it would pin this down.

Separately: the gate titles' executables (and the homebrew wachi35676 listed) have PT_GNU_EH_FRAME and no PT_SCE_DYNLIBDATA, so the new unwind-range path runs for every PS5 executable, including main's existing trailing-jump-table masking and the sceBase || !functions.empty() change. A test for that path, plus a relink comparison against main on the next head, would show it changes nothing beyond the tables.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6281100115 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8076#issuecomment-6281100115). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-20T01:22:10Z. --- Adding one case to @wachi35676's finding, because ending the mask where decodable code resumes doesn't cover it. On `main`, any instruction the decoder can't handle inside scanned code is fatal (`Cannot decode instruction`, rc 2). With this PR, the classification itself rests on that failure: a gap region is treated as a data table when the preceding function takes its address with a RIP-relative `lea`, only padding precedes it, nothing branches into it directly, and `HasUndecodableBytes` finds one undecodable byte anywhere before the next padding run. A callback routine without an FDE fits all four: its address is taken with `lea` (that's how callbacks are passed), nothing calls it directly, it follows padding, and the decoder only needs to miss one instruction in it (any extension we don't decode yet). Today that relink fails loudly. With the PR it converts, and the whole routine, including any `syscall`, is skipped by `SyscallScanner`, which is the only check that refuses forbidden syscalls. Could the mask cover only bytes that actually fail to decode from the table start, i.e. stop at the first offset where linear decoding succeeds through to padding or a decodable instruction run, and keep a region whose first bytes decode as code in the strict scan? A test with a `lea`-referenced routine that contains a `syscall` plus one undecodable instruction after it would pin this down. Separately: the gate titles' executables (and the homebrew wachi35676 listed) have `PT_GNU_EH_FRAME` and no `PT_SCE_DYNLIBDATA`, so the new unwind-range path runs for every PS5 executable, including main's existing trailing-jump-table masking and the `sceBase || !functions.empty()` change. A test for that path, plus a relink comparison against `main` on the next head, would show it changes nothing beyond the tables.
oneandonlydean commented 2026-10-20 08:10:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T08:10:09Z.


Thanks, the bounded table end and the callback case look right, and the relinked output for our two test titles is byte-identical to main on both the Linux and Windows targets.

One problem before merge: the relink takes much longer. For the PPSA21564 executable, --to-intel goes from 4.5 s on main to 124 s with this PR (121 s of user time, same output, one run each, reproduced by a second run on another machine slot). --windows goes from 44 s to 372 s. A profile puts 85% of the samples in FindRelativeJumpTables (with the new helpers inlined) and about 5% in the decoder.

The cause looks like OnlyPadding(code, pos, ...), which walks the whole padding run (00/CC/90) from pos. It is now called at every position: in DecodesAsTrailingCodeBlock's per-instruction loop, in both decode loops of FindEmbeddedDataTableEnd, and through the per-byte retry loops that call DecodesAsTrailingCodeBlock from every offset. A gap with long zero runs then costs at least quadratic time in the run length, and a title with a larger zero-filled gap could look hung.

Could you compute the padding-run ends once per gap (one backward pass gives, for each offset, where the run of padding bytes starting there ends), so that OnlyPadding is a lookup, and limit the per-byte retry so the whole search stays linear in the gap size? A test with a large zero-filled gap after a table (for example 1 MiB) would keep this from coming back.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6286491020 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8076#issuecomment-6286491020). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-20T08:10:09Z. --- Thanks, the bounded table end and the callback case look right, and the relinked output for our two test titles is byte-identical to `main` on both the Linux and Windows targets. One problem before merge: the relink takes much longer. For the PPSA21564 executable, `--to-intel` goes from 4.5 s on `main` to 124 s with this PR (121 s of user time, same output, one run each, reproduced by a second run on another machine slot). `--windows` goes from 44 s to 372 s. A profile puts 85% of the samples in `FindRelativeJumpTables` (with the new helpers inlined) and about 5% in the decoder. The cause looks like `OnlyPadding(code, pos, ...)`, which walks the whole padding run (`00`/`CC`/`90`) from `pos`. It is now called at every position: in `DecodesAsTrailingCodeBlock`'s per-instruction loop, in both decode loops of `FindEmbeddedDataTableEnd`, and through the per-byte retry loops that call `DecodesAsTrailingCodeBlock` from every offset. A gap with long zero runs then costs at least quadratic time in the run length, and a title with a larger zero-filled gap could look hung. Could you compute the padding-run ends once per gap (one backward pass gives, for each offset, where the run of padding bytes starting there ends), so that `OnlyPadding` is a lookup, and limit the per-byte retry so the whole search stays linear in the gap size? A test with a large zero-filled gap after a table (for example 1 MiB) would keep this from coming back.
screamm commented 2026-10-20 13:43:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-20T13:43:07Z.


Windows run of head e4034102a, which is the head @oneandonlydean timed. It no longer merges into main d50ec76da: besides docs/dev/debt/relinker.md, GuestModuleBuilder.cpp and RelinkerPipeline.cpp conflict with #7660 (SceUnwindRanges is now passed to the syscall scanner). I therefore built the head as-is and compared it with its merge-base 585075cb7. That base relinks every title below in the same time as main d50ec76da and to the same bytes, so the ratios also hold against current main.

Host: Windows 11 Pro 26220, Ryzen 7 5700X, NVIDIA GeForce RTX 4070 driver 596.21, WinLibs MinGW-w64 GCC 15.2 r7, Release, relinker-only build (-DANYPS5_RELINKER_ONLY=ON).

  • PR tests: control_flow_graph, executable_segments, sce_code_extent and sce_module_code_extent each passed 3/3.
  • Output: I relinked 51 local homebrew titles (every one with an eboot.elf, including PPSA99005 and PPSA99995 with its 16 Wine modules) for the default Linux target and for --windows. Every output file has the same sha256 as the base and as main. PPSA99360 --windows fails the same way on all builds (Base relocation target crosses a page boundary).
  • Relink time: the regression reproduces natively on Windows; no title is faster with the PR. Base and PR ran side by side for each sample. The 5 largest executables ran 3 times each and the rest once; figures are medians.
base PR ratio
default target, sum over 51 titles (wall) 119.6 s 450.0 s 3.76x
default target, sum (user CPU) 14.7 s 269.1 s 18.3x
--windows, sum over 51 titles (wall) 834.6 s 1481.1 s 1.77x
--windows, sum (user CPU) 535.2 s 1023.0 s 1.91x
PPSA99420 (105 MiB eboot), default 1.92 s 57.31 s 29.9x
PPSA99420, --windows 49.99 s 153.19 s 3.06x
PPSA99008 (72 MiB), --windows 34.34 s 77.54 s 2.26x
PPSA99004 (139 MiB), --windows 18.29 s 36.70 s 2.01x

The per-title median ratio is 3.06x (default) and 1.57x (--windows), and no title got faster. The cost does not follow file size: PPSA99420 gains 55 s on the default target, while the larger PPSA99004 gains 9.5 s.

  • Boots (--windows, 60 s each, RTX 4070): PPSA99005 and PPSA99995 relinked by the PR were still running at 60 s (158 and 34 frames; main gave 162 and 41 on the same loaded host), and neither printed a stop line.
  • python tools/check_conventions.py --base 585075cb7 passes, and git diff --check is clean.

Not checked: ubiservices.prx (#7547) and PPSA21564 (I don't have them), a profile, a rebase onto current main, macOS output, and the full relinker suite (a -j3 run was cut short by a host problem after 87/212 had passed).

Written with Claude Code assistance (validation by a subagent, reviewed in this session).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6292285341 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8076#issuecomment-6292285341). Originally posted by [screamm](https://github.com/screamm) on 2026-10-20T13:43:07Z. --- Windows run of head `e4034102a`, which is the head @oneandonlydean timed. It no longer merges into `main` `d50ec76da`: besides `docs/dev/debt/relinker.md`, `GuestModuleBuilder.cpp` and `RelinkerPipeline.cpp` conflict with #7660 (`SceUnwindRanges` is now passed to the syscall scanner). I therefore built the head as-is and compared it with its merge-base `585075cb7`. That base relinks every title below in the same time as `main` `d50ec76da` and to the same bytes, so the ratios also hold against current `main`. Host: Windows 11 Pro 26220, Ryzen 7 5700X, NVIDIA GeForce RTX 4070 driver 596.21, WinLibs MinGW-w64 GCC 15.2 r7, Release, relinker-only build (`-DANYPS5_RELINKER_ONLY=ON`). - **PR tests:** `control_flow_graph`, `executable_segments`, `sce_code_extent` and `sce_module_code_extent` each passed 3/3. - **Output:** I relinked 51 local homebrew titles (every one with an `eboot.elf`, including PPSA99005 and PPSA99995 with its 16 Wine modules) for the default Linux target and for `--windows`. Every output file has the same sha256 as the base and as `main`. PPSA99360 `--windows` fails the same way on all builds (`Base relocation target crosses a page boundary`). - **Relink time:** the regression reproduces natively on Windows; no title is faster with the PR. Base and PR ran side by side for each sample. The 5 largest executables ran 3 times each and the rest once; figures are medians. | | base | PR | ratio | |---|---|---|---| | default target, sum over 51 titles (wall) | 119.6 s | 450.0 s | 3.76x | | default target, sum (user CPU) | 14.7 s | 269.1 s | 18.3x | | `--windows`, sum over 51 titles (wall) | 834.6 s | 1481.1 s | 1.77x | | `--windows`, sum (user CPU) | 535.2 s | 1023.0 s | 1.91x | | PPSA99420 (105 MiB eboot), default | 1.92 s | 57.31 s | 29.9x | | PPSA99420, `--windows` | 49.99 s | 153.19 s | 3.06x | | PPSA99008 (72 MiB), `--windows` | 34.34 s | 77.54 s | 2.26x | | PPSA99004 (139 MiB), `--windows` | 18.29 s | 36.70 s | 2.01x | The per-title median ratio is 3.06x (default) and 1.57x (`--windows`), and no title got faster. The cost does not follow file size: PPSA99420 gains 55 s on the default target, while the larger PPSA99004 gains 9.5 s. - **Boots** (`--windows`, 60 s each, RTX 4070): PPSA99005 and PPSA99995 relinked by the PR were still running at 60 s (158 and 34 frames; `main` gave 162 and 41 on the same loaded host), and neither printed a stop line. - `python tools/check_conventions.py --base 585075cb7` passes, and `git diff --check` is clean. Not checked: `ubiservices.prx` (#7547) and PPSA21564 (I don't have them), a profile, a rebase onto current `main`, macOS output, and the full relinker suite (a `-j3` run was cut short by a host problem after 87/212 had passed). Written with Claude Code assistance (validation by a subagent, reviewed in this session).
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!8076
No description provided.