fix(relinker): treat DT_INIT_ARRAY without DT_INIT_ARRAYSZ as empty #6545
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6545"
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 Get-fix on 2026-10-15T19:43:15Z.
What
The OpenOrbis
create-fselfdrops aDT_INIT_ARRAYSZof 0. A PS4 program without global constructors therefore hasDT_INIT_ARRAYand no size in itseboot.bin. Two plain-C PS4 homebrew games built with the toolchain are like that, Fritz Dash (a one-button platformer) and the PS4 port of ClassiCube, and the relinker stopped on both:FreeBSD 11.4's rtld takes the number of initializers only from
DT_INIT_ARRAYSZ(rtld.c), andobj_newzero-fills the object (map_object.c), so such an array calls nothing. Code analysis now adds no roots for it, which is whatEntryPointCollectoralready did. A size without an array still fails.StrictNidFilter(unused-filter=2) keeps its stricter check: the test fixture does not run in strict mode ("unsupported executable segment layout"), so I left it unchanged. Part of the PS4 homebrew work tracked in #3093.Tested
Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON, onmain44df21632:init_array_rootshas two new cases: an array without a size whose slot holds a function, which is not kept as an initializer, and one whose slot holds an address outside the image, which must not be read. Each of these makes the test fail: the old check, and reading a missing size as one entry.0aa9324and ClassiCube33891a4, built for PS4 from source with the OpenOrbis toolchain and LLVM 21, eacheboot.binmade bycreate-fselfas its makefile does. Without this change both stop at the line above; with it both convert. With my open PS4 pull requests:src/ps4/Platform_PS4.c) are stubs that return 100.mainwith this and my open pull requests: 1305 of 1307 pass.agc_driver_gpu_indirect_arguments_misaligned_writer_aheaddoes not compile with MinGW onmain(#6452 fixes it), andprx_thread_local_destructorsfails as it did onmain92cdc7b62on this machine without my changes.tools/check_conventions.pypasses.Not tested on Linux or macOS.
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 jotitadev on 2026-10-15T20:01:54Z.
Review: COMMENTED
Ran this on macOS, since the PR was only tested on Windows.
Machine: Apple M2 Max, macOS 27.2, Xcode 27 (AppleClang), relinker-only Release build with
BUILD_TESTING=ON. Head284fc6fd8merged without a commit ontomain44df21632, built twice: native arm64, and x86_64 under Rosetta 2 with/usr/bin/python33.9.6.mainon that build (pr_overlap_tools,release_package,linux_fixed_base, all Python 3.10-only APIs), so no new failure.init_array_rootsstops atinit-without-sizewithFAIL: Code analysis: incomplete initializer array. With the fix it passes.--windows, so I ran theinit-without-sizefixture from the test through each target on both builds (unused-filter=1):main--macos(x86_64 Mach-O)incomplete initializer arrayCFG/GOT filtering: 1 -> 0--windowsincomplete initializer arrayCFG/GOT filtering: 1 -> 0The same fixture with
DT_INIT_ARRAYSZpresent still keeps the function (1 -> 1) on all three targets, so homebrew without the size tag now converts for macOS output as well.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-15T20:07:24Z.
I reproduced the strict-mode gap noted in the description and prepared an incremental candidate for head
284fc6fd8c.Using the existing importing_executable fixture gives one immutable executable PT_LOAD, so the real CLI reaches the strict filter with unused-filter=2. DT_INIT_ARRAY at an unmapped address with explicit size 0 converts successfully; omit that size and the same pipeline stops with "Strict filter: incomplete constructor array metadata". This reproduces for both Linux and Windows output on this Windows host.
The attached patch changes two production lines in StrictNidFilter: a size without an array address still fails, while absent/zero sizes contribute no roots and do not inspect the address. This completes your existing CodeInstructionCollector change; it is not a standalone patch against main.
The regression extends test_init_array_roots.py with 84 CLI cases: standard/SCE INIT, FINI and PREINIT pairs × seven metadata shapes × Linux/Windows output. It checks:
The final regression fails on the untouched PR binary at its first new missing-size case. After the fix, 7/7 focused CTests pass in 8.08 s: strict_nid_filter, init_array_roots, needed_libraries, guest_registry, entry_point_bounds, gnu_hash_analysis and unused_filter_indirect. init_array_roots takes 8.06 s including its existing cases. The complete suite was not run.
Windows 11, WinLibs GCC 15.2r7 UCRT, Release relinker-only, Python 3.12.14. Incremental conventions check passes using the trusted main checker
44df2163. The patch applies to a private base index and both resulting canonical source blobs match the tested files; diff check passes. Bundle includes patch, source snapshots, before/after probe, scripts and logs.AI-assisted implementation and verification. Synthetic inputs only: no local Fritz Dash/ClassiCube/title run, full emulator/system-library build, GPU/FPS test, Linux/macOS host execution, or composition with other PRs/current main. Existing selected CTests may contain platform skips; no skips in the added matrix on Windows. The author still needs to review and apply the candidate.
strict-empty-arrays-pr6545.zip
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-15T20:08:52Z.
Review: COMMENTED
The same case in a guest module (
.prxundersce_module) still fails with this PR, earlier, inGuestImageReader::readLifecycleArray, which requires the size tag wheneverDT_INIT_ARRAYis present:Reproduced on macOS 27.2 (Apple M2 Max, arm64, relinker-only Release) at
284fc6fd8with theguest_none_relocationsmodule fixture (lifecycle arrays atTARGET) after droppingDT_INIT_ARRAYSZ: Linux,--windowsand--macosall stop there, with the slot relocated or zero. With the size tag present all three convert.I have a follow-up ready, stacked on this PR because the Windows conversion of such a module then reaches the code analysis check this PR changes:
readLifecycleArrayreads a missing size as an empty array (init and fini), a size without an array still fails, plus three cases inguest_none_relocations. arm64 173/173, x86_64 under Rosetta with Python 3.9 matchesmain. I'll open it once this one is merged, unless you'd rather have it here.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-15T21:42:39Z.
Tested on Linux x86-64 (Release build), with
284fc6fd8merged into main31cbb55d7:init_array_roots(test_init_array_roots.py) passes.CodeInstructionCollector.cpp: theinit-without-sizecase fails. The relinker refuses withFAIL: Code analysis: incomplete initializer arrayinstead of converting.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by Get-fix on 2026-10-15T23:26:23Z.
Thanks for testing this on macOS and Linux, @jotitadev and @coltken95. The macOS table is useful: these programs now convert for macOS output as well.
@jotitadev: yes, please open the guest-module follow-up as its own pull request, stacked on this one. I'd like to keep this one to the code-analysis case, as follow-ups go in new pull requests. I'll review and test yours when it's up.
@simonbronk: thanks for reproducing the strict-mode gap. Could you open the
StrictNidFilterchange and its cases as a pull request stacked on this one as well? That keeps your authorship, and reviewers can read the change in the pull request rather than in an attachment. I'll review and test it the same way.AI-assisted: yes (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T16:33:54Z.
Some 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.
core/relinker/relinker/src/analysis/CodeInstructionCollector.cppcore/relinker/relinker/src/analysis/CodeInstructionCollector.cpp