fix(relinker): reject a Linux entry stub whose call cannot reach the entry #2097
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2097"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by treuenten on 2026-10-09T08:27:38Z.
What
EntryStubBuilder::BuildEntryStubencodes the Linux entry stub'scallwithstatic_cast<std::int32_t>(realEntryVaddr - callNextVaddr)and no range check. The stub sits just above the highest PT_LOAD end, so when an input has a PT_LOAD at or above 2 GiB the displacement silently truncates. With an extra bss PT_LOAD at0x80000000ande_entry = 0x10, main exits 0 and writes a binary whose entry stub calls0x100000010, which is unmapped, so it crashes at startup.The builder now computes the displacement as unsigned, converts it to
int64_t, and throwsRelinkerException("Entry stub call exceeds rel32 range")when it does not fit in rel32. Doing the subtraction unsigned first keeps layouts that wrap past 2^64 working, because RIP-relative math is modular. The other rel32 encodings in the Linux path (LinuxElfPatcher::_appendTrampolineand the guest initializer call inLinuxGuestModuleWriter) already check their range.test_linux_entry_argv.py(ctestlinux_entry_argv) relinks the argv fixture with a sixth PT_LOAD:0x7FF00000it must exit 0, and the decoded stubcallmust land on the entry;0x80000000it must exit 2 with the new message and write no output.The test finds the stub's
callby its opcode instead of reading it at a fixed offset, so it works with both the current stub and #2339's. The far-load case adds one program header slot to the sharedfixture()instead of setting a fixed count, so it also holds when the synthetic header count changes.EntryStubBuilder.cppnow includes<domain/Types.hpp>forRelinkerException, as the other elfpatcher sources do. Theentry_stub_teststarget from #2339 compiles that file, socore/relinker/CMakeLists.txtadds${CMAKE_CURRENT_SOURCE_DIR}/domain/includeto it. Without that line, the target fails with'domain/Types.hpp' file not found.#2339 (now on
main) put a frame record before the stub'scall, which moved it from entry + 10 to entry + 17. The test finds thecallwherever it is.One open pull request interacts with this one:
fixture()intest_linux_load_alignment.py. The far-load case sizes its header table fromfixture(), so it passes with or without #2274.No other open pull request touches these files.
Tested
macOS arm64 (Apple M3), AppleClang, relinker-only Release build on
mainb667d1e3, which includes #2339:ctest52/52, includingentry_stubandlinux_entry_argvwith thecallat entry + 17.CMakeLists.txtline,entry_stub_testsfails to compile ('domain/Types.hpp' file not found).0x100000010) and passes with the fix.ctest44/44. The previous far-load fixture fails there (Not enough program header slots: need 7, available 6). #2274 now conflicts withmainintest_linux_eh_frame_header.py, a file this PR doesn't touch. With it merged on top of this branch,entry_stubandlinux_entry_argvstill pass.EntryStubBuilder.cpp,linux_entry_argvfails: the0x80000000case exits 0.python3 tools/check_conventions.py --base origin/mainpasses.Full CI on my fork, using this repository's
build.ymlunchanged:mainb667d1e3. Every job passes: the Linux full build (ctest 598/598, including the lavapipe Vulkan tests), the Windows full build (MinGW, 606/606), and the relinker-only build on Linux (59/59), Windows (55/55) and macOS (52/52).entry_stubandlinux_entry_argvpass in all five.mainb993145d. The relinker-only build passes on Linux (52/52), Windows (47/47) and macOS (45/45), includinglinux_entry_argv, which on Linux also runs the relinked binary. The full Linux and Windows jobs stop atcheck_test_registration.py(agc_driver_recorder_tests is run by ctest now; remove it from KNOWN_UNRUN), exactly as they do onmainb993145dalone (run 38011548052).main1f0c9fef. The relinker-only build passes (50/50, 46/46, 44/44). Linux full build: ctest 567/568, andlinux_entry_argvpasses. Windows full build: 557/559.guest_video_out_resolution_statusfails in both, as it does onmain1f0c9fefin this repository's own CI; #2514 has since fixed it. Windows also failedguest_video_out_wqhd_detection_no_vulkanwith a heap corruption. That test links only libSceVideoOut, libSceAgcDriver, libkernel and libc, so none of the relinker.Negesin ran the relinker-only build on Windows with the previous head c04fb011 (36/36).
Not run: sanitizer build, any title.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Negesin on 2026-10-09T08:58:48Z.
Tested the current PR head on Windows 11 with WinLibs MinGW-w64 GCC 15.2.0.
Commit tested:
c04fb011ANYPS5_RELINKER_ONLY=ONandBUILD_TESTING=ONctest -R "^linux_entry_argv$" --output-on-failure: 1/1 passedI did not test a full AnyPS5 build or any title/game execution.
Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-09T15:51:42Z.
Heads-up: #2339 changes the same Linux entry stub (it pushes a zero frame record and sets
rbpbefore the call), so thecallmoves fromentry + 10toentry + 17.entry_call_targetin this PR's test reads it at+ 10; whichever of the two lands second needs that offset updated. The range check here and that change don't otherwise interact.Written by Claude (AI assistant) on a contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by treuenten on 2026-10-10T01:34:08Z.
@johnmaia thanks for the heads-up, you're right: the test read the
callat a fixedentry + 10.entry_call_targetnow finds thecallby its opcode instead, so the test works with both the current stub and yours. With this PR merged with #2339,linux_entry_argvpasses with the call atentry + 17, and the old version of the test fails there, so the test no longer needs changing whichever lands first.There's one more interaction, in the build. This PR makes
EntryStubBuilder.cppinclude<domain/Types.hpp>(forRelinkerException, as the other elfpatcher sources do). #2339's newentry_stub_teststarget only addselfpatcher/include, so with both merged that target fails to compile because it can't finddomain/Types.hpp. Adding${CMAKE_CURRENT_SOURCE_DIR}/domain/includeto its include directories, aswindows_icon_resource_testsdoes, fixes it. With that line the merged tree passes 45/45. The line does nothing on currentmain, so adding it to #2339 now covers both orders. If #2339 lands first without it, I'll add it here.While checking, I also found that #2274 would break this test's far-load case (it adds a synthetic program header), so that case now sizes its header table from the shared fixture. I've rebased onto
maina291ae0fand squashed it into 607fde62. Fork CI: the relinker-only build passes on Linux, Windows and macOS (run 38011567988). The full builds fail only wheremainitself currently fails; the description has the details.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T05:17:47Z.
#2339 is on main now, and its
entry_stub_teststarget buildsEntryStubBuilder.cppwithoutdomain/include, so with this PR merged<domain/Types.hpp>isn't found. Please rebase and add${CMAKE_CURRENT_SOURCE_DIR}/domain/includetotarget_include_directories(entry_stub_tests ...)incore/relinker/CMakeLists.txt:303, as you suggested on #2339.Imported from boykopovar/AnyPS5. Originally posted by treuenten on 2026-10-10T05:38:00Z.
@oneandonlydean done: rebased onto
mainb667d1e3, and${CMAKE_CURRENT_SOURCE_DIR}/domain/includeis now intarget_include_directories(entry_stub_tests ...), squashed intoded18e50. Without that lineentry_stub_testsfails with'domain/Types.hpp' file not found. With it, the relinker-only ctest passes 52/52 here, includingentry_stubandlinux_entry_argv.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:49:32Z.
Checked the rebase on current
main:domain/includeis now inentry_stub_tests(core/relinker/CMakeLists.txt:322), as Dean asked. Relinker build and ctest pass (55/55, includingentry_stubandlinux_entry_argv), relinker CI is green on the head. Merging.