Skip to content

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

Merged
oneandonlydean merged 8 commits into
boykopovar:mainfrom
brainiac91:fix/relinker-embedded-data-tables
Oct 26, 2026
Merged

oneandonlydean merged 8 commits into
boykopovar:mainfrom
brainiac91:fix/relinker-embedded-data-tables

Conversation

@brainiac91

@brainiac91 brainiac91 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot added the unblocks title Names a title ID on the Unblocks line label Oct 19, 2026
@brainiac91 brainiac91 changed the title fix(relinker): mask embedded data tables in inter-FDE gaps (#7547) fix(relinker): mask embedded data tables in inter-FDE gaps Oct 19, 2026
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 10792 core/relinker/relinker/src/guest/GuestModuleBuilder.cpp L409-410
PR 10861 core/relinker/relinker/src/guest/GuestModuleBuilder.cpp L403, L408-410
core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp L397-398, L402-408
docs/dev/debt/relinker.md L33-34

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 docs/dev/debt/relinker.md

@github-actions github-actions Bot added fix error Closes an issue (Fixes #N) relinker docs labels Oct 19, 2026
@MarcZX10

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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 9127ea3)
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:

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

@MarcZX10

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Collaborator

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.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 20, 2026
@screamm

screamm commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

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).

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@brainiac91 I checked the rebase and the backward gap analysis. The scanner ranges stay SCE-only and the repeated suffix walks are gone, but the new trailing state loses one case the old walk preserved.

For b8 3b 00 00 00 0f 05 00 01 90, the suffix is mov eax,59; syscall; add byte ptr [rcx],al; nop. The 00 01 instruction is not a padding suffix: its second byte is 01. Its decoded successor is padding, though, so RelativeJumpTables.cpp:162–164 gives it Trailing::Padding while padding[pos] is false. Lines 158–160 then copy that state back over the syscall. The old walk kept its preceding terminator when an instruction started with 00; the new query returns false. In a LEA-referenced table candidate that starts with undecodable bytes, the fallback at 239–244 can therefore extend the mask over this syscall.

Could you preserve the old state through this case and add a regression with a table prefix followed by that suffix, requiring the mask to end before the syscall and the relinker to refuse it? Please cover both the executable and guest-module routes and keep the large-gap test. I checked the byte sequence with objdump and replayed the source recurrence; I have not run the full relinker counterexample because the shared build slot is occupied.

The timed output comparisons against current main on both targets are still needed after the fix; the synthetic timing result does not replace them.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 25, 2026
@plexerPK

Copy link
Copy Markdown
Contributor

The recurrence issue now reproduces through both actual conversion routes at exact head c8de02cba916afac9879fe0ae885f530df832443, not only the table helper.

I reused the existing fixture(gap_embedded_data=True) and sce_module(gap_embedded_data=True) builders and replaced the gap with 0f 78 cc b8 09 00 00 00 0f 05 00 01 90, followed by NOP padding to the next FDE. Data-only controls use 0f 78 33 1e followed by that same padding.

Route c8de02c One-line correction
SCE executable, Linux/Windows/macOS outputs All three convert successfully All three refuse syscall 9 at 0x228
SysV executable, Linux/Windows/macOS outputs All three convert successfully All three refuse syscall 9 at 0x228
Guest module, Linux/Windows/macOS outputs All three convert successfully All three refuse syscall 9 at 0x1028

The corrected cases return exit 2 with Forbidden syscall instruction; all nine data-only controls still return exit 0 on both builds. That is 36 conversions total. Only the previously suggested one-line recurrence correction differs between the builds.

The existing sce_code_extent, sce_module_code_extent and control_flow_graph suites still pass with the correction (3/3); the latter includes the retained large-gap performance test and completed in 0.21 s locally. Please add executable and guest regression variants with this decoded-padding suffix so the suite guards the actual refusal paths too.

This is synthetic conversion evidence on macOS arm64; I did not execute the generated guest code, use title/proprietary inputs, or test a combined-main tree.

