fix(libc): give abort and __stack_chk_fail the guest calling convention #17900

Open
klosixgaming-arch wants to merge 1 commit from upstream-pr/17900 into main
klosixgaming-arch commented 2026-11-09 21:19:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-11-09T21:19:25Z.


What

abort and __stack_chk_fail are defined in libc's Process.cpp without APS5_VABI (on the console __stack_chk_fail is a libkernel export; here it is defined in libc). On Windows that makes them Microsoft x64 functions called by SysV guest code. Both never return, so this has no visible effect: the change is for consistency with the guest convention and so the tools see the two exports. On Linux and macOS APS5_VABI is empty and the generated code is unchanged.

The definitions now have APS5_VABI, and so does the abort_nid_postfix declaration in BoundsChecking.cpp, which calls it. Clang rejects a sysv_abi definition after a declaration without it, so the two have to change together.

The tools find exports through their APS5_VABI definitions, so on main tools/progress.py does not count these two, tools/nid_names.py --where --name abort __stack_chk_fail finds neither (both with this branch), and pr_overlap.py's export pattern misses them. tools/progress.py --module libc --compare on main and this branch: libc 1738/1746 -> 1740/1748.

A scan of core/libs for _nid_postfix function definitions without APS5_VABI whose names are in aerolib found these two and _ZSt17iostream_categoryv, which #14796 already changes, so it is left out here.

Tested

Ubuntu 24.04, GCC 13.3, Release, BUILD_TESTING=ON (configured with the SDL XRandR and audio checks relaxed locally for missing dev packages; no SDL code was built): libc, libkernel, libSceLibcInternal and guest_signal_tests build, and ctest -R guest_signals passes.

A throwaway program linked against the unpatched libraries forks, installs a guest SIGABRT handler with sigaction_nid_postfix and calls abort_nid_postfix. With the default disposition the process ends by SIGABRT. A handler that returns runs, then the process ends by SIGABRT. A handler that siglongjmps out runs and the process continues. With SIGABRT blocked through _sigprocmask_nid_postfix the handler does not run and the process ends by SIGABRT, where FreeBSD 11.4's abort unblocks it first; that is unchanged here. On Linux APS5_VABI is empty, so this shows the existing behaviour, not a change.

Windows, the only platform where the generated code changes: JJenkx's run below (Windows 11 22621, WinLibs GCC 15.2 UCRT, Release, 47b83fb merged onto f439f7f) builds and passes the libc tests in 3 of 3 runs. No test calls abort_nid_postfix or __stack_chk_fail_nid_postfix, so that run shows the change builds and nothing else regresses, not the two functions themselves.

python3 tools/check_conventions.py --base origin/main passes. tools/pr_overlap.py could not run here; open libc PRs were checked by hand. #9162, which the overlap report could not compare, changes only WaitChildProcess_nid_no_patch in Process.cpp.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a (no AGC, shader recompiler or VideoOut change)
  • AI-assisted: yes. Written with AI assistance and reviewed by me.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5231368511 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17900). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-11-09T21:19:25Z. --- ### What `abort` and `__stack_chk_fail` are defined in libc's `Process.cpp` without `APS5_VABI` (on the console `__stack_chk_fail` is a libkernel export; here it is defined in libc). On Windows that makes them Microsoft x64 functions called by SysV guest code. Both never return, so this has no visible effect: the change is for consistency with the guest convention and so the tools see the two exports. On Linux and macOS `APS5_VABI` is empty and the generated code is unchanged. The definitions now have `APS5_VABI`, and so does the `abort_nid_postfix` declaration in `BoundsChecking.cpp`, which calls it. Clang rejects a `sysv_abi` definition after a declaration without it, so the two have to change together. The tools find exports through their `APS5_VABI` definitions, so on main `tools/progress.py` does not count these two, `tools/nid_names.py --where --name abort __stack_chk_fail` finds neither (both with this branch), and `pr_overlap.py`'s export pattern misses them. `tools/progress.py --module libc --compare` on main and this branch: libc 1738/1746 -> 1740/1748. A scan of `core/libs` for `_nid_postfix` function definitions without `APS5_VABI` whose names are in aerolib found these two and `_ZSt17iostream_categoryv`, which #14796 already changes, so it is left out here. ### Tested Ubuntu 24.04, GCC 13.3, Release, `BUILD_TESTING=ON` (configured with the SDL XRandR and audio checks relaxed locally for missing dev packages; no SDL code was built): libc, libkernel, libSceLibcInternal and `guest_signal_tests` build, and `ctest -R guest_signals` passes. A throwaway program linked against the unpatched libraries forks, installs a guest SIGABRT handler with `sigaction_nid_postfix` and calls `abort_nid_postfix`. With the default disposition the process ends by SIGABRT. A handler that returns runs, then the process ends by SIGABRT. A handler that `siglongjmp`s out runs and the process continues. With SIGABRT blocked through `_sigprocmask_nid_postfix` the handler does not run and the process ends by SIGABRT, where FreeBSD 11.4's `abort` unblocks it first; that is unchanged here. On Linux `APS5_VABI` is empty, so this shows the existing behaviour, not a change. Windows, the only platform where the generated code changes: JJenkx's run below (Windows 11 22621, WinLibs GCC 15.2 UCRT, Release, 47b83fb merged onto f439f7f) builds and passes the libc tests in 3 of 3 runs. No test calls `abort_nid_postfix` or `__stack_chk_fail_nid_postfix`, so that run shows the change builds and nothing else regresses, not the two functions themselves. `python3 tools/check_conventions.py --base origin/main` passes. `tools/pr_overlap.py` could not run here; open libc PRs were checked by hand. #9162, which the overlap report could not compare, changes only `WaitChildProcess_nid_no_patch` in `Process.cpp`. ### 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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a (no AGC, shader recompiler or VideoOut change) - [x] AI-assisted: yes. Written with AI assistance and reviewed by me.
MarcZX10 commented 2026-11-22 11:44:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T11:44:43Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this; the points below are optional.

What I ran

Reviewed head 47b83fb894408503f4ab0873a03617f71a4bae9a and the prepared diff. No commands or tests were run.

Results

Check Result Note
Diff review passed Two libc source files
Tests not run Author reports platform runs

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests were run independently. I read core/libs/prx/libc/src/BoundsChecking.cpp, core/libs/prx/libc/src/Process.cpp, and core/libs/prx/libc/include/general/VabiMacros.hpp. The manifest lists two changed files and both full texts were available and read; no changed files were excluded. The description's reported build and test results were not independently verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6012036673 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17900#pullrequestreview-6012036673). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T11:44:43Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this; the points below are optional. ## What I ran Reviewed head `47b83fb894408503f4ab0873a03617f71a4bae9a` and the prepared diff. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff review | passed | Two libc source files | | Tests | not run | Author reports platform runs | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No tests were run independently. I read `core/libs/prx/libc/src/BoundsChecking.cpp`, `core/libs/prx/libc/src/Process.cpp`, and `core/libs/prx/libc/include/general/VabiMacros.hpp`. The manifest lists two changed files and both full texts were available and read; no changed files were excluded. The description's reported build and test results were not independently verified. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 16:56:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T16:56:10Z.

Review: COMMENTED


Both changed translation units passed the MinGW UCRT syntax check. The guest calling-convention annotation now agrees between the abort_nid_postfix definition and the declaration in BoundsChecking.cpp. I checked the declarations and compilation, with runtime abort and stack-check handling still unverified on Windows.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6174409119 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17900#pullrequestreview-6174409119). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T16:56:10Z. **Review:** COMMENTED --- Both changed translation units passed the MinGW UCRT syntax check. The guest calling-convention annotation now agrees between the `abort_nid_postfix` definition and the declaration in `BoundsChecking.cpp`. I checked the declarations and compilation, with runtime abort and stack-check handling still unverified on Windows. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/17900:upstream-pr/17900'
git switch 'upstream-pr/17900'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/17900'
git switch 'upstream-pr/17900'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/17900'
git switch 'upstream-pr/17900'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/17900'
git switch 'main'
git merge --squash 'upstream-pr/17900'
git switch 'main'
git merge --ff-only 'upstream-pr/17900'
git switch 'main'
git merge 'upstream-pr/17900'
git push origin 'main'
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!17900
No description provided.