Repository navigation
fix(relinker): treat DT_INIT_ARRAY without DT_INIT_ARRAYSZ as empty - #6545
Conversation
The OpenOrbis create-fself drops a DT_INIT_ARRAYSZ of 0, so a PS4 program without constructors, such as the ClassiCube PS4 port, has DT_INIT_ARRAY and no size. Code analysis rejected it with "incomplete initializer array". FreeBSD 11.4's rtld takes the number of initializers only from DT_INIT_ARRAYSZ and starts it at 0, so such an array calls nothing; code analysis now adds no roots for it. A size without an array still fails.
jotitadev
left a comment
There was a problem hiding this comment.
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. Head 284fc6fd8 merged without a commit onto main 44df21632, built twice: native arm64, and x86_64 under Rosetta 2 with /usr/bin/python3 3.9.6.
- Full ctest: arm64 173/173. x86_64 + Python 3.9: 170/173, the same three failures as plain
mainon that build (pr_overlap_tools,release_package,linux_fixed_base, all Python 3.10-only APIs), so no new failure. - The new cases fail without the fix on both builds: with only the test applied,
init_array_rootsstops atinit-without-sizewithFAIL: Code analysis: incomplete initializer array. With the fix it passes. - The test only converts with
--windows, so I ran theinit-without-sizefixture from the test through each target on both builds (unused-filter=1):
| Target | main |
this PR |
|---|---|---|
--macos (x86_64 Mach-O) |
incomplete initializer array |
converts, CFG/GOT filtering: 1 -> 0 |
--windows |
incomplete initializer array |
converts, CFG/GOT filtering: 1 -> 0 |
| Linux (default) | converts | converts, unchanged |
The same fixture with DT_INIT_ARRAYSZ present 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.
|
I reproduced the strict-mode gap noted in the description and prepared an incremental candidate for head 284fc6f. 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 44df216. 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. |
jotitadev
left a comment
There was a problem hiding this comment.
The same case in a guest module (.prx under sce_module) still fails with this PR, earlier, in GuestImageReader::readLifecycleArray, which requires the size tag whenever DT_INIT_ARRAY is present:
FAIL: .../sce_module/module.prx: Incomplete guest lifecycle array
Reproduced on macOS 27.2 (Apple M2 Max, arm64, relinker-only Release) at 284fc6f with the guest_none_relocations module fixture (lifecycle arrays at TARGET) after dropping DT_INIT_ARRAYSZ: Linux, --windows and --macos all 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: readLifecycleArray reads a missing size as an empty array (init and fini), a size without an array still fails, plus three cases in guest_none_relocations. arm64 173/173, x86_64 under Rosetta with Python 3.9 matches main. 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.
|
Tested on Linux x86-64 (Release build), with 284fc6f merged into main 31cbb55:
AI-assisted: yes (Claude Code) |
|
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 AI-assisted: yes (Claude Code). 🤖 Generated with Claude Code |
|
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.
|
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(test(agc): align the indirect arguments block at run time #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