fix(relinker): treat address-taken code as reachable in unused-filter=1 #2332
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2332"
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 simonbbby on 2026-10-09T15:42:00Z.
What
At
unused-filter=1the CFG followed only direct branches andcall/jmp [rip+slot]through RELATIVE-relocated slots. Code reached through a register (lea reg, [rip+f]; call reg, vtables and callback tables, switch jump tables) was unreachable, and imports used only there were removed. GOT accesses were counted only formovloads andcall/jmp [rip+slot].The CFG now also walks RELATIVE relocation targets in text, RIP-relative
leatargets, and int32 jump tables at alea'd data address, using the strict filter's walk moved toReadRelativeTableTargets. Any RIP-relative operand that names a GOT slot counts as an access. Address-taken targets are walked after the direct control flow. A target that does not decode is not code and ends that path, so a stray table entry cannot abort the conversion. Strict filter behaviour is unchanged.Absolute immediates (
mov r, imm,push imm) and raw data words pointing into text are still not roots at level 1.Changes the same files as #2238 (LEA roots for the Windows TLS collector) and #2304 (CFG decoding performance), with a different scope.
Tested
macOS arm64, relinker-only Release build: ctest 39/39,
strict_nid_filterunchanged.test_unused_filter_indirect.pycovers lea + call reg, a RELATIVE pointer called through a register, a jump-table case block, GOT access by lea/push/cmp, two unreachable controls, and two address-taken targets on undecodable bytes. On main the six indirect cases reportCFG/GOT filtering: 1 -> 0. No title was converted from a retail dump.Linux (Ubuntu 24.04, GCC 13.3), relinker-only Release build: ctest 44/44.
Also converted 43 open-source titles from the PS5 homebrew catalog (eboot.bin and bundled libc.prx, unwrapped from fSELF) with main and with this branch, for Linux and Windows at unused-filter 0, 1 and 2. No conversion changed outcome. At unused-filter=1, all 38 titles that convert keep more imports, 1 to 283 each (5,812 in total), on both outputs; none keeps fewer.
Runtime check on Linux (Ryzen 9 9950X, RTX 3090, NVIDIA 595.99.02) with DOOM PPSA99666 v1.1.1 from the catalog. Both trees relink it with
--registry unused-filter=1and run the title's owntest/console-play.cfgwithout itsserveline: it startsdoom1.wad, plays and exits at frame 900. Both trees carry #1529, without which the bundledlibc.prxshim takes DOOM's libc imports on Linux (#1497); this PR does not depend on it.maind70b8998+ #1529HU_Init, before the first frame (2 of 2 runs)On
mainthe crash is a call to address 0 in the audio thread. Its start routine is referenced only by theleathat passes it topthread_create, so level 1 dropssceAudioOutOutput, which the thread loads withmov <GOT>, %r14and calls through%r14. The other 59 dropped imports include ones used by the download worker and upload server threads (sceHttp*,accept), the on-screen keyboard (sceImeDialog*) and music (log10). At levels 0 and 2 both trees produce the same executable. #2238 and #2304, built the same way, produce a level-1 executable byte-identical tomain's.ScreenTester5 PPSA69420 on
mainand Yamagi Quake II PPSA99007 with #2330, both at level 1, stop on a call through the removed GOT slot ofpthread_key_create. This branch keeps that slot. Both titles then keep imports that AnyPS5 does not implement yet and stop at load instead: ScreenTester5 withundefined symbol: MhC53TKmjVA(sysctlbyname); for Quake II the import audit lists 20.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-09T17:52:55Z.
Tested on Linux (CachyOS x86_64, Intel RPL-S iGPU / Mesa 26.3.0-devel / Vulkan 1.4.363, GCC 16.2.1) at
4ea9f974:/tmp/anyps5_build) with zero warnings/errors.python3 tools/check_conventions.py --base origin/main --head HEAD-> PASS (0 errors).unused-filter=1. Essential for indirect jump tables and function pointers in stripped guest modules.LGTM!
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T05:18:55Z.
Please rebase onto main: #2238 landed and conflicts in
ControlFlowGraph.cppandcore/relinker/CMakeLists.txt.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:26:02Z.
Review: CHANGES_REQUESTED
Thanks, the DOOM measurement is convincing. This needs a rebase onto
mainafter #2238, and the conflict inControlFlowGraph.cppis not mechanical, so it should be resolved by you:BuildControlFlowGraphonmainnow takesbool followCodeAddresses(REX.Wlearip-relative → enqueue the target). This PR replaces that same parameter withconst std::vector<StrictDataRegion>* dataand handles the sameleawithtakeAddressplus jump-table targets. Please unify them: either keep one parameter that covers both cases or keep both explicitly, and make sure theleatarget is not enqueued twice with different rules (#2238's callers must keep their behaviour; its tests must still pass).core/relinker/CMakeLists.txt: keep bothentry_point_boundsandunused_filter_indirectadd_testentries.After the rebase please rerun
unused_filter_indirectandtls_function_coverage.Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-10T10:05:19Z.
Additional platform validation on standalone PR head
4ea9f9748fd948396923c29ff76d2578e99af93e:Windows: passed — Windows 11, supported WinLibs GCC 15.2.0 UCRT/POSIX/SEH r7; CMake 4.3.1 / Ninja.
Release /
BUILD_TESTING=ON: built the selected test targets; 41 CTest cases, 0 failures, 0 CTest skips.All 41 registered relinker tests passed (
ANYPS5_RELINKER_ONLY=ON).Integration limitation: a local merge against main
948a526c2has source conflicts; these results validate the standalone PR head, not a resolved merge.Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-10T13:41:32Z.
Rebased onto
main78aedb40, after #2238, #2330, #2304 and #2708.followCodeAddressesand the data regions: I kept both, explicitly, as two arguments of one internalbuildGraph. It walks #2304'sstd::spantext into the caller-ownedreachableset.BuildControlFlowGraphoverloads keep #2304's signatures and pass no data regions. #2238's rule is the onlylearule there: the target is enqueued directly and decoded strictly, and addresses already in the caller's set are skipped, as onmain.BuildAddressTakenControlFlowGraph, which unused-filter=1 uses, passes the data regions andfollowCodeAddresses = false. Only this PR's rule applies there: the target, and any relative table at it, are walked after the direct control flow, and a target that doesn't decode is dropped.CMakeLists.txt:entry_point_bounds,init_array_rootsandunused_filter_indirectare all registered.main's XOP decoding (#2568), I converted the 43 catalog titles for Linux and for Windows at filter levels 0, 1 and 2, withmainand with this PR. No conversion result changes, on either platform, at any level. With this PR, Stremio Plus (PPSA74126), OpenNOW (PPSA99082) and PPSA99420 convert for Windows at level 1. They keep 433, 316 and 507 imports, against 196, 143 and 210 onmain.unused_filter_indirectand everytls_function_coverage_*case. At level 1, 38 titles keep more imports than onmain, the same set and counts as before the rebase. DOOM goes from 110 to 171 kept imports, and Quake II from 133 to 355. Levels 0 and 2 are unchanged.Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-10T17:52:34Z.
Checked
814fcc47merged onto currentmain(57f96fd2; clean merge) on Linux (Ubuntu 26.04 in WSL2, GCC 15.2.0, relinker-only Release build). The relinker ctest run is already covered by this PR's CI job; the checks below are the ones it does not do:unused_filter_indirectpins the change: with the nine non-test sources reverted tomain(the test and itsadd_testkept), it fails on exactly the six indirect cases the description lists:lea-call-register,relative-relocation-pointer,jump-table-case-block,got-slot-lea,got-slot-push,got-slot-compare. Thetls_function_coverage_*tests pass with and without the change, as expected.ControlFlowGraph.cppthe twolearules are behind different gates. #2238's (followCodeAddresses, REX.W only, enqueued directly) is the only one reachable from the threeBuildControlFlowGraphoverloads, which passdata = nullptr; this PR's (data != nullptr, any RIP-relativeleaplus the relative table at its target, deferred to the speculative pass) is reachable only fromBuildAddressTakenControlFlowGraph, which passesfollowCodeAddresses = false. No walk applies both.add_testblock only: all three append afterinit_array_roots(CMakeLists.txt:317) and share no source file (theUSAGE.mdlines differ and merge cleanly). Merging the three in sequence conflicts only in that block each time.Not checked here: the catalog conversions and the XOP question from the review (no titles on this machine), and nothing ran in a game.
AI-assisted: yes (Claude Code).
Edited: removed the ctest pass count, which this PR's relinker CI job already reports.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:32:55Z.
Review: APPROVED
Rebased onto current
main(one conflict incore/relinker/CMakeLists.txtafter #2119: kept bothto_rosettaandunused_filter_indirect). Relinker-scoped build and ctest: 91/91 pass.unused_filter_indirectfails with the non-test changes reverted. Merging on green CI.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:37:18Z.
Rebased onto current
main(one conflict incore/relinker/CMakeLists.txtafter #2119 and the newsyscall_number: kept both it andunused_filter_indirect). Relinker-scoped build and ctest: 93/93 pass.unused_filter_indirectfails with the non-test changes reverted. Merging on green CI.