trailing[next] is Padding for an instruction that starts with 00 or CC
even when the rest of its bytes are code, so it is not the same as
padding[next]. The recurrence treated the two as interchangeable and
overwrote the trailing state of a syscall that precedes such an
instruction, which let the fallback extend the mask over it and made
both conversion routes accept the gap. Decide from the trailing state
whether the successor is padding.

The regression covers the table helper plus the executable and guest
module routes; without the correction the executable and module
conversions succeed instead of refusing syscall 9.
@brainiac91

brainiac91 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Good catch, both of you. padding[next] and trailing[next] == Padding aren't interchangeable: an instruction starting with 00/CC gets the latter while padding stays false, which copied that state back over the syscall. Fixed in 640577c3e with exactly the one-line change you proposed.

Added the helper test plus executable (SCE and SysV) and guest-module regressions. Reverting the fix makes the executable and module cases convert instead of refusing syscall 9, so they guard the real path.

301/301 ctest, conventions and git diff --check clean. @plexerPK, the large-gap test classifies 32 tables rather than exercising 32 rejection paths - strictly more work, so it still catches a quadratic walk. Say the word if you want the rejection variant too.

The real-title timings are still outstanding. No title inputs here, so PPSA21564 / PPSA99420 need a run on your side.

@plexerPK

Copy link
Copy Markdown
Contributor

Verified 640577c3ecfd4cdf443224d59ef90f1f0e0cd75d: the production sources and build inputs match the one-line corrected tree I tested; only the three regression files differ. I ran those new tests against both production variants. control_flow_graph, sce_code_extent and sce_module_code_extent each fail on the old c8de02cb production and pass with the correction (0.213 s, 0.460 s and 0.177 s locally). The executable and module failures are the previously incorrect successful conversion of the syscall fixture. This closes my recurrence finding.

I do not require an additional large-gap rejection variant for this correction. The retained acceptance fixture exercises the cached analysis and trailing retries; I found no concrete uncovered superlinear path, and the earlier rejection-path proof remains available.

These are synthetic macOS arm64 unit/conversion checks, using production-identical binaries for the Python suites and rebuilding the new C++ test against matching sources. They are not a combined-main build, generated guest execution or hosted CI. I do not have the requested title inputs, so I cannot supply PPSA21564/PPSA99420 timings; those measurements remain outstanding.

@brainiac91

Copy link
Copy Markdown
Contributor Author

Thanks for re-running both trees — that closes it on my side too. Agreed on the large-gap variant; I'll leave the current fixture as is.

Only the PPSA21564 / PPSA99420 timings are left, and none of us has the inputs, so @oneandonlydean or @screamm will need to run those when a build slot is free.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@brainiac91 Thanks for tracking this down. Two things I'd like to see before this goes in:

  1. In FindRelativeJumpTables the loop over pending branch targets walks the whole functions vector for every target to test whether it is inside a known function. The vector is sorted, so a binary search would make that O(targets log functions) instead of O(targets x functions). Could you switch it and attach before/after relink times for a large executable?
  2. When a code block in the gap (for example a syscall stub with no unwind record) is followed by something that is not padding, such as a constant pool or a second table, GapAnalysis classes the block as invalid and the mask then runs to the end of the gap, which hides that block's syscall from the scan. Could the mask stop at the first block that ends in a return, jump, trap or syscall, or refuse to mask when the rest of the gap is not table-shaped? A test with a syscall stub followed by non-padding data would cover it.

@plexerPK

Copy link
Copy Markdown
Contributor

The second condition also reproduces through the actual relinker routes at 640577c3ecfd4cdf443224d59ef90f1f0e0cd75d. The synthetic table prefix and tail are:

0f 78 cc b8 09 00 00 00 0f 05 c3 0f 78 33 1e

That is undecodable table data, padding, mov eax,9; syscall; ret, then further undecodable non-padding data. NOPs fill the rest of the inter-FDE gap.

