fix(relinker): reject R_X86_64_COPY relocations #10658
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10658"
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 roboterspinne on 2026-10-24T15:31:07Z.
What
ValidationPolicyacceptedR_X86_64_COPY(type 5) and the Linux outputs kept it:SysVDynamicSectionBuilderwrites every import symbol withst_size0 and copies the relocation type into the outputRELA, so glibc'self_machine_relarunsmemcpy(reloc_addr, value, MIN(sym->st_size, refsym->st_size))with a reference size of 0 (sysdeps/x86_64/dl-machine.h, caseR_X86_64_COPY), copies nothing and at most warns about the size difference; the variable stays zero. Windows and macOS already rejected the type in the relocation builder (Unsupported Windows relocation type 5,WindowsRelocationBuilder.cpp), the default and--lazy-bindingLinux outputs relinked with exit 0.extractRelathrowsUnsupported relocation type 0x5for every output before any target code runs, and thecase R_X86_64_COPYin the fixed-base rebasing ofLinuxElfPatcher.cpp, which validation makes unreachable, is gone. The relinker cannot emit the definition's size, which only the library knows, so rejecting is the fail-fast answer. No title is known to useCOPY: PS5 executables are position independent and reach shared data through the GOT, whileCOPYrelocations arise in non-PIC executables that reference a shared library's data directly.test_copy_relocations.pyon the fixture oftest_jmprel_table_bounds.py: aCOPYinDT_RELAand one in the PLT table are rejected on the default and--lazy-bindingLinux, Windows and macOS outputs with the identicalFAILline, and theGLOB_DATandJUMP_SLOTcontrols stay accepted. The test asserts the type part of the message only, so it holds with #10390, which drops the offset the CLI already prints.COPYrelocations from the symbol size and had threecopy-*cases; its commit9bf8860f87drops that width and those cases, soCOPYtakes the 8-byte default there until this PR rejects it in validation. The merged state rejectsCOPYconsistently in either merge order, the two branches share no lines, and neither depends on the other.pr_overlap.pycannot compare this branch with #5021 and #7173 (core/relinker/CMakeLists.txt), because those do not merge withmain, and reports no other shared lines. Checked by hand: theirCMakeLists.txthunks start at lines 52 to 390 and 505, this PR adds two lines after 766. The test is registered afterjmprel_table_bounds, whose fixture it uses, rather than afterlinux_fixed_base, where #7532 inserts its own test.Tested
Windows 11, GCC 15.2.0 (WinLibs UCRT), relinker-only Release build (
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON); synthetic fixtures only, no title or homebrew, relinked outputs not run.ctest --test-dir build-relinker -j 6: 242 tests, 240 passed,long_pathsskipped;select_testsfails on this machine onmainas well (FileExistsErrorintools/tests/test_select_tests.py, a Windows symlink problem unrelated to this change).copy_relocationsagainst amainbuild (d098eca3d6): theCOPYinDT_RELArelinks with exit 0 and an output file on the default and--lazy-bindingLinux outputs and fails on Windows and macOS withUnsupported Windows relocation type 5; theCOPYin the PLT table already failed on every output withUnsupported PLT relocation type; both controls pass. With this change all 16 runs behave as asserted, in 0.8 s.COPYrelocation read 0; withst_size8 on the import symbol the value was copied.python tools/check_conventions.py --base upstream/mainwith this title and description passed.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T15:39:24Z.
Review: CHANGES_REQUESTED
The implementation and regression coverage look sound: removing
R_X86_64_COPYfromValidationPolicymakes validation fail before either output is emitted, and removing the now-unreachable Linux fixed-base case keeps behavior consistent. The test exercises COPY in both DT_RELA and JMPREL across all output targets, with GLOB_DAT/JUMP_SLOT controls.git diff --checkand the merge-tree check pass. Hosted conventions, eligibility, intake, labels, all four relinker platform jobs, and ASan pass; product jobs are skipped by policy. I did not independently run the tests locally.Please coordinate the behavior with open #10402 before merging. That PR explicitly derives a width for and accepts COPY relocations; this PR rejects them because emitted import symbols have size zero and the dynamic loader would copy no data. The body recognizes that one branch must adapt, but the checklist still says
Depends on: noneand does not record an agreed order or which branch will be changed. Please agree on the integration order with #10402’s author and record the dependency/plan so the final merged state rejects or correctly supports COPY consistently, including updating #10402’s acceptance tests if rejection is the chosen behavior.Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T15:43:22Z.
Review: APPROVED
Checked against main
c9b75825f3and the relinker sources (RelinkerPipeline.cpp, ValidationPolicy.cpp, LinuxElfPatcher.cpp, WindowsRelocationBuilder.cpp, MacOsMachOPatcher.cpp, GuestImageReader.cpp):extractRelavalidates the type (RelinkerPipeline.cpp:349) for both DT_RELA and DT_JMPREL before the PLT check and before any target writer. With type 5 gone from the set, every output, including--lazy-binding, stops with the sameUnsupported relocation type 0x5, which is what the new test asserts.case R_X86_64_COPYfromRebasedRelocationslooks safe: those tables only carry validated types, and the default branch would still throw.da511cb29clanded next to the LinuxElfPatcher hunk. Looks good to me.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T16:06:32Z.
Review: APPROVED
Re-reviewed exact head
7f58c7a407aed7cb626f90f3212bc392f141f7d7. The earlier integration concern with #10402 is addressed: that PR now removes its COPY support cases, and its current body records that #10658 rejects COPY after validation; the other reviewer also verified the behavior/order. I built the relinker-only Release target with GCC 12.2.0 and ranctest -R copy_relocations(1/1 passed), rantools/check_conventions.py --base upstream/main(pass), and confirmedgit diff --checkplus a clean merge tree with currentupstream/main. Hosted Linux/Windows/macOS relinker matrices and ASan are green; product jobs were skipped by policy. I did not run the full relinker suite.