loader: rebind pending imports after module load #343

Closed
github-bot wants to merge 1 commit from gh-pr/343/head into gh-pr/343/base
Owner

@⁠Techx3 on GitHub · 2026-08-28 18:50 UTC · original
Techx3:techx3/loader-rebind-unresolved → main · +125 −0 · 5 files · 1 commits · closed without merging

Summary

  • Revisit imports in already-relocated programs after sceKernelLoadStartModule loads a shared module.
  • Patch only linker-owned pending values: null, the invalid-object sentinel, a registered import thunk, or the original ELF value used by unresolved STT_NOTYPE imports.
  • Preserve self/local bindings, valid resolved targets, and relocation slots modified by guest code.

Why

Late function thunks can resolve on first call, but unresolved object and STT_NOTYPE imports have no equivalent call path. Re-running RelocateAll would rewrite every live import slot. This change handles newly available exports without disturbing valid runtime state.

Implementation

  • Add RuntimeLinker::RebindPendingImports and invoke it after relocating a newly loaded module.
  • Centralize pending-target classification in a documented helper.
  • Scan both RELA and PLT tables only for already-relocated programs.
  • Log each changed slot and the final rebound count.
  • Add focused positive and negative classifier coverage.

Verification

  • Build of virtual_memory_allocation_tests: passed.
  • Focused executable test: passed.
  • CTest import_rebind_classifier: passed (1/1).
  • Full virtual_memory_allocation_tests could not reach its cases on this Windows host: InitSubsystems aborts in memoryAddressSpace.inc:662 because the required host reservation is unavailable. The focused classifier runs before subsystem initialization and is unaffected.

Adapted from the external development branch and expanded with stricter classification, documentation, and negative coverage. Original work is retained through the commit co-author trailer.

**@⁠Techx3** on GitHub · 2026-08-28 18:50 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/343) `Techx3:techx3/loader-rebind-unresolved` → `main` · +125 −0 · 5 files · 1 commits · closed without merging ## Summary - Revisit imports in already-relocated programs after sceKernelLoadStartModule loads a shared module. - Patch only linker-owned pending values: null, the invalid-object sentinel, a registered import thunk, or the original ELF value used by unresolved STT_NOTYPE imports. - Preserve self/local bindings, valid resolved targets, and relocation slots modified by guest code. ## Why Late function thunks can resolve on first call, but unresolved object and STT_NOTYPE imports have no equivalent call path. Re-running RelocateAll would rewrite every live import slot. This change handles newly available exports without disturbing valid runtime state. ## Implementation - Add RuntimeLinker::RebindPendingImports and invoke it after relocating a newly loaded module. - Centralize pending-target classification in a documented helper. - Scan both RELA and PLT tables only for already-relocated programs. - Log each changed slot and the final rebound count. - Add focused positive and negative classifier coverage. ## Verification - Build of virtual_memory_allocation_tests: passed. - Focused executable test: passed. - CTest import_rebind_classifier: passed (1/1). - Full virtual_memory_allocation_tests could not reach its cases on this Windows host: InitSubsystems aborts in memoryAddressSpace.inc:662 because the required host reservation is unavailable. The focused classifier runs before subsystem initialization and is unaffected. Adapted from the external development branch and expanded with stricter classification, documentation, and negative coverage. Original work is retained through the commit co-author trailer.
Revisit already-relocated import slots when a shared module is loaded, but patch only linker-owned pending sentinels. Preserve valid and guest-modified targets, and cover the classifier with a focused CTest case.

Co-authored-by: GodsWill <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:16:55 +00:00
github-bot closed this pull request 2026-11-26 09:16:55 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.