fix(relinker): take LEA addresses in PS5 images as code only when code uses them as code pointers #14107
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14107"
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 Khlopyev on 2026-10-31T19:12:51Z.
What
In images without
PT_SCE_DYNLIBDATA, the Windows and macOS code analysis follows every address a REX.WLEAcomputes as code. Tables that assembly keeps in.textare referenced exactly that way, so they were decoded as instructions:UD2(silent data corruption; the conversion succeeds);Unsupported Windows guest TLS instruction (bytes: 64 6f),Instruction truncated ...).OpenSSL's x86-64 assembly keeps its constants in
.textup to 3.3, which titles and middleware bundle (#7547 isubiservices.prx). With current main, 7 of 12 OpenSSL x86-64 modules built that way fail the Windows and macOS code analysis.#8166 added a rule for PS4 images. This PR covers the other images that have unwind or symbol functions (under
--function-symbol-roots, which ignores symbol sizes, only unwind functions count): aLEAtarget outside them is followed as code only when the computed register is used as a code pointer on some path of at most 64 instructions through direct jumps, both edges of conditional branches and the return of calls: the target of an indirect call or jump, stored or pushed, kept in an argument register at a call, or returned inrax. Register moves,testandcmpkeep the register; after a call onlyrbx,rbpandr12tor15keep it. Every other target joins the existing pointer targets taken as data, so it is reported in the same message and still protects its entry from TLS patches. Targets inside functions, relocation targets, PS4 images and images without unwind or symbol functions keep their current behaviour. The gap left by the rule is recorded indocs/dev/debt/relinker.md.tools/pr_overlap.pyreports overlapping lines with #12154, #12282 and #13825 (theBuildControlFlowGraphcall inCodeInstructionCollector.cpp) and with #11525 (docs/dev/debt/relinker.md). It could not compare #5021, #7531, #9793, #10792 and #10861 because they conflict withmain. Of all of these, only #10861 changesaddAddressTakenRoot: it takes the targets ofLEAs without REX.W or with a 32-bit address size as data and keeps the REX.W targets that this PR narrows as pointer roots, so the two PRs change the same lines.Tested
ctest315/315.ctest813/815 at the current head, merged withmain2f4d22d9e5:select_tests_MissingCommandTestsandvulkan_validation_gate_commandsfail because this Windows account may not create symbolic links (WinError 1314). On the first commitannotate_moduleexceeded its 20 s timeout in two runs on this machine with GNU objdump onPATHand passed without the timeout (53 tests, 1 skipped, 98 s); in the last run it passed in 11 s.code_analysis_address_data, for--windowsand--macos: a table read through theLEAregister keeps its GS look-alike bytes, a callback passed inrdito a call is still analysed (its GS access becomesUD2), and a table that starts with0F 78converts. On main the first case rewrites the table to0f 0b 90 90. The test also covers a callback inrbxthat is checked withtest rbx, rbxbeforecall rbx, one called only on the taken edge of a conditional branch, and one kept inrbxacross another call: the GS access in each becomesUD2, while the first commit left all three unchanged. A table checked withtestbefore it is read keeps its bytes..section .rodatadirectives removed (the 3.3-and-older layout), each linked into a guest module with.eh_frame, converted with--windowsand--macosunder--skip-syscall-check: main fails 14 of 24 conversions; with this PR all 24 convert and the code segment of every output is byte-identical to the input. Measured on the first commit and not repeated after the second.windows_tls_protected_entriesandtls_function_coverage(address-taken TLS callback) pass unchanged.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)Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-10-31T19:38:45Z.
Review: COMMENTED
Audited the relinker code analysis refactor for PS5 images with unwind/symbol tables:
UsedAsCodeAddresscleanly differentiates data table pointers from function/callback pointers computed via REX.WLEA. Inspecting up to 64 instructions along the fall-through and direct-jump path strikes an effective balance between analysis depth and bounded execution time.rdi,rsi,rdx,rcx,r8,r9) are correctly masked viaRegisterBiton direct calls and tail jumps (CallandUnconditionalJump).0xff /2and0xff /4) on tracked registers and returns inrax(RegisterBit(0)) are properly handled.memory & tracked) accurately reject pointers used as memory operands (table loads/stores), classifying them as data roots.0xc4/0xc5, EVEX0x62, and XOP0x8f) terminate tracking immediately, preventing misclassification from SIMD data computation.PT_SCE_DYNLIBDATA(!sceFunctions.empty()), images lacking unwind/symbol functions (functions.empty()), and targets already within known function boundaries continue to follow established pointer-root paths.BuildControlFlowGraph, updating the entries check tosceFunctions.empty() && functions.empty()ensures PS5 binaries with unwind records do not treat every raw pointer as an unconditional CFG root.docs/dev/debt/relinker.mdis well under the 1,000 character limit and clearly describes the 64-instruction search horizon and VEX/EVEX/XOP boundaries.CodeInstructionCollector.cpp.python tools/check_conventions.py(0 findings/errors on the changed lines).test_code_analysis_address_data.pytest suite tests both--windowsand--macostargets, verifying that GS look-alike data tables are preserved rather than rewritten to0f 0b 90 90(UD2), while callbacks passed inrdiremain reachable for analysis.Excellent, thorough fix for
.textconstant tables in OpenSSL 3.3 and related middleware.Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-06T23:31:57Z.
Review: COMMENTED
Tested on Windows 11 x64 with WinLibs GCC 15.2.0
15.2.0posix-14.0.0-ucrt-r7(as in CI), its CMake 4.3.1 and Ninja 1.13.2, and Python 3.15.0. Relinker-only Release build.4fd7f9e3merged intomaind7c58042:ctest --output-on-failure --timeout 120 --parallel 4passed 793/793, includingcode_analysis_address_data.test_code_analysis_address_data.pyrun against themainrelinker fails, because the table is rewritten to0f 0b 90 90. The new test therefore covers the change.Four more cases, built with the test's own
moduleandconverthelpers on--windows, each with a control. Onmain, every callback case gets its GS access rewritten and both table cases get the table rewritten. With this PR:LEAlea rax, cb; test rbx, rbx; cmove rbx, rax; call rbxmov rbx, raxlea rbx, cb; test edi, edi; jne use; 60 × nop; jmp use; use: mov esi, 1; call rbxnoplea rax, cb; 66 90; mov [rdi], rax66 90lea rdx, table; movzx edx, byte [rdi]; call fmov edx, [rdi]In
CodeInstructionCollector.cppat the head:cmovccdoes not copy the tracked register, andmovzx,movsx,setccandimul r, rmdo not end it.visited(L55, L58) keys on the position and the tracked set, not on the path length. The fall-through is followed before the pending taken edge (L159–162). Here the fall-through reachesuseat instruction 63 and runs out, and the taken edge, which reachesuseat instruction 3, is then refused as visited. The same order decides which states the 256 cap keeps.RegisterBit(0)to0x90(nop,66 90,pause), so the path ends wheneverraxis tracked. Without REX,0xb4–0xb7map torsp–rdiinstead ofah–bh.The first three cases move callbacks that
maintreats as code to the data side, so their GS access is no longer rewritten. The new test does not cover a store or push, a return inrax, an indirectjmp, or an argument at an indirect call.AI-assisted: yes.