Skip to content

test(relinker): cover non-8-aligned target addresses in RELR unpacking - #14582

Open
slopgobblercobbler wants to merge 1 commit into
boykopovar:mainfrom
slopgobblercobbler:test/relinker-relr-misaligned-addr-bounds
Open

slopgobblercobbler wants to merge 1 commit into
boykopovar:mainfrom
slopgobblercobbler:test/relinker-relr-misaligned-addr-bounds

Conversation

@slopgobblercobbler

@slopgobblercobbler slopgobblercobbler commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

What

Add test coverage for even, non-8-aligned target addresses (0x204 and 0x206) as positive controls in the registered RelrRelocationTests fixture alongside existing 0x202 and 0x1ffc cases.

Per DT_RELR specification and existing AnyPS5 relinker behavior, an RELR address entry only requires bit 0 clear (even target), not an 8-byte multiple; bitmap entries subsequently step in 8-byte increments. Reverts the rejected production throw from RelrRelocations.cpp, removes the unregistered RelrMisalignedAddr.cpp, and folds the positive controls directly into the registered RelrRelocationTests.cpp suite.

Tested

  • Built and ran relr_relocations_tests with CTest (ctest --test-dir build -C Release -R relr_relocations -V), passing all assertions.
  • Verified python tools/check_conventions.py --base upstream/main --head HEAD passes with 0 findings.

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
  • AI-assisted: yes

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks for looking at RELR address entries. As written, though, the change breaks the existing registered RELR test and its own test never runs:

  1. The new check at core/relinker/relinker/src/parsing/RelrRelocations.cpp:80 throws Misaligned RELR target address for any address entry that is not a multiple of 8. The registered core/relinker/relinker/tests/RelrRelocationTests.cpp explicitly accepts the even, non-8-aligned targets 0x202 (lines 79-80) and 0x1ffc (lines 83-85), so relr_relocations would now fail. An address entry only needs bit 0 clear to be an address; the 8-byte step applies to the bitmap entries (cursor += 63 * 8), not to the address entry itself, and the PR gives no source for the stricter rule. Please remove the check and keep those cases as positive controls; the existing load-segment and overlap checks already constrain the targets. If you have a specification text or producer/loader code that requires 8-byte-aligned address entries, please cite it and update the existing test in the same PR, saying that previously accepted input is now rejected.

  2. core/relinker/tests/RelrMisalignedAddr.cpp is not registered: core/relinker/CMakeLists.txt has no add_test_executable/add_test for it, and core/relinker/tests/ does not exist on main, so it never runs and the "Compiled and executed" in the PR text cannot come from the build. The registered RELR test (line 279 of that CMake file) already has the same Fixture and Reject helpers; please put any cases that remain there and delete the new file.

Reviewed at 7b90505ddd.

@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.

Changes requested — the new RELR check breaks three existing relinker tests, and the new test is not registered

The new check (RelrRelocations.cpp, "Misaligned RELR target address") rejects inputs that the existing RELR tests expect to convert. In the hosted Ubuntu g++ relinker job, relr_relocations, relr_conversion and guest_relr_conversion fail with that message. The Python fixture test_relr_relocations.py reports zero-fill-addends (target 0xffc) and partial-overlap failing with "Misaligned RELR target address". The macOS and Windows g++ relinker jobs also failed; I read only the Ubuntu log. In addition, the new test file core/relinker/tests/RelrMisalignedAddr.cpp is not referenced by any CMake file, so it never runs.

What I ran

  • Head 7b90505ddd82cea528e5ecfc984e6aa203a58738; base f2d874c1fdccf781c0fa5d86619bb5dd8894b958. 3 files: core/relinker/relinker/src/parsing/RelrRelocations.cpp (+1, the new check) and the new core/relinker/tests/RelrMisalignedAddr.cpp (+67).
  • Searched every CMake file at the head for RelrMisalignedAddr: no match. relr_relocations_tests is at core/relinker/CMakeLists.txt line 279.
  • Read the hosted logs: the Ubuntu g++ job's CTest list (relr_relocations, relr_conversion, guest_relr_conversion Failed; exit code 8) and its Python output (test_relr_relocations.py, line 171 and 182).
  • Read-only checks from the trusted main checkout (precheck not run: this session does not run code from PR heads): diff check and conventions passed; the ABI audit is not applicable.
  • Hosted: relinker ubuntu g++, windows g++ and macOS (both) failed; relinker asan passed; the main windows job was skipped.
  • No MarcZX10 review at this head.

Results

