fix(relinker): treat data between PS4 unwind functions as data in the syscall scan and the code roots #8166
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8166"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-20T01:04:49Z.
What
PS4 images keep read-only data inside the executable segment, between the functions that
.eh_framedescribes.boggle.selfandtp.selffrom CUSA03312 (Hasbro Family Fun Pack) are Unity players with about 15 MB of such data between their unwind functions. Two parts of the relinker treat bytes there as code:Syscall scan. A table in a gap can hold
0f 05. The scan failed withForbidden syscall instructionat0xa579ad(Boggle) and0xa8a209(Trivial Pursuit). Outside the unwind functions of a PS4 image, asyscall,sysenterorint 0x80pattern now fails the relink only when a constant syscall number is set before it. The others, and everysysretpattern, are skipped and counted in oneSkipped N syscall byte pattern(s)line. The number is looked for in two places:ConstantSyscallNumberalready does, now requiring each instruction it looks back over to end where the next one starts;mov eax, imm32,mov rax, imm32,mov rax, imm64orxor eax, eax, optionally followed bymov al, imm8ormov ax, imm16, then by any number of register moves or zeroings that leaveraxalone.The scan merges nested and overlapping unwind ranges with the instruction scanner's
MergeCodeRanges, which is now exported. Inside the unwind functions, in images withoutPT_SCE_DYNLIBDATA, and in guest modules without it, every such instruction still fails.Code roots for the Windows and macOS outputs.
CodeInstructionCollectorfollowed every relocation andleatarget inside the code range as code. Strings and tables in the gaps then decoded into garbage, and the conversion failed withInstruction exceeds 15 bytes. Outside the unwind functions, such a target is now decoded linearly up to its first jump, return or trap, the start of the next unwind function, or 256 instructions. It is followed as code when either holds:fs:[disp32]access, the form the linear TLS sweep already roots;Every other such target is taken as data. These targets are counted in one
Took N pointer target(s) outside the unwind functions as dataline, and the Windows TLS rewrite fails instead of overwriting one.leatargets go through the same rule instead of the graph's own address-taken roots. Images without unwind functions are unchanged.The debt file records both rules as heuristics.
The first two commits are the original change, rebased on
mainnow that #7660 is merged. The last two address the reviews by @SandstromPL and @wachi35676:Tested
Windows 11 Pro 26300, WinLibs GCC 15.2.0, Release, relinker-only build (
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON) onmain56b299c3a.ctest: 223/223 pass, both at the head and with only the first three commits.e0095e5b4also acceptsmov rax, imm64, amov al/mov aximmediate after a constant, and more than seven register moves. Their three missed rows (and amov axrow) are refused now; each fails at58a2a4962. On the stack below, all four Hasbro games still convert with the same 67 and 28 skipped patterns.test_sce_code_gaps.pyandtest_sce_code_extent.pygain the reviewers' cases:Skippedline;leapath of the pointer rule, with assertions on theTookline;PT_TLSand refused without it;GuestModuleBuilder.cpp:346and without the module gate, the PS5 module case fails; with the gate, it passes.--executable <game>.self), for Windows, macOS and Linux. The base stack ismain, #6684, #8168 and the TLS relocation commit from #6977; each game was converted on it with and without this PR:.desktopfiles differ only by the output path.Forbidden syscall instruction) and convert with it. Boggle skips 67 syscall patterns and takes 5676 pointer targets as data; Trivial Pursuit skips 28 and takes 5384.ModulesandPlugins(--module-dir), converted with each game as the input for Windows and with the launcher for macOS and Linux. No game was run for this update.--module-dirstops onGuest modules convert differently for <game>.self, so it cannot share them with the input executable. It stops the same way at the previous head, so it is not from this change.tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py --branchlists:GuestModuleBuilder.cpp:346, which the module gate now covers.CodeInstructionCollector.cppline is the interpreter trim, not these rules.GuestModuleWritersignatures that this PR extends with a message callback.The jump-table case in Boggle's
SavedGames.prxplugin is separate and is #8168. A function's relative jump table ends 8 bytes past its FDE, and code follows after 16-byte padding, whichmain'sFindTrailingRelativeJumpTabledid not accept. Trivial Pursuit converts without it.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T01:19:49Z.
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.
main)core/relinker/elfpatcher/include/elfpatcher/general/GuestModuleWriter.hppL10-12core/relinker/relinker/src/guest/GuestModuleBuilder.cppL397core/relinker/relinker/src/analysis/CodeInstructionCollector.cppL98Some 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.
docs/dev/debt/relinker.mdcore/relinker/relinker/src/analysis/CodeInstructionCollector.cppcore/relinker/elfpatcher/src/macos/MacOsGuestModuleWriter.cppcore/relinker/elfpatcher/src/windows/WindowsGuestModuleWriter.cppcore/relinker/elfpatcher/src/windows/WindowsPePatcher.cppcore/relinker/relinker/src/analysis/CodeInstructionCollector.cppcore/relinker/relinker/src/guest/GuestModuleBuilder.cppcore/relinker/relinker/tests/test_sce_code_extent.pydocs/dev/debt/relinker.mdcore/relinker/codegen/include/codegen/IInstructionScanner.hppcore/relinker/codegen/src/InstructionScanner.cppcore/relinker/relinker/src/analysis/SyscallScanner.cppcore/relinker/relinker/src/analysis/CodeInstructionCollector.cppcore/relinker/relinker/src/guest/GuestModuleBuilder.cppcore/relinker/relinker/tests/test_sce_code_extent.pydocs/dev/debt/relinker.mdImported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-20T02:39:55Z.
Confirmation from Gang Beasts (CUSA04865, own dump):
Media/Modules/MonoAssembliesPS4.prxholds 78 Mono AOT images (mono_aot_version67) whose tables, PLT info words and strings sit in the executable segment outside any FDE.mainatc2b0159d6the relinker stops withForbidden syscall instruction at code offset 0x129f1c, insideclass_name_table.relinker --skip-sce-moduleconverts it. The executablePT_LOADof the output is byte-identical to the input (48,101,680 bytes, SHA-1dd2fd057bf50…), and the trampolines go to a new segment.Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7. I'm closing my #8198, which did the same for this module with a Mono-specific reader of each image's
globalstable.Imported from boykopovar/AnyPS5. Originally posted by SandstromPL on 2026-10-20T11:14:37Z.
@savvaniss Review of your two commits on 5cababf14 (cddd6cfff and a0ccdeee2). Base for comparison: main
a569f47cb+ #7660c92f09d1d. All results come from synthetic fixtures built with your test helpers. We have not seen any of these on a real title.1. Nested FDE ranges let a syscall without a number through
SyscallScanner.cpp:194-199, used at :226, sorts the unwind ranges byBegin.insideFunctionthen tests only the last range whoseBegin <= offset, and the ranges are never merged.InstructionScannerdoes merge the same ranges, withMergeCodeRanges(InstructionScanner.cpp:13-24, :30).Nothing upstream refuses overlapping FDEs:
ReadExceptionFunctionsandSceCodeExtentdon't check for them. Only the opt-in strict NID filter does.Fixture:
test_sce_code_extent.fixture(gap=0x20)with the FDE table[(0x180,0x80),(0x190,0x8),(0x200,0x10)], the ranges filled with NOPs, and89 f8 0f 05 c3(mov eax,edi; syscall; ret) at 0x1c0.--windowsand--macos, with "Skipped 1 syscall byte pattern(s) … the first at code offset 0x1c2".This contradicts the body's "Inside the unwind functions … any such instruction still fails". Linkers rarely emit nested FDEs (lld drops entries with duplicate starts, and GNU ld warns about overlaps), so this is a risk rather than a bug we have seen. The fix is small: merge after the sort (not built), or expose
MergeCodeRangesfrom codegen so the two components can't disagree.Test: add the fixture above to
test_sce_code_gaps.py, expecting "Forbidden syscall instruction at code offset 0x1c2".2. Only the
sceImage ?atGuestModuleBuilder.cpp:346keeps PS5 modules strict, and #8076 changes that lineGuestModuleBuilder.cpp:352, which comes from #7660, callsSceUnwindRangeswithout asceImagegate. Non-SCE modules stay strict only because :346 leavesunwindFunctionsempty. cddd6cfff widens what non-empty ranges unlock. On the #8166 binary, with identical module bytes and FDE (gap bytes8b c7 0f 05 c3at 0x1000, FDE at 0x1010):#8076 (e4034102a) changes :346 to
sceImage || PT_GNU_EH_FRAME. In agit merge-treeof the two heads, that line merges outside the conflict markers, because the conflict covers only the scan-call lines. A resolution that keeps both sides therefore turns on the gap leniency for PS5 modules. cc @oneandonlydean, since you are assigned both.Removing
sceImage ?from :346 also passes all 219 tests today. Suggested gate:Suggested test for
test_sce_code_gaps.py, which turns header 3 (PT_SCE_DYNLIBDATA) into PT_NULL. Head and main refuse it, and it converts withoutsceImage ?.sce_module()keeps its PT_GNU_EH_FRAME, so the test also catches the #8076 merge.3. The pointer rule drops code without any message, TLS accesses included
addPointerRoot(CodeInstructionCollector.cpp:165-166, used at :171, :268 and :276, with the graph's lea following turned off at :447) drops a relocation or lea target outside every FDE in three cases: it is unaligned, it is 256 bytes or more past the previous FDE end, or it is before the first FDE. No message is printed. Base follows such targets.Fixture:
fixture(gap=0x140)plus PT_TLS, an FDE at 0x200-0x210, a RELATIVE pointer to 0x310, NOP padding, and64 48 8b 04 25 00 00 00 00 c3at 0x310.fs:[0]stays in both outputs, and nothing is printed.The same mechanism turns refusals on base into silent conversions on #8166:
64 48 8b 00 48 89 c7 c3, base fails with "Unsupported macOS guest TLS instruction";lea rdi,[rip→0x304], base fails on Windows with "TLS rewrite would overwrite an executable entry point (offset 0x304)". #8166 converts it, and the rewrite overwrites the lea target.What limits the damage:
fs:[disp32]sweep still catches local-exec loads behind 16-alignedcc ccpadding. With 0xCC padding, the output is identical to base.call/jmp [rip+slot]targets are still followed.decodesToTransferalso filters very little. The decoder throws only on length or truncation errors, and the probe walks on into the next FDE function. SoHello everyone!\0at an aligned address 0x40 past an FDE end is accepted, and its65bytes become UD2+NOP. Base does the same, so that part is not a regression. In practice, the alignment check and the 256-byte window are what do the filtering.Suggestions:
Begin. If a64/65-prefixed instruction shows up, follow the target or refuse.decodesToTransferat the next FDEBegin.Two questions:
--windows/--macos, are the outputs byte-identical with and without a0ccdeee2?64/65-prefixed instruction before its first transfer?4. The syscall-number lookback ignores adjacency (this one fails safe)
ConstantSyscallNumber(SyscallScanner.cpp:149-172) usesrecent.Before(step)without checking that it ends where the next instruction starts. #7660's byte-by-byte skip in gaps (InstructionScanner.cpp:61-65) pushes nothing torecent.Using your
executable()with gapb8 14 00 00 00+41×15 +0f 05 c3:90×5 in place of the mov, it is rc 0, "Skipped 1 … 0x217".On a CPU, that mov is followed by a 17-byte instruction (#GP), so it cannot set eax for the syscall. The flaw only causes false refusals, and it needs more than 15 prefix bytes before
0f 05. Suggested fix (not built):Test:
executable(SYSCALL_NUMBER + b"\x41" * 15 + SYSCALL)with no expected errors.Test gaps. Each mutant below passes the full 219-test suite. Each killer below was run against the head binary and the mutant binary.
addPointerRootis never tested. Making the third disjunct on :166 false survives, and TLS in gap thunks would then go unrewritten. So does dropping the alignment check or the near-end check, or letting the transfer probe accept the first instruction it decodes. Case, forwindowsandmacos:fixture(early_function=True, pointer_target=0x1B0, gap_bytes=(0x1B0, UNSUPPORTED_TLS)), and the same at 0x170, both expecting "Unsupported Windows/macOS guest TLS instruction". Head refuses both, and the mutant converts them. To kill the other three mutants, add these to your aligned/unaligned loop (all three convert on head):(0x1A4, UNSUPPORTED_TLS)(alignment);fixture(gap=0x140, pointer_target=0x310, gap_bytes=(0x310, UNSUPPORTED_TLS))(near-end);(0x1B0, b"\x90" + INVALID)(transfer probe).fixture(early_function=True, gap_bytes=(0x1B0, INVALID)), withFUNCTIONset to48 8d 05 <rel32 to 0x1B0> c3. Head converts it, and each revert fails with "Instruction exceeds 15 bytes".<=, skipping only Invocation kinds, or deleting the "Skipped" message all survive. Cases:executable(SYSCALL), the pattern at 0x210 right after the FDE, expecting rc 0;executable(SLOT + bytes.fromhex("0f 07"))(sysret), expecting rc 0;sce-gap-table-with-syscall-bytes.run()ignores stdout today.Our runs (Linux GCC, relinker-only Release):
e9a5a0c84: 227/227.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-20T11:38:46Z.
Verdict: defect. In a gap, data that ends right before code can absorb the
mov eax, N. The syscall after it then has no constant number, and the scan skips it.Tested at
5cababf14, merged ontomain02fb1ce53. Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs GCC 15.2.0 r7, relinker-only Release. WSL Ubuntu 24.04, GCC 13.3.Probe: the PS4
fixture(gap=0x20)thattest_sce_code_gaps.pyuses (PT_SCE_DYNLIBDATA, one unwind function at 0x200..0x210). The listed bytes start at 0x210, in the gap. Both the Linux default and--windowsgive the same result:mainb8 3b 00 00 00 0f 05 c3(mov eax,59; syscall; ret)Forbidden syscall ... 0x215: syscall number 590f 78 11 22 33 44+b8 3b 00 00 00 0f 05 c3Cannot decode instruction: Unsupported 0F 78 opcode ... (offset 0x210)Skipped 1 syscall byte pattern(s) ... 0x21b, output still holds0f 050f 78 11 22 33 44 3c+ the same codeCannot decode instructionSkipped ... 0x21c0f 78 11 22 33 44 cc cc+ the same codeCannot decode instructionForbidden syscall ... syscall number 59b8 3b 00 00 00 48 89 df 0f 05 c3Forbidden syscall ... 0x21831 c0 0f 05 c3Forbidden syscall ... 0x212What happens in the second and third rows: the scanner fails to decode at 0x210 and moves on one byte at a time. It then decodes
44 b8 3b 00 00 00as one instruction (mov eaxwith a REX prefix), or decodes3c b8ascmp al, 0xb8.ConstantRaxLoadaccepts onlyb8 imm32with no REX and48 c7 c0 imm32, so the load is not recognised. The PR describes a constant number loaded right before the syscall as "still rejected". That only holds when padding or a decodable instruction ends the data before the code, as in the fourth row. The last two rows are what the new debt line already says ("whose number is set further back").mov eax, N; mov rsi, rbx; syscallis also the shape of the SDK's own inline mmap stub.#8076 at
e4034102arefuses all six rows on the same probe: rc 2, the same errors asmain.A jump table directly followed by code makes the same thing happen. Probe: two unwind functions, 0x200 and 0x230. The first is
lea rcx,[rip+9]; movsxd rax,[rcx+rdi*4]; add rax,rcx; jmp raxwith a 4-entry table at 0x210, followed directly bymov eax,59; syscall; retat 0x220:mainand #8076: rc 2Forbidden syscall instruction at code offset 0x225, without a number, because the table words misalign the decode.Skipped ... 0x225, and the syscall is still in the output.... 0x225: syscall number 59. #8168 masks the table only up to 0x220, so the load is decoded. Data that is not a recognised jump table, as in rows 2 and 3 of the table above, still gets skipped with #8168 merged; I measured the same results for all six rows.Other results:
ctest: Windows 222/222 (main221/221), WSL 227/227 (main226/226).c92f09d1d) fails this branch'stest_sce_code_gaps.pyatsce-gap-syscall-bytes-after-slotandtest_sce_code_extent.pyatsce-pointer-to-unaligned-gap-data-windows.mainfails atsce-gap-slot-linux(Instruction exceeds 15 bytes).PT_SCE_DYNLIBDATA, so the new rules don't run for them. Relinked with--windows --to-intel,--macos --to-rosettaand Linux--to-intel, all 12 output sets are byte-identical tomain.One way to keep the refusal: before skipping a pattern, also check the raw bytes in front of it for a
b8 imm32or48 c7 c0 imm32load, independent of how the scanner aligned its decode.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-20T12:58:19Z.
@SandstromPL Thank you for the review and the fixtures. Everything below is at
58a2a4962: the branch is rebased onmain56b299c3a(#7660 is merged), with two new commits on top of the original two. "Before" means 5cababf14.1. Nested FDE ranges.
MergeCodeRangesis now exported fromIInstructionScanner.hpp. The syscall scan uses it instead of its own sort, so the scan and the instruction scanner cannot disagree.CodeInstructionCollectormerges its ranges the same way. Your fixture is intest_sce_code_gaps.pyassce-nested-function-syscall-{linux,windows,macos}: FDEs(0x180,0x80),(0x190,0x8),(0x200,0x10), NOPs, and89 f8 0f 05 c3at 0x1c0.Forbidden syscall instruction at code offset 0x1c2.2. PS5 modules.
GuestModuleBuilder.cpp:352now readssceImage ? SceUnwindRanges(...) : std::vector<CodeRange>{}.ps5_module()is added as you wrote it, expectingForbidden syscall instruction at code offset 0x1020. I checked the #8076 merge by changing line 346 to read the unwind table for every module:3. The pointer rule. All three suggestions are in, with one narrowing that your second question decided:
Took N pointer target(s) outside the unwind functions as data, the first at 0x.... A message callback goes fromConversionandGuestModuleBuilderthrough the Windows and macOS writers intoCodeInstructionCollector::Collect. Every new parameter is defaulted.fs:[disp32]access, the same check the linear sweep uses (now one shared lambda). I did not follow on every64/65prefix, because in Boggle and Trivial Pursuit about 2,500 data targets each hit one; numbers below. Following all of them makes both conversions fail:Instruction exceeds 15 bytes(Boggle) andCode analysis: overlapping instruction boundaries(Trivial Pursuit).decodesToTransferstops at the next FDEBegin. The same run serves both checks.entryRoots. So the Windows TLS rewrite fails instead of overwriting one, as it did on base when they were roots.Your fixtures, now in
test_sce_code_extent.pyfor--windowsand--macosunless noted:64 48 8b 04 25 00 00 00 00 c3fs:[0]in PE and Mach-OGuest TLS access without PT_TLS/... a non-empty PT_TLS64 48 8b 00 48 89 c7 c3at 0x310Took 1 pointer target(s) ... the first at 0x310lea rdi,[rip→0x304](Windows)TLS rewrite would overwrite an executable entry point (offset 0x304)The
fs:[rax]form behind a far pointer stays a known gap, and the debt entry now names it.Hello everyone!\0near an FDE end is still accepted if it decodes to a transfer before the next FDE start, as on base.Your questions:
main, #6684, #8168 and the TLS relocation commit from #6977, with and without the whole PR. The syscall half only turns refusals into skips, so for titles that convert either way, any output difference would come from the pointer rule. Risk and Monopoly (CUSA03312), each with the pack's launcher, convert either way. All 11 output files of each are byte-identical for--windowsand--macos. Linux output is identical too, apart from the path in the.desktopfile. That stack also carries #8168. Against the previous head on the same stack, every output of all four games is byte-identical for every target, Boggle's and Trivial Pursuit's UnityModulesandPluginsincluded. So the review changes alter nothing these titles get.64/65fs:[disp32]boggle.selftp.selfeboot.binSo yes, many decode to a
64/65-prefixed instruction, mostlygsfrom theebytes of strings. None decodes to thefs:[disp32]form the rule now follows, and both titles still convert with the same 67 and 28 skipped syscall patterns.4. Lookback adjacency. Your diff is in
ConstantSyscallNumber. The test issce-gap-syscall-after-overlong-instruction,executable(SYSCALL_NUMBER + b"\x41" * 15 + SYSCALL):... 0x217: syscall number 20.Skipped 1 ... 0x217.The new raw-byte check (see wachi35676's thread) does not find a number there either, because 15
41bytes sit between the load and the pattern.Test gaps. All three are covered, and each of your 10 mutants now fails at least one case:
UNSUPPORTED_TLSat 0x170 and at 0x1B0 through a RELATIVE pointer, and at 0x1B0 through alea. Each expectsUnsupported Windows/macOS guest TLS instruction.gap=0x140) and90+INVALIDeach expect rc 0 and theTookline. A newFS_SUBTRACTrun at 0x1F0, which reaches the next FDE at 0x200, covers the stop at the next FDE start.leapath.FUNCTION = 48 8d 05 <rel32 to 0x1B0> c3withINVALIDat 0x1B0 expects rc 0 andTook 1 ... 0x1b0.sysretafter a slot, andsce-gap-table-with-syscall-bytes. All assert theSkippedline, whichrun()now checks.90+INVALID, run into the next FDE (both targets)leato gap data (both targets), TLS rewrite over the lea target<=sysretSkippedmessageResults: full
ctest223/223 at the head, and 223/223 with only the first three commits (Windows 11, WinLibs GCC 15.2, relinker-only Release).check_conventions.pypasses.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-20T12:58:21Z.
@wachi35676 Thank you, confirmed and fixed at
58a2a4962. Before a pattern outside the unwind functions is skipped, the scan now looks for a constant syscall number in the raw bytes in front of it, independent of where its decoding landed. It accepts any of these, ending at the pattern:mov eax, imm32(b8);mov rax, imm32(48 c7 c0);xor eax, eax(31 c0or33 c0).It also accepts one of them followed by at most seven register moves or zeroings (
89/8b/31/33with a register ModRM and an optional REX prefix) that leaveraxalone. Those cover your fifth row, the SDK's inline mmap stub (mov rsi, rbx), and the mprotect stub'smovs andxor r10d/r8d/r9d.Your six rows and the jump-table row are in
test_sce_code_gaps.pyfor Linux,--windowsand--macos. Before is 5cababf14; after is this head:b8 3b 00 00 00 0f 05 c30x215: syscall number 590f 78 11 22 33 44+ the sameSkipped 1 ... 0x21b0x21b: syscall number 590f 78 11 22 33 44 3c+ the same0x21c: syscall number 590f 78 11 22 33 44 cc cc+ the samesyscall number 590x21d: syscall number 59b8 3b 00 00 00 48 89 df 0f 05 c30x218: syscall number 5931 c0 0f 05 c30x212: syscall number 0mov eax,59; syscall; retat 0x220Skipped 1 ... 0x2250x225: syscall number 59Each of these "after" results needs the raw-byte check: removing it makes the five changed rows fail on all three targets. A new case,
b8 3b 00 00 00 48 89 f8 0f 05 c3, pins the other side:mov rax, rdioverwrites the number, so the pattern is still skipped. It fails if a move intoraxis allowed as an intermediate.On the real data, the check refuses none of the 67 patterns in Boggle or the 28 in Trivial Pursuit. Both still convert with the same
Skippedcounts, and for every target Risk and Monopoly produce the same bytes as without this PR.The debt entry now says what is still not refused: a syscall without an unwind entry whose number comes from memory or from another register.
Results: full
ctest223/223 (Windows 11, WinLibs GCC 15.2, relinker-only Release). The other review findings and the measurements are in my reply to SandstromPL above.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-20T13:10:08Z.
Re-ran Gang Beasts (CUSA04865) on
58a2a49against 5cababf:relinker --windows --windows-gui --registry --module-dir Media/Modules eboot.binon an Itemzflow dump, withsce_module/left out so the TLS stop that needs #6977's fix does not come first.gb.exe, the two convertedMedia/Modulesimages and the json files.MonoAssembliesPS4.prx; the new raw-byte check refuses none of them.58a2a49:Took 18554 pointer target(s) outside the unwind functions as data, the first at 0xf0forMonoAssembliesPS4.prx, and 23 (the first at 0x19077) foreboot.bin. 0xf0 is where the first AOT image'smethodsrange starts, so, as SandstromPL expected, the Mono AOT method code (no FDEs) is taken as data. It has no fs/gs accesses, which is why the output does not change.Windows 11 26200, WinLibs GCC 15.2.0 r7.
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-20T13:33:12Z.
Verdict: confirm the fix for the six rows; it holds. One note on scope: the new raw-byte check still misses some ordinary constant syscall-number loads, and its debt line understates that.
Re-ran at
58a2a4962merged ontomain30fda0a03(clean merge, heada7c553bb3), Windows 11 with WinLibs GCC 15.2.0 (relinker-only Release). Currentmainalready refuses every syscall pattern it finds in a PS4 gap (rc 2), so each row below ismainrc 2 vs this head. Same fixture as before (executable(gap_bytes), one unwind function 0x200..0x210, bytes at 0x210); Linux,--windowsand--macosall agree.The six original rows are now refused, as you describe:
main30fda0a03b8 3b 00 00 00 0f 05 c30x215: number 590f 78 11 22 33 44+ the same0x21b(no number)0x21b: number 590f 78 11 22 33 44 3c+ the same0x21c0x21c: number 590f 78 11 22 33 44 cc cc+ the same0x21d: number 590x21d: number 59b8 3b 00 00 00 48 89 df 0f 05 c30x2180x218: number 5931 c0 0f 05 c30x2120x212: number 0What still skips (rc 0, the
0f 05left in the output,Skipped 1 ... without a syscall number), all forbidden syscallsmainrefuses with rc 2:48 b8 3b 00 00 00 00 00 00 00 0f 05 c3mov rax, 59(imm64); syscall0x21a31 c0 b0 3b 0f 05 c3xor eax,eax; mov al, 59; syscall0x214b8 3b 00 00 00+89 db×8 +0f 05 c3mov eax,59; 8 reg moves; syscall0x225b9 3b 00 00 00 89 c8 0f 05 c3mov ecx,59; mov eax,ecx; syscall0x2176a 3b 58 0f 05 c3push 59; pop rax; syscall0x2130d 3b 00 00 00 0f 05 c3or eax, 59; syscall0x215b8 3b 00 00 00 48 89 f8 0f 05 c3mov eax,59; mov rax,rdi; syscall0x218The last four match the residual the debt line names (number from another register or from
push/or/an overwrite). The first three do not: the syscall number is a plain compile-time immediate still live in rax/eax atsyscall, the check just does not model that encoding.mov rax, imm64(48 b8) is missed, while the other 64-bit formmov rax, imm32(48 c7 c0 3b 00 00 00) is accepted and refused (0x217: number 59). Both encodemov rax, 59.xor eax,eax; mov al, Nis missed;xor eax,eaxon its own is accepted (row 6, number 0). The 8-bitmov alafter the zeroing is not followed.mov eax,59+ 7mov ebx,ebxis refused (0x223: number 59), + 8 is skipped (0x225), though rax is untouched throughout.So the debt entry's "whose number comes from memory or from another register" could also say "or from an immediate the lookback does not decode (
mov rax, imm64,xor eax,eax; mov al, N, or a constant more than seven register ops before the syscall)". These only matter if such bytes are real code in a gap rather than data; with the gap-as-data premise they are benign, but they are not refused the way the three constant-immediate cases above suggest.No false refusals:
mainrefuses every gap syscall, so this PR only ever relaxes relative tomain; there is no patternmainconverts that this head rejects.Other results:
ctest: this head 223/223 (Windows 11, WinLibs GCC 15.2, relinker-only Release).main30fda0a03has no gap-skip logic (noSkippedmessage in the source) and the added tests are this PR's.PT_SCE_DYNLIBDATA, so these rules don't run; relinked--windows --to-intel,--macos --to-rosettaand Linux--to-intel, all 12 output sets are byte-identical tomain30fda0a03.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-20T15:13:40Z.
@wachi35676 Thank you, all three were real gaps. Fixed in
e0095e5b4(fix(relinker): find more constant syscall numbers before a gap syscall). The raw-byte check now:mov rax, imm64(48 b8) as a constant load;mov al, imm8(b0) ormov ax, imm16(66 b8) that follows a constant into that constant. A partial write with no constant before it stays unknown;raxalone, instead of at most seven. Visited states keep the walk linear in the bytes it covers.Same fixture (
executable(gap_bytes), bytes at 0x210), on Linux,--windowsand--macos. Before is58a2a4962:58a2a4962e0095e5b448 b8 3b 00 00 00 00 00 00 00 0f 05 c30x21a0x21a: syscall number 5931 c0 b0 3b 0f 05 c30x2140x214: syscall number 5931 c0 66 b8 3b 01 0f 05 c30x2160x216: syscall number 315b8 3b 00 00 00+89 db×7 +0f 05 c30x223: syscall number 59b8 3b 00 00 00+89 db×8 +0f 05 c30x2250x225: syscall number 59b9 3b 00 00 00 89 c8 0f 05 c30x2170x2176a 3b 58 0f 05 c30x2130x2130d 3b 00 00 00 0f 05 c30x2150x215b8 3b 00 00 00 48 89 f8 0f 05 c30x2180x218b0 3b 0f 05 c30x2120x212test_sce_code_gaps.pygains the48 b8,31 c0 b0,31 c0 66 b8and eight-move rows; each fails at58a2a4962on all three targets.mov alalone is pinned as still skipped. The debt entry now lists exactly what is still not refused, following your wording: a number set from memory or another register (mov eax, ecx), bypush/popor arithmetic (or eax, imm32), or with any other instruction between the load and the pattern.On the real data, Boggle's 67 and Trivial Pursuit's 28 patterns are all still skipped, and nothing new is refused. That holds on a stack of
main, #6684, #8168 and #6977's TLS relocation commit: all four Hasbro games convert for Windows, Boggle and Trivial Pursuit with their UnityModulesandPlugins.@ntamas94 Thank you for the Gang Beasts rerun on
58a2a49. It confirms SandstromPL's expectation on real AOT code, and it shows the raw-byte check leaves all 147 patterns inMonoAssembliesPS4.prxalone. This commit can only turn a skip into a refusal, so I expect the same output there. A rerun on this head would confirm it if you have time.Results: full
ctest223/223 (Windows 11, WinLibs GCC 15.2, relinker-only Release);check_conventions.pypasses.AI-assisted: yes (Claude Code)