All nine syscall fixtures currently convert successfully: SCE executable, SysV executable and guest module, each targeting Linux, Windows and macOS. All nine data-only controls also succeed. Our earlier 70de97e3b7 build gives the same route results. At the public table helper, original e4034102ac, our 70de97e3b7 and corrected 640577c3ec all return [0x1010,0x1030), covering the syscall at 0x1018.

This is therefore a pre-existing table-classification limitation preserved by the optimization, separate from the recurrence regression fixed in 640577c3ec. The useful acceptance criterion is that later non-padding bytes must not extend the table mask over an earlier syscall block: stop the mask before that block, or conservatively refuse the candidate. Please exercise both real conversion routes and retain the existing decoded-padding and large-gap tests.

These are synthetic conversion checks on macOS arm64, without guest execution, proprietary/title inputs or a combined-main build. The original e4034102ac comparison is helper-level only; the full conversion comparisons use the two builds named above.

Every pending gap target walked the whole unwind function vector, so a
large executable cost targets x functions. Sort and merge the ranges once,
then use upper_bound for each target.
A gap that holds a table, padding and then a syscall stub followed by
non-padding data classified the stub as invalid, so the mask ran to the end
of the gap and hid the syscall from the scan. Mark any instruction that ends
control flow as a terminator, which stops the mask before that block.

Covered by the helper test and by the SCE, SysV and guest-module conversion
tests, which convert before the change and refuse syscall 9 after it.
@brainiac91

Copy link
Copy Markdown
Contributor Author

Both done, head 3cb3e8f53.

Binary search is in: the unwind ranges are sorted and merged once, then upper-bounded per pending target. Synthetic 1.2 MiB executable, 20,000 functions and 20,000 gap branch targets, median of five runs on this machine: 2.159 s before, 0.228 s after. The helper alone at 40,000 functions and targets goes 6.935 s to 0.190 s. I have no PPSA21564/PPSA99420 inputs here, so that is as close to a title comparison as I can get.

The mask now ends before any block that ends in a jump, return, trap or syscall, even when non-padding data follows it. @plexerPK's exact bytes are in the helper test, both executable routes and the guest module; all of them convert before the change and refuse syscall 9 after it.

One trade-off: table bytes that look like a padding run followed by a terminator block can now end the mask early, which surfaces as a decode failure instead of a hidden syscall. Say the word if you would rather refuse the candidate in that case.

301/301 ctest, conventions and diff check clean.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@brainiac91 On the timings: I don't have PPSA99420, so the relink timing we can run is PPSA21564 (main vs this PR, Linux and Windows, plus a byte-compare of the output). I'll run it on the head that addresses the two points in my earlier comment and post the numbers here.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@brainiac91 Thanks, the binary search is exactly what I meant and the syscall-stub case now works.

One new concern with ending the mask at any terminator: a position now counts as a trailing code block when valid decoding from just after a pad run reaches any ret, jump, trap or syscall, even if non-padding data follows. Real tables have 00/cc/90 bytes, so this can trigger inside a table. As a rough check I generated the standard Whirlpool table (2 KB, same layout as the one in ubiservices) and swept the bytes after each pad run with objdump: two of the 15 runs, around offsets 952 and 957, lead into a valid chain that ends in a ret. If the relinker decoder agrees, the mask would stop there and leave the rest of that table unmasked, which is the original failure. I could not run the real relinker decoder or ubiservices.prx, so please check it.

Could you (1) tighten the trailing-block test, for example by requiring a 16-byte aligned start after at least one pad byte, or a minimum run of valid instructions; (2) add a test that uses a realistic table containing 00/cc/90 and ret-like bytes and asserts the whole table is masked; and (3) relink the real ubiservices.prx on this head?

@plexerPK

Copy link
Copy Markdown
Contributor