Check Result Note
Diff check passed
Conventions and PR template passed conventions check from the main checkout
Mergeability and dependencies passed depends on none; the stack check passed
Existing relr_relocations, relr_conversion, guest_relr_conversion failed Ubuntu g++ job; exit code 8 (the new check rejects their inputs)
zero-fill-addends and partial-overlap fixtures failed "Misaligned RELR target address" in test_relr_relocations.py
New test RelrMisalignedAddr.cpp not run not registered in any CMake file
Relinker jobs (hosted) failed ubuntu g++, windows g++ and macOS (both) failed; asan passed
ABI audit not applicable no exported symbol changed
Build and runtime tests not run no local build
Negative controls not run no local build
Hosted CI failed relinker jobs failed (see above); the main windows job was skipped
Read-only check output

Precheck was not run: this session does not run code from PR heads. Hosted: gh api repos/boykopovar/AnyPS5/commits/7b90505ddd82cea528e5ecfc984e6aa203a58738/check-runs. Ubuntu CTest failures: 349 - relr_relocations (Failed), 391 - relr_conversion (Failed), 392 - guest_relr_conversion (Failed), exit code 8.

Negative control

Not run here. A negative control needs a build, and code from this head is not run here.

Findings

Blocking

  1. The new check breaks existing tests. In the Ubuntu g++ relinker job, relr_relocations, relr_conversion and guest_relr_conversion fail with "Misaligned RELR target address", and the Python fixtures zero-fill-addends (target 0xffc) and partial-overlap expect conversions instead. Please reconcile the check with those fixtures (either the fixtures are wrong, or the rule is too strict), and rerun the relinker jobs. The macOS and Windows g++ jobs also failed; their logs were not read.
  2. core/relinker/tests/RelrMisalignedAddr.cpp is not registered in any CMake file, so the new case never runs. Please register it, or move it into RelrRelocationTests.cpp, which already runs as relr_relocations_tests.

Non-blocking

  • The title ("test(relinker): cover misaligned target address in RELR unpacking") describes a test, but the diff adds a production rejection. Please state the behaviour change in the title and body.

Sources

Not verified

  • The macOS and Windows g++ relinker logs were not read.
  • The fixture expectations were not checked against the RELR specification beyond the failing messages.

To get this to a good state

  • Reconcile the check with the existing RELR fixtures, register or fold the new test, state the behaviour change, and rerun the relinker jobs.

@adriadam10 adriadam10 self-assigned this Nov 6, 2026

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • core/relinker/relinker/src/parsing/RelrRelocations.cpp:80: the new Misaligned RELR target address throw is a behaviour change, not test coverage. An RELR address entry only needs bit 0 clear; the existing RelrRelocationTests.cpp accepts 0x202 and 0x1ffc. It fails relr_relocations, relr_conversion and guest_relr_conversion in the relinker jobs on Linux, macOS and Windows.
  • core/relinker/tests/RelrMisalignedAddr.cpp is not registered in core/relinker/CMakeLists.txt (add_test_executable + add_test), so it never runs; the "executed successfully" line in Tested cannot be true for it. It also asserts rejection of 0x202, which contradicts the existing test.
  • Fix: drop the throw and this test, or, if you have a reference showing real RELR tables never carry non-8-aligned addresses, cite it, update the existing tests and register the new one so it fails without the change.

@gabichuuuuu

Copy link
Copy Markdown
Contributor

Windows check of head 7b90505ddd, merged onto main 31b4aa91e8 (clean merge, built together with other open PRs that touch different files).

Setup: Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0 (r7), Ninja, Release, -DANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON, Python 3.15.

  • tools/select_tests.py explain selected no test whose build inputs include this PR's files, so no test was run for it. This is not a pass or a failure.

AI-assisted: yes.

@adriadam10 adriadam10 removed their assignment Nov 17, 2026
@slopgobblercobbler
slopgobblercobbler force-pushed the test/relinker-relr-misaligned-addr-bounds branch from 7b90505 to cd7592b Compare November 18, 2026 20:27
@slopgobblercobbler slopgobblercobbler changed the title test(relinker): cover misaligned target address in RELR unpacking test(relinker): cover non-8-aligned target addresses in RELR unpacking Nov 18, 2026
@slopgobblercobbler

Copy link
Copy Markdown
Contributor Author

Thanks @oneandonlydean, @MarcZX10, and @adriadam10 for the reviews!

Updated head cd7592b275e cleanly rebased onto upstream/main:

  1. Reverted the stricter entry % 8 != 0 check in core/relinker/relinker/src/parsing/RelrRelocations.cpp so that it matches main. RELR address entries only require bit 0 clear (even target), not an 8-byte multiple.
  2. Deleted the unregistered core/relinker/tests/RelrMisalignedAddr.cpp.
  3. Added positive control assertions for even non-8-aligned addresses (0x204 and 0x206) directly to the registered core/relinker/relinker/tests/RelrRelocationTests.cpp test suite alongside existing 0x202 and 0x1ffc cases.
  4. Updated PR title to test(relinker): cover non-8-aligned target addresses in RELR unpacking and description accordingly.
  5. Verified python tools/check_conventions.py --base upstream/main passes with 0 errors.

Ready for re-review.

@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.

Reviewed — looks good

The test adds positive controls for even RELR target addresses that are not 8-byte aligned, and the assertions match the existing relinker behavior.

What I ran

Reviewed head cd7592b275e1da37938817955128a5b0893255b5 using the prepared diff and pinned reader. No test commands were run.

Results

Check Result Note
Changed test lines passed All four added lines read
Test execution not run No build or test run performed

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author reports convention checks and a passing test build; these were not run during this review. No files were excluded in the manifest. Read RelrRelocationTests.cpp in full and RelrRelocations.cpp for the behavior exercised; also read description.md, commits.md, manifest.json, diff.patch, and the review-folder README. files.json was not available through the reader.

To get this to a good state

Nothing is required.

@slopgobblercobbler

Copy link
Copy Markdown
Contributor Author

@oneandonlydean

The fix for PR #14582 has been force-pushed (commit cd7592b275e).

  • Rebase base: upstream/main.
  • Test status: Linux and Windows CI builds (relinker) passed successfully.

@slopgobblercobbler
slopgobblercobbler force-pushed the test/relinker-relr-misaligned-addr-bounds branch from cd7592b to 03bda9f Compare November 20, 2026 17:42
@slopgobblercobbler

Copy link
Copy Markdown
Contributor Author

@oneandonlydean @soupap08 @adriadam10 @MarcZX10

Branch rebased cleanly on latest upstream/main and squashed into a single conventional commit:

  • Retained the positive control assertions for even non-8-aligned addresses (0x204 and 0x206) directly in registered core/relinker/relinker/tests/RelrRelocationTests.cpp, matching existing 0x202 and 0x1ffc behavior.
  • Cleanly verified: 0 comments in code, and 0 findings from python tools/check_conventions.py --base upstream/main --head HEAD.
  • Built and ran relr_relocations_tests successfully via CTest (all tests passed).

@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head 03bda9f539, applied with git apply on main fd4aeed483 together with the other 29 PRs of one batch (#17478, #21223, #24030, #24201, #14202, #18889, #19531, #21641, #21773, #22468, #22471, #23239, #23255, #23484, #23869, #23992, #24311, #18425, #21195, #21255, #22989, #23507, #23886, #17878, #19666, #19899, #20138, #21656, #21746). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
(the test file this PR changes could not be matched to a ctest name by me) - -

Whole batch: the full ctest -j 12 (6522 tests) on the RTX 3080 has 4 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Intermittent in this run (pass when rerun alone, or known flaky): agc_driver_store_over_untracked. The 2125 agc_/video tests on the iGPU have 2 failing: agc_driver_stencil_plane_memory, agc_driver_store_over_untracked (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

@slopgobblercobbler
slopgobblercobbler force-pushed the test/relinker-relr-misaligned-addr-bounds branch from 03bda9f to fcc8b26 Compare November 21, 2026 12:07
@slopgobblercobbler

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto latest upstream/main (fcc8b260f18):

  • Verified python tools/check_conventions.py --base upstream/main --head HEAD passes cleanly with 0 findings.
  • Retains approved positive control assertions for even non-8-aligned addresses (0x204 and 0x206) directly in registered RelrRelocationTests.cpp.
  • PR is mergeable and ready for final merge.

@catminou4 catminou4 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.

Reviewed at fcc8b26, applied on main 7a1c9bb, relinker-only Release build (GCC, Ubuntu 22.04).

  • ctest -R '^relr_relocations$': passes. Full relinker ctest: no new failures (only tools_headers_manifest, environmental, also fails on main).
  • Checked the expected addends by hand: the fixture writes offset + 0x900 at every 8-byte slot, so the bytes from 0x204 are 00 00 00 00 08 0b 00 00 → 0x00000b0800000000, and from 0x206 00 00 08 0b 00 00 00 00 → 0x000000000b080000. Both match.
  • Test-only; no textual conflict with #14505, #14127 or #23861.

Mergeable.

@ligmaSec ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Built this head with ANYPS5_RELINKER_ONLY=ON and ran relr_relocations on Linux. It passed, including the added non-eight-aligned target case.

AI-assisted: yes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants