Skip to content

fix(relinker): treat DT_INIT_ARRAY without DT_INIT_ARRAYSZ as empty - #6545

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
Get-fix:ps4/relinker-init-array-without-size
Oct 19, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
Get-fix:ps4/relinker-init-array-without-size

Conversation

@Get-fix

@Get-fix Get-fix commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

What

The OpenOrbis create-fself drops a DT_INIT_ARRAYSZ of 0. A PS4 program without global constructors therefore has DT_INIT_ARRAY and no size in its eboot.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:

FAIL: Code analysis: incomplete initializer array

FreeBSD 11.4's rtld takes the number of initializers only from DT_INIT_ARRAYSZ (rtld.c), and obj_new zero-fills the object (map_object.c), so such an array calls nothing. Code analysis now adds no roots for it, which is what EntryPointCollector already 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, on main 44df21632:

  • init_array_roots has 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.
  • Fritz Dash 0aa9324 and ClassiCube 33891a4, built for PS4 from source with the OpenOrbis toolchain and LLVM 21, each eboot.bin made by create-fself as its makefile does. Without this change both stop at the line above; with it both convert. With my open PS4 pull requests:
    • Fritz Dash plays: its menu, level select and the first level run at 59.94 FPS, driven by the keyboard's controller mapping.
    • ClassiCube starts and draws its launcher at 1920x1080, and goes no further on any platform: the file functions in its PS4 port (src/ps4/Platform_PS4.c) are stubs that return 100.
  • Full ctest of main with this and my open pull requests: 1305 of 1307 pass. agc_driver_gpu_indirect_arguments_misaligned_writer_ahead does not compile with MinGW on main (test(agc): align the indirect arguments block at run time #6452 fixes it), and prx_thread_local_destructors fails as it did on main 92cdc7b62 on this machine without my changes.
  • tools/check_conventions.py passes.

Not tested on Linux or macOS.

Checklist

🤖 Generated with Claude Code

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 jotitadev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 main on 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_roots stops at init-without-size with FAIL: Code analysis: incomplete initializer array. With the fix it passes.
  • The test only converts with --windows, so I ran the init-without-size fixture 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.

@simonbronk

Copy link
Copy Markdown
Contributor

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:

  • missing and explicit-zero sizes at an unmapped address are accepted without reading it;
  • a nonempty array retains a distinct constructor as a second live region (empty arrays leave one);
  • size-only 0/8, partial entries and unmapped nonempty arrays remain rejected;
  • all new input bytes remain unchanged, and all 18 valid Windows outputs execute with exit 42.

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.
strict-empty-arrays-pr6545.zip

@jotitadev jotitadev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@coltken95

Copy link
Copy Markdown

Tested on Linux x86-64 (Release build), with 284fc6f merged into main 31cbb55:

  • With the PR: init_array_roots (test_init_array_roots.py) passes.
  • With main's CodeInstructionCollector.cpp: the init-without-size case fails. The relinker refuses with FAIL: Code analysis: incomplete initializer array instead of converting.

AI-assisted: yes (Claude Code)

@Get-fix

Get-fix commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

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 StrictNidFilter change 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

@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 6607 core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp
PR 6974 core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp

@adriadam10 adriadam10 self-assigned this Oct 19, 2026
@adriadam10
adriadam10 merged commit b44d012 into boykopovar:main Oct 19, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants