Skip to content

fix(relinker): infer guest dependencies from referenced imports - #6903

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
Zinebyte:fix/guest-unused-import-dependencies
Oct 20, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
Zinebyte:fix/guest-unused-import-dependencies

Conversation

@Zinebyte

@Zinebyte Zinebyte commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What

A bundled guest module can retain an undefined dynamic symbol without any relocation using it. If a runtime-only plugin exports that symbol, conversion currently infers an initialization dependency and loads the plugin at startup. A native regression shows its initializer runs even though the executable and bundled module never reference it.

Infer module-to-module initialization dependencies from symbols used by non-NONE RELA or PLT relocations, as the executable path already does. Preserve explicitly declared dependencies and normal import resolution. Windows retains its existing eager DLL-loading policy; its initializer state and import-table controls are covered by metadata checks.

Tested

Linux x86-64, GCC 13.3, Release relinker-only build on main d9b696ddbb: all 183 CTests pass. The 27 focused cases cover Linux, macOS and Windows output: unreferenced strong/weak imports, NONE relocations, real strong/weak and PLT references, explicit needed libraries, missing strong imports and declared dependency cycles. Native Linux processes verify initializer events and exit values. The unchanged baseline runs the supposedly deferred initializer; the fix leaves it deferred. Native macOS/Windows execution and retail titles were not tested locally.

Independently reviewed the Windows writer's relocation-based import collection. A clean combined merge with #6105 5c378ece37 and #6106 b50ab4eb43 passes six targeted tests, and component-filtered runs select both new tests. Their production changes are independent. Hosted Build 38940688286 passed on exact head 6b14c31437: Linux 183/183 tests, Windows 178/178 and macOS 174/174. The 27-case regression passed on every host. Conventions and whitespace checks pass. After the registration-only follow-up, hosted Build 38951158365 also passed on current head 61fe1795fa5c07124f01093f01294745f131087e: the Linux, Windows and macOS relinker jobs succeeded, and Conventions passed. The full Linux and Windows runtime jobs were skipped under the contribution policy.

Checklist

  • Based on current main; no other open PR implements the same fix
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@github-actions

github-actions Bot commented Oct 16, 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 5021 core/relinker/CMakeLists.txt
PR 6044 core/relinker/CMakeLists.txt
PR 6618 core/relinker/CMakeLists.txt
PR 6879 core/relinker/CMakeLists.txt
PR 6977 core/relinker/CMakeLists.txt
core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
PR 7332 core/relinker/CMakeLists.txt

@DProkos

DProkos commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Windows check of 61fe179 merged onto current main (c4c2b3aa7, clean merge).

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release, ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON, Python 3.11.0.

  • guest_unused_import_dependencies: passed.
  • Full relinker suite: 197/197 passed.

Negative control: with GuestModuleBuilder.cpp restored to main and the new test kept, guest_unused_import_dependencies fails on the unreferenced case: the provider still appears in the root module's needed list ($ORIGIN/app0/Media/Plugins/provider.prx.guest.prx).

Not run: titles or homebrew.

AI-assisted: yes

@adriadam10 adriadam10 self-assigned this Oct 19, 2026
@adriadam10
adriadam10 merged commit 77c18ce into boykopovar:main Oct 20, 2026
10 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked: module-to-module dependencies now come only from symbols used by non-NONE RELA/PLT relocations, matching the executable path; declared needed libraries are kept. The new test fails without the change (negative control by @DProkos on Windows), and the CMake registration still merges cleanly on current main. Relinker jobs green on all three hosts; merged.

lulebo added a commit to lulebo/AnyPS5 that referenced this pull request Oct 20, 2026
…st-loading option

guest_unused_import_dependencies, added in boykopovar#6903, runs its relinked
Linux programs against copies of the instrumented
guest_module_args_host.prx in libs/, as guest_module_args,
guest_deferred_dependencies, guest_module_fini and
guest_zero_initializer do. Those four run with
verify_asan_link_order=0 through add_asan_test_options (boykopovar#7147); this
one did not, so in an ANYPS5_ENABLE_ASAN build the program of its
referenced case exited with 1 and "ASan runtime does not come first in
initial library list" instead of 42. It now runs with the same option,
which changes nothing outside ASan builds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants