Skip to content

fix(tests): use position-independent unwind data in the C++ error fixture - #5300

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
David-cmrg:fix/tests-ampr-cpp-error-pie
Oct 14, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
David-cmrg:fix/tests-ampr-cpp-error-pie

Conversation

@David-cmrg

Copy link
Copy Markdown
Contributor

What

Fixes #5299.

On Linux, GuestAmprCppError.S now uses position-independent unwind data, so the PIE test executable needs no dynamic relocations in read-only sections:

  • the personality goes through a pointer in .data.rel.ro (.cfi_personality 0x9b);
  • the LSDA pointer is PC-relative (.cfi_lsda 0x1b);
  • the two type-table entries are PC-relative indirect .long entries (TType encoding 0x9b) instead of absolute .quad ones.

AnyPS5's unwinder and personality decode these encodings through Encoded in exceptions/Unwind.hpp. The Windows encodings are unchanged.

Tested

Fedora 44, GCC 16.2.1, GNU ld 2.46.1, Release, main 0214069e3:

  • On main, guest_ampr_cpp_error_tests fails to link with "read-only segment has dynamic relocations". With the change it links, without TEXTREL, and guest_ampr_cpp_error passes in 3 of 3 runs.
  • With -DANYPS5_ENABLE_ASAN=ON it also links and passes in 3 of 3 runs, with no AddressSanitizer report.
  • readelf --debug-dump=frames on the object shows augmentation zPLR with personality encoding 0x9b and LSDA encoding 0x1b.
  • With both type-table entries pointed at FixtureOtherType, the test aborts, so the personality does read the new entries.
  • Windows was not built; its encodings are unchanged.
  • python3 tools/check_conventions.py --base origin/main passes, and git diff --check is clean.

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
  • Unblocks: none
  • AI-assisted: yes (Claude Opus 5.5)

@MarcZX10

Copy link
Copy Markdown
Contributor

I independently validated the Linux path on the PR head: Ninja Release build of guest_ampr_cpp_error_tests with -Wl,-z,text succeeded, and ctest -R '^guest_ampr_cpp_error$' passed (1/1). readelf reports a PIE (DYN) with no TEXTREL dynamic tag. This confirms the updated fixture works under the strict no-text-relocation link check on my Linux toolchain; I did not test Fedora or Windows.

@MarcZX10

Copy link
Copy Markdown
Contributor

I checked the changed encodings against the fixture declarations: FixtureCatchType and FixtureOtherType are pointer variables, so the PC-relative indirect type-table entries point to storage containing the actual type-info address. The personality pointer has its writable relocation storage in .data.rel.ro, while the .eh_frame/LSDA references are relative. That matches the PR’s stated goal of removing dynamic relocations from read-only segments. The Linux/ASan link and runtime evidence in the description is also clearly scoped; Windows remains untested as stated.

AI-assisted: yes; reviewed by MarcZX100. I did not rerun this PR locally.

@gunerky

gunerky commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Additional, limited Windows compatibility evidence for PR head 5757a9fdc241e5dd6eaa708918b2476585124d67: Windows x64, WinLibs MinGW-w64 GCC 15.2.0, -O3 -DNDEBUG, with the existing -fno-asynchronous-unwind-tables fixture flag and .eh_frame to .ehfram post-link rename.

  • The Windows assembly objects from frozen main 18c438b1092b09cef54e4cfacab441c009a6b501 and this head are byte-identical (SHA-256 b3cee3aee48963c027bf35a14ae91530c77fc54fd3eaad0db43625598817ac22).
  • The exact head C++/assembly fixture was compiled and linked locally, then passed three runs: 0.094, 0.031 and 0.031 seconds. These execute the fixture's guest catches/type checks and out-of-range controls.

The runtime libraries were reused from my frozen local build at source revision 51d1ed859f9b443874353cf2a6c124506a6a9d10. This is isolated compatibility testing of the exact test source against those libraries, not a full PR/current-main Windows build.

Separately, the installed clang/LLD 19.1.5 cross-assembled the ELF fixture. With identical ld.lld -pie -z text -z relro arguments and a local symbol-only link oracle, main rejects absolute relocations in .rodata/.eh_frame, whereas head links with no TEXTREL; its dynamic relative relocation is in .data.rel.ro under GNU RELRO. Restoring an absolute LSDA pointer in a disposable mutant makes that strict link fail again. The ELF was not executed, so this does not add Linux exception-decoding or ASan runtime coverage to the existing Linux report.

Linux/ASan execution and full PR builds: not tested. AI-assisted: yes; local execution and result checking assisted by Codex.

@Dripl1x

Dripl1x commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Tested on Ubuntu and on Windows, which the description lists as not built. #5102 (mine) is what registered this fixture on Linux, so the absolute relocations reached Fedora through it; thanks for the fix.

The tree is main 8cf6a0bc3 with #5083's branch on top (it does not touch libSceAmpr or this test) and GuestAmprCppError.S replaced by the file at 5757a9fdc.

  • Ubuntu 26.04 under WSL, GCC 15.2.0, GNU ld 2.46, Release. With the fixture from main the executable carries 2 TEXTREL dynamic entries, and relinking it with -Wl,-z,text fails with read-only segment has dynamic relocations, as on Fedora. With this PR's fixture it has none, the same relink succeeds, and guest_ampr_cpp_error passes 3 of 3 runs.
  • Windows 11, WinLibs MinGW-w64 GCC 15.2.0 r7, Release: guest_ampr_cpp_error_tests builds and guest_ampr_cpp_error passes 3 of 3 runs.

Not checked: Fedora itself, the ASan build, the full test suite.

Ubuntu: relink of the main fixture with -z text
/usr/bin/x86_64-linux-gnu-ld.bfd: core/libs/prx/libSceAmpr/CMakeFiles/guest_ampr_cpp_error_tests.dir/__/__/tests/GuestAmprCppError.S.o: warning: relocation in read-only section `.eh_frame'
/usr/bin/x86_64-linux-gnu-ld.bfd: read-only segment has dynamic relocations
collect2: error: ld returned 1 exit status
Windows: ctest with this PR's fixture
Test project <build>
    Start 669: guest_ampr_cpp_error
    Test #669: guest_ampr_cpp_error .............   Passed    0.13 sec
    Start 669: guest_ampr_cpp_error
    Test #669: guest_ampr_cpp_error .............   Passed    0.05 sec
    Start 669: guest_ampr_cpp_error
1/1 Test #669: guest_ampr_cpp_error .............   Passed    0.05 sec

100% tests passed, 0 tests failed out of 1

Total Test time (real) =   0.49 sec

AI-assisted (Claude Code).

@LloydNicholson

Copy link
Copy Markdown

Tested on Nobara 44 (Fedora 44), GCC 16.2.1, GNU ld 2.46.1, Release, BUILD_TESTING=ON, ANYPS5_ENABLE_SPIRV_TOOLS=ON, with this PR's head 5757a9fdc merged onto main dacd78525:

Not tested: ASan, Windows.

AI-assisted (Claude Code).

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the additional Fedora/Ubuntu and Windows runs; they address the platform gap called out in the description. I verified the only changed file is the unwind fixture, which has not changed on current main, and the reported merge state is clean. This head is still 51 commits behind current main (bf8dc61), though, and the PR checks currently skip both full Linux and Windows jobs. Please rebase/update onto current main and rerun the relevant Linux test before merge; I can then complete the review.

@David-cmrg
David-cmrg force-pushed the fix/tests-ampr-cpp-error-pie branch from 5757a9f to 75c25e1 Compare October 13, 2026 23:59
@David-cmrg

Copy link
Copy Markdown
Contributor Author

Rebased onto main d1670009f. The new head is 75c25e16f, and git range-diff shows the commit unchanged, so the earlier runs on this PR still cover the same patch.

Rerun on the new base: Fedora 44, GCC 16.2.1, GNU ld 2.46.1, Release, BUILD_TESTING=ON, and the same configuration with -DANYPS5_ENABLE_ASAN=ON:

  • main d1670009f: guest_ampr_cpp_error_tests still fails to link in both builds with "read-only segment has dynamic relocations".
  • This head: it links without TEXTREL, and guest_ampr_cpp_error passes in 5 of 5 runs in the Release build and 3 of 3 in the ASan build.

@oneandonlydean
oneandonlydean merged commit 52686e7 into boykopovar:main Oct 14, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests: guest_ampr_cpp_error_tests doesn't link on Fedora ("read-only segment has dynamic relocations" from GuestAmprCppError.S)

6 participants