Skip to content

fix(relinker): keep syscall blocks outside embedded data masks - #11565

Merged
oneandonlydean merged 5 commits into
boykopovar:mainfrom
Mherberts:codex/fix-embedded-data-syscall-boundary
Nov 15, 2026
Merged

oneandonlydean merged 5 commits into
boykopovar:mainfrom
Mherberts:codex/fix-embedded-data-syscall-boundary

Conversation

@Mherberts

@Mherberts Mherberts commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What

A LEA-referenced data table followed by a syscall block, padding and another code block could be masked through the later padding boundary, hiding the earlier syscall from executable and bundled-module validation. Keep the padding-derived upper bound, then shorten it to an earlier syscall-containing block recognized by the existing gap analysis.

Updated with main c3a5290c7d, retaining the corrected fixture byte (0x55, not the REX prefix 0x44) requested in the reviews. This also incorporates main's wrapped-declaration class split and #15526's split of guest_none_relocations into plain/SCE runs. The latter addresses the 20 s timeout seen twice on the preceding macOS x86-64 checks without raising the timeout or reducing coverage. The syscall-boundary change and its regression fixtures remain unchanged by this integration.

Tested

Head 827267128c, Windows x64, MinGW GCC 13.2.0, Python 3.13.15, Ninja Release, ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON.

  • Complete relinker-only build passed. All 21 focused CTests passed in 21.33 s: control_flow_graph, both embedded-syscall conversion tests, both plain/SCE guest-relocation groups and all 16 wrapped-declaration/ABI-alias cases. The two guest-relocation groups took 2.72 s and 3.06 s on this Windows host.
  • Earlier hosted validation of the same syscall change and corrected fixture passed Windows (686/686), Linux, macOS arm64 and Linux ASan. The macOS x86-64 retry on 42432069c7 completed 670/671 tests; guest_none_relocations alone timed out. The current integration includes the upstream fix for that test (test(relinker): run guest_none_relocations as two halves #15526).
  • This integration build executed the focused conversion tests locally, including the syscall fixtures that Windows Application Control blocked on the previous build. No Windows security setting was changed.
  • Conventions against upstream/main and git diff --check upstream/main...HEAD passed. The required comparison with the fork's outdated origin/main also ran and reports six unrelated upstream commit-subject errors and existing debt-length warnings.

Current-head CI audit on 2026-11-05: Build run 41923925977 passed all four relinker configurations (Linux, Windows, macOS arm64 and macOS x86-64) and relinker ASan on 827267128c5b2b7ab9d104b6aef133b1028d1c82. Conventions and labels also passed. Full product jobs were skipped by workflow policy. The fixture already uses 0x55, and the requested main integration is included. No retail title or GPU testing.

Current overlap audit, 2026-11-05: manually inspected newly listed base-conflicting #6149 (module-args test source), #13486 (zero-finalizer test/stub-window safety) and #15245 (executable-export test registration). Their CMake edits do not implement or modify this syscall-mask boundary fix. No source update was needed for those notices.

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

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 6149 core/relinker/CMakeLists.txt
PR 7531 core/relinker/CMakeLists.txt
PR 10861 core/relinker/CMakeLists.txt
core/relinker/relinker/tests/ControlFlowGraphTests.cpp
PR 11628 core/relinker/CMakeLists.txt
PR 11661 core/relinker/CMakeLists.txt
PR 11689 core/relinker/CMakeLists.txt
PR 11698 core/relinker/CMakeLists.txt
PR 13486 core/relinker/CMakeLists.txt
PR 13716 core/relinker/CMakeLists.txt
PR 15245 core/relinker/CMakeLists.txt
PR 15642 core/relinker/CMakeLists.txt
PR 15896 core/relinker/CMakeLists.txt
PR 15903 core/relinker/relinker/src/analysis/RelativeJumpTables.cpp
core/relinker/relinker/tests/ControlFlowGraphTests.cpp
PR 17451 core/relinker/CMakeLists.txt
PR 17473 core/relinker/CMakeLists.txt
PR 17557 core/relinker/CMakeLists.txt
PR 17558 core/relinker/CMakeLists.txt

@oneandonlydean oneandonlydean self-assigned this Oct 26, 2026

@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 exact head 6ceab4098a3f2ee85987d10accdea78d19026278; no actionable findings. FindEmbeddedDataTableEnd now preserves the padding-derived upper bound and checks earlier trailing-code blocks for a syscall before returning it. The native cases cover syscall instruction forms, prefixes, padding bytes and optional leading padding; the conversion fixtures exercise both executable and guest-module paths across Linux, Windows and macOS outputs, with non-syscall controls. The author reports the focused native/Python tests and complete relinker-only build passed; hosted eligibility, conventions, intake, labels, all relinker platforms and ASan pass. I did not rerun the tests locally.

@JJenkx

JJenkx commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Windows run of this head (6ceab4098a), Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, BUILD_TESTING=ON. Edited: an earlier version of this comment called the Python-test failure Windows-specific; it isn't. It comes from merging with current main.

  • control_flow_graph: merged onto main 3a2b919816, it passes 3 of 3. With core/relinker/relinker/src/analysis/RelativeJumpTables.cpp put back to main's version (the build succeeds), it fails, so the C++ test catches the change.
  • embedded_data_syscalls and guest_embedded_data_syscalls:
    • On this PR's own head (relinker-only build), both pass, as in this PR's relinker (windows-latest) check.
    • Merged onto current main 3a2b919816, both fail. The first failing case is sce-syscall-00-linux: the relinker converts the input and exits 0, where the test expects exit 2 with the forbidden-syscall error and no output file.
  • Bisect: over main's first-parent commits since this PR's base fc7e583e6e, the first main commit with which this PR's Python tests fail is 09919b040d, the merge of fix(relinker): honor prefixes in the syscall number byte walk #10537 (nedra23, syscall-number REX prefixes). With main just before it (4c6fcfcb5c) they pass. Both PRs change how syscall instructions are scanned, so a rebase onto current main will likely need this PR's check updated for fix(relinker): honor prefixes in the syscall number byte walk #10537's change.

AI-assisted: yes (Claude Code).

@Nciibi

Nciibi commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Independent Windows verification of the same FindEmbeddedDataTableEnd boundary:

  • Windows 10 x64 22H2 (10.0.19045), WinLibs GCC 16.2.0, Ninja Release relinker-only build (ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON).
  • A local patch using the same candidate-then-shorten approach makes control_flow_graph, sce_code_extent and sce_module_code_extent pass 3/3.
  • Negative control, with only RelativeJumpTables.cpp reverted to main and the new regression tests kept:
    • control_flow_graph: Mask covered a syscall stub before table padding
    • sce_code_extent: sce-gap-syscall-before-padding-windows exits 0 instead of 2, with no Forbidden syscall instruction
    • sce_module_code_extent: sce-module-gap-syscall-before-padding-linux exits 0 instead of 2, with no Forbidden syscall instruction

The executable and module cases were added to the existing SCE fixture scripts, so this is independent coverage of the same bug. I am not opening a duplicate PR.

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

Follow-up on the main merge failure that JJenkx bisected to #10537. Checked on Linux x86-64 (Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON): head 6ceab4098a3f, merged onto main 4570612f40.

  • Same result: both embedded_data_syscalls tests fail 3/3 on the merge and pass 3/3 on the head alone.
  • My own first-parent bisect also lands on 09919b040d (#10537).

The cause is the test fixture, not the RelativeJumpTables.cpp change. tail() writes 0f 78 11 22 33 44 immediately before the routine 31 c0 b0 3b 0f 05.

  • Since #10537, ActivePrefixesBefore treats that trailing 0x44 as a REX.R prefix of the 31 c0. That is how a CPU decodes it: 44 31 c0 is xor eax, r8d, which does not zero eax.
  • ConstantRaxSetEndingAt therefore no longer derives syscall number 59 from xor eax,eax; mov al,0x3b.
  • Outside the unwind functions, a syscall without a number is now skipped (Skipped 1 syscall byte pattern(s) without a syscall number ...) instead of failing with Forbidden syscall instruction.

One-byte fix, verified on the merge:

--- a/core/relinker/relinker/tests/test_embedded_data_syscalls.py
+++ b/core/relinker/relinker/tests/test_embedded_data_syscalls.py
@@ def tail(opcode, padding):
-    return b"\x0f\x78\x11\x22\x33\x44" + routine + padding * 4 + b"\x31\xc0\xc3"
+    return b"\x0f\x78\x11\x22\x33\x55" + routine + padding * 4 + b"\x31\xc0\xc3"
  • With the fix on the merge: both tests pass 3/3, and the full relinker-only suite passes 535/535.
  • Negative control: with the same fixed fixture, but RelativeJumpTables.cpp reverted to main's version, both tests still fail (sysv-syscall-00-linux and syscall-00-linux exit 0). The test still catches the masking bug after the change.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@Mherberts this needs a merge of main plus a one-byte change to the test fixture before it can land. On current main, embedded_data_syscalls and guest_embedded_data_syscalls fail (JJenkx and jotitadev both bisected it to #10537): the 0x44 at the end of the 0f 78 11 22 33 44 prefix in tail() is now read as a REX prefix of the following 31 c0, so the fixture's syscall number is no longer derived. jotitadev's fix above, 0x44 -> 0x55, makes both pass on the merge and keeps the negative control failing on main's RelativeJumpTables.cpp. Could you merge main, apply it and push? The relinker change itself looks good to us.

@TechLevelZero

Copy link
Copy Markdown
Contributor

✅ AMD GPU test: passed

PR head 8272671 merged onto main 4639eff · tested 2026-11-05 08:45 UTC · 23 min

GPU AMD Radeon RX 6300 (RADV NAVI24), driver Mesa 25.2.8-0ubuntu0.24.04.4, Vulkan 1.4.318
Host Ubuntu 26.04.1 LTS, kernel 7.0.0-42-generic, container ubuntu:24.04
Logs build and test logs for this run
Build ✅ passed (Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON)
Tests ✅ 1,076 passed · 3 failed (0 new, 3 also fail on main) · 8 skipped (ANYPS5_REQUIRE_VULKAN=1)
Test setup CPU-only tests without a GPU; GPU tests (and any CPU-only test that failed or skipped without one) once on the GPU with VK_LAYER_KHRONOS_validation and ANYPS5_NO_SHADER_CACHE=1; main ran the same way
Test selection 1,087 of 3,962 tests run: the ones this change can reach, chosen by tools/select_tests.py from main's build graph
Vulkan validation ✅ no new validation IDs vs main (546 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) ⚠️ public_headers 45.6 s, ⚠️ agc_driver_image_sample_unnormalized 43.6 s, ⚠️ agc_driver_lazy_resolved_abi 36.0 s
Failing on main too (3, not counted against this PR)
agc_driver_image_table
agc_driver_native_depth_bda_clear
agc_driver_native_multisample_depth
Validation IDs already present on main (4 IDs in 426 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (426 tests): agc_driver_address_draw_space_reuse, agc_driver_address_passes, agc_driver_alias_copy_label, agc_driver_alpha_to_coverage, agc_driver_array_layer_target, agc_driver_bc_block_copy, agc_driver_bda_anchor_reads, agc_driver_bda_span_reads, and 418 more
VUID-vkCmdCopyImage-srcImage-01548 (4 tests): agc_driver_depth_clear_hle, agc_driver_depth_storage_dispatch, agc_driver_depth_surface_from_storage, agc_driver_dispatch_move_depth
VUID-vkCmdCopyImage-srcImage-01551 (4 tests): agc_driver_depth_clear_hle, agc_driver_depth_storage_dispatch, agc_driver_depth_surface_from_storage, agc_driver_dispatch_move_depth
VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (1 test): agc_driver_prepared_exports
Skipped (8)
agc_driver_copied_writer_label_order: skipped, the device reports a minStorageBufferOffsetAlignment of 4, so the dispatch binds its record at +0x1004 in place and nothing is written back; the test needs an alignment above 4
agc_driver_float16_unused_nan_payloads: skipped, the device has no native f16 conversions with RTE rounding and kept f16 denormals
agc_driver_gcn_display_present: skipped, no display: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
agc_driver_linear_target_direct_write_completion: skipped, the device does not keep host imports write-watched, so no completion stamp over the target is tracked
agc_driver_ngg_vertex_wave_reduction: skipped, s3 describes a 32-lane wave only on 32-lane subgroups, and the device has 64 lanes
agc_driver_recorded_draw_staging: skipped, the device does not keep host imports write-watched, so the target is never resident
agc_driver_scattered_runs: skipped, host imports are unavailable: /dev/udmabuf is not accessible
Reproduce
git fetch origin 827267128c5b2b7ab9d104b6aef133b1028d1c82 4639eff7f4c23325a916875a0e37f1e312fa18f4
git checkout 4639eff7f4c23325a916875a0e37f1e312fa18f4 && git merge --no-ff 827267128c5b2b7ab9d104b6aef133b1028d1c82
git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build && cmake --build build --target libs
VK_DRIVER_FILES=/nonexistent/icd.json ctest --test-dir build -E '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 12 --output-on-failure
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
  ctest --test-dir build -R '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 16 --output-on-failure
# failures are then re-run alone: --timeout 360 --parallel 2; new validation IDs: the test alone, twice, --parallel 1

Automated build and test on a contributor's AMD machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs.

@gabichuuuuu

Copy link
Copy Markdown
Contributor

Windows check of head 827267128c, 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.

  • Tests chosen with tools/select_tests.py explain from this PR's test files: control_flow_graph, embedded_data_syscalls, guest_embedded_data_syscalls.
  • All of them pass in 3 of 3 runs.
  • Negative control: with this PR's code reverted to main (files it adds removed) and rebuilt, control_flow_graph, embedded_data_syscalls, guest_embedded_data_syscalls fail in 2 of 2 runs, so the tests detect the change.

AI-assisted: yes.

@oneandonlydean
oneandonlydean merged commit cde0ecc into boykopovar:main Nov 15, 2026
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants