feat: find a lifted program's guest images, load its modules and switch its fibers #15804

Closed
oberonlift wants to merge 33 commits from upstream-pr/15804 into main
oberonlift commented 2026-11-04 16:24:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oberonlift on 2026-11-04T16:24:08Z.


Merge after #15803. Until the PRs before it merge, this PR also shows their changes; oberonlift/AnyPS5#14 shows only its own.

ps5lift is a static recompiler for PS5 executables: it lifts a game's x86-64 code to LLVM IR and compiles it ahead of time to aarch64, which runs on Linux against AnyPS5's own libraries with no interpreter or JIT. It runs AnyPS5's PS5-style test programs and a homebrew media player to its home screen; commercial games are not playable yet. Branch ps5lift-preview merges all of its PRs (how to try it); native Apple Silicon support is coming along fast. It is a separate approach from the ARM64 compiler in #5021; #1835 has an introduction.

This is 8 of 8 PRs that let AnyPS5's libraries run a lifted program; the lifter itself follows them.

x86-64: behaviour unchanged. The native module lifecycle runs through the state machine it now shares with lifted modules.

What

ps5lift's runtime maps a lifted program's executable and modules; the host's dynamic loader never sees them.

  • dlopen resolves the path as the native loader would and takes the lifted image whose path ends with it, or with it and .guest.prx appended, so a system library path still reaches AnyPS5's library when the title ships a module of the same name. It runs the module's lifecycle table through guest calls. Symbols come from that image's export table, and dlopen(NULL), whose handle is the executable's module ID, and the default scope search every image. A name that is not lifted still goes to the native loader; the lifecycle state machine is shared between the two paths.
  • Module queries (sceKernelGetModuleInfoFromAddr, sceKernelGetModuleInfoForUnwind, sceKernelGetModuleList, module info by handle, thread_atexit) find an image through dl_iterate_phdr and identify it by the address of its first loadable segment, so a module's ID matches its load handle. Lifted images are never system images and are never unloaded.
  • libSceFiber gives every fiber its own host stack, switches host stacks on aarch64, and saves and restores the guest registers around each switch through GuestCpu. Resuming a suspended fiber on a thread other than the one that started it throws, until each fiber has a guest state of its own.
  • The libkernel and libSceFiber debt entries record what still differs.
  • CI: the workflow builds every library, and ps5lift/tests/lifted_tests.txt names the 2,285 tests that pass with this PR, up from 101.

#5021 also changes some of the same files: DynamicLoader.cpp, ModuleInfo.cpp, Rtld.cpp.

Tested

Compiled for x86-64 Linux before and after this PR (GCC 13, same flags): 154 of the 155 objects it reaches are byte-identical; DynamicLoader.cpp differs by the lifecycle it now shares with lifted modules.

On a DGX Spark (aarch64 Linux, NVIDIA GB10, LLVM 18), with all eight PRs and ps5lift on top: every library builds for a lifted program, 2,285 of AnyPS5's own tests pass in that build on lavapipe, and ps5lift's 69 tests pass, among them its libc, exceptions, kernel, fiber and module-loading fixtures and upstream's libc test programs.

The conventions check passes on this branch.

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: #15803
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GB10, driver 580.178.04, Ubuntu 24.04.5 (DGX OS)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5157737121 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15804). Originally posted by [oberonlift](https://github.com/oberonlift) on 2026-11-04T16:24:08Z. --- **Merge after #15803.** Until the PRs before it merge, this PR also shows their changes; oberonlift/AnyPS5#14 shows only its own. **ps5lift** is a static recompiler for PS5 executables: it lifts a game's x86-64 code to LLVM IR and compiles it ahead of time to aarch64, which runs on Linux against AnyPS5's own libraries with no interpreter or JIT. It runs AnyPS5's PS5-style test programs and a homebrew media player to its home screen; commercial games are not playable yet. Branch [`ps5lift-preview`](https://github.com/oberonlift/AnyPS5/tree/ps5lift-preview) merges all of its PRs ([how to try it](https://github.com/oberonlift/AnyPS5/blob/ps5lift-preview/PS5LIFT_PREVIEW.md)); native Apple Silicon support is coming along fast. It is a separate approach from the ARM64 compiler in #5021; #1835 has an introduction. This is 8 of 8 PRs that let AnyPS5's libraries run a lifted program; the lifter itself follows them. **x86-64:** behaviour unchanged. The native module lifecycle runs through the state machine it now shares with lifted modules. ### What ps5lift's runtime maps a lifted program's executable and modules; the host's dynamic loader never sees them. - `dlopen` resolves the path as the native loader would and takes the lifted image whose path ends with it, or with it and `.guest.prx` appended, so a system library path still reaches AnyPS5's library when the title ships a module of the same name. It runs the module's lifecycle table through guest calls. Symbols come from that image's export table, and `dlopen(NULL)`, whose handle is the executable's module ID, and the default scope search every image. A name that is not lifted still goes to the native loader; the lifecycle state machine is shared between the two paths. - Module queries (`sceKernelGetModuleInfoFromAddr`, `sceKernelGetModuleInfoForUnwind`, `sceKernelGetModuleList`, module info by handle, `thread_atexit`) find an image through `dl_iterate_phdr` and identify it by the address of its first loadable segment, so a module's ID matches its load handle. Lifted images are never system images and are never unloaded. - libSceFiber gives every fiber its own host stack, switches host stacks on aarch64, and saves and restores the guest registers around each switch through `GuestCpu`. Resuming a suspended fiber on a thread other than the one that started it throws, until each fiber has a guest state of its own. - The libkernel and libSceFiber debt entries record what still differs. - **CI**: the workflow builds every library, and `ps5lift/tests/lifted_tests.txt` names the 2,285 tests that pass with this PR, up from 101. #5021 also changes some of the same files: `DynamicLoader.cpp`, `ModuleInfo.cpp`, `Rtld.cpp`. ### Tested Compiled for x86-64 Linux before and after this PR (GCC 13, same flags): 154 of the 155 objects it reaches are byte-identical; `DynamicLoader.cpp` differs by the lifecycle it now shares with lifted modules. On a DGX Spark (aarch64 Linux, NVIDIA GB10, LLVM 18), with all eight PRs and ps5lift on top: every library builds for a lifted program, 2,285 of AnyPS5's own tests pass in that build on lavapipe, and ps5lift's 69 tests pass, among them its libc, exceptions, kernel, fiber and module-loading fixtures and upstream's libc test programs. The conventions check passes on this branch. ### Checklist - [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: #15803 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GB10, driver 580.178.04, Ubuntu 24.04.5 (DGX OS) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)

Pull request closed

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!15804
No description provided.