Verified exact head 3cb3e8f53ba29296f07676428d349b851850987c. All nine non-padding-tail syscall cases now refuse syscall 9 with exit 2 and no output; all nine data-only controls still convert. The three focused suites pass, including both masking regressions and the large-gap test (0.84 s total, control_flow_graph 0.20 s). Running the updated tests against previous 640577c3ec production fails each suite at its new non-padding-tail assertion, after the earlier decoded-padding checks pass. This closes my second masking finding.

The merged-range lookup matches the previous linear membership predicate in 1,320,000 synthetic comparisons using the extracted source, including unsorted/nested/adjacent/empty/reversed ranges, endpoints and uint64_t limits. I found no material issue in the scoped change. Conservatively stopping the mask when bytes look like terminating code is consistent with refusing ambiguous input; I am not requesting a different policy without a concrete failing case.

This is macOS arm64 synthetic conversion/unit evidence, not generated guest execution or a combined-main build. The real-title timing and output comparisons remain separate and outstanding; I have no inputs to supply them.

A chain of table bytes that decodes to a return after a padding run looked
like trailing gap code and stopped the mask inside a real table, which hands
the rest of it back to the decoder. Truncating now needs the block to contain
a syscall, or to end where the gap turns into padding, so a 2 KiB table with
00/cc/90 runs and return-like bytes stays masked.
@brainiac91

Copy link
Copy Markdown
Contributor Author

Reproduced and fixed, head 133ae3261.

A 2 KB Whirlpool-style table with 00/cc/90 runs and mov rax,rax; ret chains after them did stop the mask at about offset 952, and again at a 16-byte aligned run; the rest of the table went to the decoder.

I tightened it by requiring the block to hold a syscall, or to end where the gap turns into padding, rather than by alignment: an aligned pad run inside table data can still decode to a ret, and requiring alignment would hide unaligned stubs.

CheckTableWithPaddingAndReturnBytes asserts the whole table is masked. It fails on 3cb3e8f53, passes now, and passed on 640577c3e. The stub-before-data cases still refuse syscall 9 on the SCE, SysV and module routes.

I can't relink ubiservices.prx - no title inputs here, so PPSA21564 is yours. 301/301 ctest and conventions clean.

@brainiac91

Copy link
Copy Markdown
Contributor Author

Thanks for the sweep. Head moved to 133ae3261: a block now ends the mask only if it holds a syscall, so table bytes that decode to a ret no longer truncate it, and there is a 2 KB table regression for that. Nothing in your nine conversion cases changes.

@plexerPK

Copy link
Copy Markdown
Contributor

Checked 133ae3261f839a540269fd7bdd862a64aaafb607. The new CheckTableWithPaddingAndReturnBytes fails against 3cb3e8f53b with the expected premature-mask-end assertion and passes on this head. All three focused suites pass (1.19 s total), including both earlier masking regressions and the large-gap test.

I also reran both external nine-route matrices: 18 syscall refusals (exit 2, syscall 9, no output) and 18 successful data controls across SCE executable, SysV executable and guest-module conversion to Linux/Windows/macOS. Thus both reported syscall cases remain corrected. The interval-membership implementation is unchanged.

One evidence boundary: the added 2 KiB test repeats a synthetic row and inserts return chains; it is not the complete standard Whirlpool table. Its red/green result is established, but it does not by itself establish the reviewer's whole-table reproduction or real ubiservices conversion. Those checks and title timings remain outstanding. This is macOS arm64 synthetic conversion/unit evidence, with no generated guest execution, title inputs or combined-main verification.

@brainiac91

Copy link
Copy Markdown
Contributor Author

Closed the whole-table gap on my side with the real table, not a synthetic one. I took the standard 2 KiB Whirlpool C0 constants from Linux crypto/wp512.c (public domain) and drove FindRelativeJumpTables plus MakeSyscallScanner over the gap layout from the trace on 133ae3261.

With the reported 0F 78 33 1E at the LEA target the mask covers all 2048 table bytes, the scan finds no syscall inside them, and a mov eax,9; syscall; ret stub in the pad behind the table is still scanned and refused with syscall 9, so the boundary does not swallow the stub. C0 on its own decodes linearly (798 instructions, reaches +2046) and holds no 0F 05/0F 34/0F 07/CD 80 pair anywhere, so detection never fires for it and nothing changes; the mask needs the decode failure the trace shows.

