feat(libc): unwind guest frames and keep the host's exception runtime in lifted builds #15800

Closed
oberonlift wants to merge 15 commits from upstream-pr/15800 into main
oberonlift commented 2026-11-04 16:23:56 +00:00 (Migrated from github.com)

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


Merge after #15799. Until the PRs before it merge, this PR also shows their changes; oberonlift/AnyPS5#10 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 4 of 8 PRs that let AnyPS5's libraries run a lifted program; the lifter itself follows them.

x86-64: unchanged: the code compiles to the same objects, apart from the line numbers in error messages. The new host_exception_pointer test builds and runs in every build; in CI's lifted build it runs from the last PR of the series on, since libc first compiles for a lifted guest there.

What

  • The DWARF unwinder starts from the guest frame that called the import, finds frames through the unwind tables of the guest images, resolves the personality routine from its import name and installs a landing pad by handing its registers back to the guest CPU, through new GuestCpu functions.
  • In a lifted build ElfTypes.hpp redirects dl_iterate_phdr to the runtime's GuestCpuIterateImages, which lists the guest images. libc and libkernel include ElfTypes.hpp instead of <link.h> where they walk images (the unwinder, the application heap's process parameters, direct memory, module info and the AGC driver's guest memory), so each of them sees the guest images.
  • Lifted builds don't export the host ABI's exception names: Exports.cpp's __cxa_* and _Unwind_* aliases and Personality.cpp's global __gxx_personality_v0. A lifted executable loads libc before libstdc++ and libgcc_s, so the host's own throw bound to libc's versions and aborted.
  • A lifted build keeps the host's C++ runtime, but with libstdc++ libc still defined std::current_exception, std::rethrow_exception and exception_ptr's members over its own runtime. Host code that caught an exception then got a null exception_ptr: the AGC driver reported a failed compute dispatch as "null asynchronous failure" and terminated. Lifted builds now give the guest its own exception pointer type, as libc++ builds do, and leave the host's exception pointers to the host runtime; HostExceptionPointer tests it. The guest's _Result_base destructor export releases the guest pointer in place.
  • The libc debt notes record that a lifted build calls only AnyPS5's personality routines and does not unwind through native frames.

#5021 also changes some of the same files: GuestMemory.cpp, GuestAllocations.cpp, DirectMemory.cpp, ModuleInfo.cpp.

Tested

Compiled for x86-64 Linux before and after this PR (GCC 13, same flags): 226 of the 227 objects it reaches are byte-identical, and Exports.cpp differs only in line-number constants; the new host_exception_pointer test builds after it only.

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: #15799
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5157734145 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15800). Originally posted by [oberonlift](https://github.com/oberonlift) on 2026-11-04T16:23:56Z. --- **Merge after #15799.** Until the PRs before it merge, this PR also shows their changes; oberonlift/AnyPS5#10 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 4 of 8 PRs that let AnyPS5's libraries run a lifted program; the lifter itself follows them. **x86-64:** unchanged: the code compiles to the same objects, apart from the line numbers in error messages. The new `host_exception_pointer` test builds and runs in every build; in CI's lifted build it runs from the last PR of the series on, since libc first compiles for a lifted guest there. ### What - The DWARF unwinder starts from the guest frame that called the import, finds frames through the unwind tables of the guest images, resolves the personality routine from its import name and installs a landing pad by handing its registers back to the guest CPU, through new `GuestCpu` functions. - In a lifted build `ElfTypes.hpp` redirects `dl_iterate_phdr` to the runtime's `GuestCpuIterateImages`, which lists the guest images. libc and libkernel include `ElfTypes.hpp` instead of `<link.h>` where they walk images (the unwinder, the application heap's process parameters, direct memory, module info and the AGC driver's guest memory), so each of them sees the guest images. - Lifted builds don't export the host ABI's exception names: `Exports.cpp`'s `__cxa_*` and `_Unwind_*` aliases and `Personality.cpp`'s global `__gxx_personality_v0`. A lifted executable loads libc before libstdc++ and libgcc_s, so the host's own `throw` bound to libc's versions and aborted. - A lifted build keeps the host's C++ runtime, but with libstdc++ libc still defined `std::current_exception`, `std::rethrow_exception` and `exception_ptr`'s members over its own runtime. Host code that caught an exception then got a null `exception_ptr`: the AGC driver reported a failed compute dispatch as "null asynchronous failure" and terminated. Lifted builds now give the guest its own exception pointer type, as libc++ builds do, and leave the host's exception pointers to the host runtime; `HostExceptionPointer` tests it. The guest's `_Result_base` destructor export releases the guest pointer in place. - The libc debt notes record that a lifted build calls only AnyPS5's personality routines and does not unwind through native frames. #5021 also changes some of the same files: `GuestMemory.cpp`, `GuestAllocations.cpp`, `DirectMemory.cpp`, `ModuleInfo.cpp`. ### Tested Compiled for x86-64 Linux before and after this PR (GCC 13, same flags): 226 of the 227 objects it reaches are byte-identical, and `Exports.cpp` differs only in line-number constants; the new `host_exception_pointer` test builds after it only. 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: #15799 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [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!15800
No description provided.