fix(relinker): collect init and fini array roots through the containing load segment #2330
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2330"
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:41:53Z.
What
At
unused-filter=1,EntryPointCollectortranslated DT_INIT_ARRAY and DT_FINI_ARRAY through PT_DYNAMIC and skipped an array placed before it, which is the usual linker layout. Constructors and destructors were then not CFG roots, and imports used only by them were removed. A slot whose value exists only as a RELATIVE addend was read as 0.Arrays are now translated through the PT_LOAD that holds them, slot targets come from RELATIVE relocations when present, 0 and -1 are skipped, and DT_PREINIT_ARRAY is collected, as in the strict filter. An array outside every file-backed PT_LOAD, or with a size that is not a multiple of 8, throws.
Changes the same lambda as #2196 (bounds checks); the conflict is textual.
Tested
macOS arm64, relinker-only Release build: ctest 39/39.
test_init_array_roots.pycovers arrays before and after PT_DYNAMIC, SCE tags, RELATIVE addends, terminators, FINI and PREINIT arrays, and an array outside every PT_LOAD. On main the arrays before PT_DYNAMIC, the addend-only slots and PREINIT reportCFG/GOT filtering: 1 -> 0. No title was converted from a retail dump.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, 22 of the 38 titles that convert keep 1 to 14 more imports (86 in total), on both outputs; none keeps fewer.
Linux (Ubuntu 24.04, GCC 13.3), relinker-only Release build: ctest 44/44.
Runtime check on Linux (Ryzen 9 9950X, RTX 3090, NVIDIA 595.99.02) with Yamagi Quake II PPSA99007 0.2.0-alpha.1 from the catalog, relinked with
--registry unused-filter=1. Both trees carry #1529, without which the bundledlibc.prxshim takes the title's libc imports on Linux (#1497); this PR does not depend on it.maind70b8998+ #15290xfec30) callsfreopenthrough its removed GOT slotpthread_key_create, which #2332 keepsThe title does not reach its menu with either change: at level 1 with #2332 it keeps 20 imports that AnyPS5 does not implement yet.
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:53:00Z.
Tested on Linux (CachyOS x86_64, Intel RPL-S iGPU / Mesa 26.3.0-devel / Vulkan 1.4.363, GCC 16.2.1) at
bfaad395:/tmp/anyps5_build) with zero warnings/errors.python3 tools/check_conventions.py --base origin/main --head HEAD-> PASS (0 errors)..init_arrayand.fini_arrayroot collection inrelinker. Guarantees guest static initializers are preserved during pruning.LGTM!
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T05:18:51Z.
This conflicts with main in
core/relinker/CMakeLists.txt; please rebase. I'll take #2196 first, since both change the same lambda inEntryPointCollector.cpp, so expect one more rebase after it.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:27:47Z.
Rebased onto current
main(#2196 landed): kept both tests incore/relinker/CMakeLists.txt, and inEntryPointCollector.cppkeptfitsAtfor the other reads and this PR'scollectArray. Local relinker build and ctest pass, includingentry_point_boundsandinit_array_roots. Merging.