The harness is scratch and stays out of the tree - I did not want 2 KiB of constants in the suite, and the committed 2 KiB test already pins the boundary rule. ubiservices.prx conversion and the title timings still need a machine with the inputs.

@wachi35676

Copy link
Copy Markdown
Contributor

Re-checked head 133ae3261f merged onto main 5b85225ef (clean). Windows 11, WinLibs GCC 15.2.0, Release. I compared it with main built from the same tree.

All the gap cases I have are refused. I added three aimed at the new rule (end the mask only at a block that holds a syscall). The probe image is unchanged (lea-referenced table at 0x1310, next FDE at 0x1400), and the Linux default and --windows give the same results:

bytes after the table and cc padding 3cb3e8f53ba2 133ae3261f
b8 3b 00 00 00 eb 01 0f 0f 05 c3, then data (jmp over one byte into syscall) rc 0, 0f 05 c3 left in output rc 2, Forbidden syscall instruction at code offset 0x1328
48 89 c0 c3 b8 3b 00 00 00 0f 05 c3, then data (ret block, then a stub) rc 2 rc 2, Forbidden … 0x1329
eb 06, data, b8 3b 00 00 00 0f 05 c3, then data (jmp to a stub) rc 2 (Cannot decode) rc 2, Forbidden … 0x132d
b8 09 00 00 00 0f 05 c3, then data (stub, then data) rc 2 rc 2, Forbidden … 0x1325

The earlier cases (… 0f 05 00 01 90 and the rest) are still refused. Main refuses all of them with Cannot decode instruction.

  • All 177 relinker tests pass, and check_conventions.py passes.
  • With the new line reverted to trailing[pos] = Trailing::Terminator;, control_flow_graph fails with Mask stopped inside a table with padding and return bytes. The conversion tests don't cover that case.
  • PPSA99005, PPSA47402, PPSA99581 and PPSA99995 (16 modules) give 12/12 output sets byte-identical to main.

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

@oneandonlydean
oneandonlydean merged commit b744c37 into boykopovar:main Oct 26, 2026
6 checks passed
Lindamea1 added a commit to Lindamea1/AnyPS5 that referenced this pull request Oct 27, 2026
…osetta conversion

The syscall scans mask the tables FindRelativeJumpTables finds in
executable segments (trailing relative jump tables and, since boykopovar#8076,
LEA-referenced data tables between unwind functions), but the Intel and
Rosetta converter still decodes the whole segment and stops on table
bytes such as 0F 78 ("Cannot decode instruction"). Compute the table
ranges once, before conversion, with a DataTableRanges helper that
Conversion and the guest module builder call. The converter scans a copy
with those ranges masked, drops every instruction that overlaps one, and
keeps stub windows and islands from spanning them. The later syscall
scans reuse the same ranges; the pipeline computes them itself only when
Conversion passes none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Lindamea1 added a commit to Lindamea1/AnyPS5 that referenced this pull request Oct 29, 2026
…osetta conversion

The syscall scans mask the tables FindRelativeJumpTables finds in
executable segments (trailing relative jump tables and, since boykopovar#8076,
LEA-referenced data tables between unwind functions), but the Intel and
Rosetta converter still decodes the whole segment and stops on table
bytes such as 0F 78 ("Cannot decode instruction"). Compute the table
ranges once, before conversion, with a DataTableRanges helper that
Conversion and the guest module builder call. The converter scans a copy
with those ranges masked, drops every instruction that overlaps one, and
keeps stub windows and islands from spanning them. The later syscall
scans reuse the same ranges; the pipeline computes them itself only when
Conversion passes none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs fix error Closes an issue (Fixes #N) relinker unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Relinker: ubiservices.prx conversion fails on 0F 78 while preparing The Rogue Prince of Persia (PPSA28155)

6 participants