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

Merged
Get-fix merged 1 commit from upstream-pr/6545 into main 2026-10-19 06:22:07 +00:00
Get-fix commented 2026-10-15 19:43:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Get-fix on 2026-10-15T19:43:15Z.


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 (#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

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PS4 homebrew Fritz Dash and ClassiCube, #3093
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4878896303 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6545). Originally posted by [Get-fix](https://github.com/Get-fix) on 2026-10-15T19:43:15Z. --- ### 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](https://github.com/BrianBoitano/fritz-dash) (a one-button platformer) and the PS4 port of [ClassiCube](https://github.com/ClassiCube/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](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/libexec/rtld-elf/rtld.c#L1230-L1236)), and `obj_new` zero-fills the object ([map_object.c](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/libexec/rtld-elf/map_object.c#L437-L447)), 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` (#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 <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PS4 homebrew Fritz Dash and ClassiCube, #3093 - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jotitadev commented 2026-10-15 20:01:54 +00:00 (Migrated from github.com)

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. 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5539157015 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6545#pullrequestreview-5539157015). Originally posted by [jotitadev](https://github.com/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`. 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 commented 2026-10-15 20:07:24 +00:00 (Migrated from github.com)

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:

  • 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 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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6201234392 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6545#issuecomment-6201234392). Originally posted by [simonbronk](https://github.com/simonbronk) on 2026-10-15T20:07:24Z. --- I reproduced the strict-mode gap noted in the description and prepared an incremental candidate for head 284fc6fd8c18ca8d1ae0c24a662f32dce7528471. 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 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](https://github.com/user-attachments/files/33513761/strict-empty-arrays-pr6545.zip)
jotitadev commented 2026-10-15 20:08:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-15T20:08:52Z.

Review: COMMENTED


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 284fc6fd8 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5539238762 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6545#pullrequestreview-5539238762). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-15T20:08:52Z. **Review:** COMMENTED --- 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 284fc6fd8 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 commented 2026-10-15 21:42:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-15T21:42:39Z.


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

  • 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)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6202889104 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6545#issuecomment-6202889104). Originally posted by [coltken95](https://github.com/coltken95) on 2026-10-15T21:42:39Z. --- Tested on Linux x86-64 (Release build), with 284fc6fd8 merged into main 31cbb55d7: - 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 commented 2026-10-15 23:26:23 +00:00 (Migrated from github.com)

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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6204394129 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6545#issuecomment-6204394129). Originally posted by [Get-fix](https://github.com/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 `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](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-18 16:33:54 +00:00 (Migrated from github.com)

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.

Pull request Shared files not compared
PR 6607 core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp
PR 6974 core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6252351877 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6545#issuecomment-6252351877). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T16:33:54Z. --- <!-- pr-overlap --> 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](https://www.github.com/boykopovar/AnyPS5/pull/6607) | `core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp` | | [PR 6974](https://www.github.com/boykopovar/AnyPS5/pull/6974) | `core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp` |
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!6545
No description provided.