fix(relinker): tolerate trailing data in TLS scan #299
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/299"
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 Pouare514 on 2026-10-01T23:33:45Z.
What
The TLS code scan over unwind function ranges failed the whole relink when a range ended with undecodable bytes. TLOU Part I has an FDE range ending with trailing jump-table data, so the scan now tolerates a short tail (at most 15 bytes, the longest x64 instruction) without an FS prefix instead of aborting. A branch target that lands inside a skipped tail is still rejected, and an overlapping instruction that starts with, or lands inside, an FS-prefixed instruction is rejected as overlapping boundaries (the 0x64 scan now starts at the overlapping address instead of after the previous instruction).
Tested
test_tls_function_coverage.pyagainst the rebuilt relinker: all pass, including the restoredoverlapping-entryexpectation (Code analysis: overlapping instruction boundaries) and the newoverlapping-fs-prefixcase (FS-prefixed instruction starting inside the previous one is rejected).empty_tls,tls_function_coverage,guest_tls: 3/3 pass.Checklist
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T05:40:22Z.
Thanks, the tail rule reads as sound to me: an FS instruction starting in the skipped bytes would have its 0x64 byte there, so the no-0x64 check plus the branch check covers it. The overlap part has a hole though: the 0x64 search starts at previousEnd, so an FS-prefixed instruction that starts inside the previous one (0x64 at
address, before previousEnd) is accepted, stays in the instruction set, and its TLS patch would overwrite bytes of the earlier instruction. Searching fromaddressto spanEnd would close it. Could you also restore the PR description (it stops after the first sentence) with the Tested section and the checklist, and add a new test case rather than changing what overlapping-entry expects?Imported from boykopovar/AnyPS5. Originally posted by Pouare514 on 2026-10-04T13:42:35Z.
Done: the 0x64 scan now starts at the overlapping address, plus a prefix scan of the overlapped previous instruction so a branch landing inside an FS-prefixed instruction (like overlapping-entry) is still rejected as overlapping boundaries. overlapping-entry expectation restored, new overlapping-fs-prefix case added. ctest empty_tls/tls_function_coverage/guest_tls 3/3 green.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T21:07:43Z.
Thanks, starting the scan at
addresscloses the hole, and the new case covers it. One more thing about the check on the previous instruction: it looks for 0x64 only in its first 4 bytes, but WindowsTlsBuilder patches any instruction whose decodedSegmentPrefixis 0x64 and accepts any number of 0x66 prefixes before it. So a previous instruction like66 66 66 66 64 48 8b 04 25 ...passes this check and still gets patched. Decoding the previous instruction and checking itsSegmentPrefixmatches exactly what gets patched. With that it looks ready to merge from my side. The red Windows job is the guest_audio_in_no_device flake that #532 fixed.Imported from boykopovar/AnyPS5. Originally posted by Pouare514 on 2026-10-04T22:57:25Z.
Done: the previous-instruction check now decodes it and compares SegmentPrefix to 0x64, matching exactly what WindowsTlsBuilder patches (any number of 0x66 prefixes included). Added an overlapping-fs-prefix-66 case with four 0x66 prefixes; verified it fails without the fix and passes with it. Also dropped the stray libSceAudioIn hunk from this branch.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T23:43:40Z.
Thanks, decoding the previous instruction and comparing its
SegmentPrefixwith 0x64 is exactly the set WindowsTlsBuilder patches, andoverlapping-fs-prefix-66covers the four 0x66 case.tls_function_coverageandempty_tlspass here on this head merged with current main, and CI is green. Ready to merge from my side.A small note, no action needed: the
libSceAudioInline in this branch is now the same as main's #532, so it merges to nothing. It only shows up in the diff because the branch is based before #532.