fix(relinker): reject link-time relocation types in executables #9220
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9220"
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-21T15:29:54Z.
What
ValidationPolicyaccepted the link-time relocation typesR_X86_64_GOT32(3),PLT32(4),GOTPCREL(9),32S(11),GOTPCRELX(41) andREX_GOTPCRELX(42) in an executable'sDT_RELA. The linker resolves these types, and glibc's ld.so does not apply them:elf_machine_relainsysdeps/x86_64/dl-machine.hhas no case for them and its default branch fails withunexpected reloc type. FreeBSD'srtld-elf/amd64/reloc.cand musl'sldso/dynlink.creject them as well. The--lazy-bindingLinux output copied them into its dynamic relocation table, so the relink succeeded and ld.so refused the program at load; the fixed-base output, the default since #8973, did the same for 32S. They are now rejected when the executable is validated, for every target, withUnsupported relocation type 0x.., asTPOFF32already is.--linux-fixed-baseall but 32S, and inDT_JMPRELthey already fail the PLT slot check. Windows and macOS now report the shared message instead ofUnsupported Windows relocation type.657ada06b); no commit, test or debt entry relies on these entries.PC32and32stay: glibc applies them and the fixed-base whitelist accepts them.--lazy-bindingand 32S.unsupported-typecase oftest_linux_fixed_base.pynow uses 32S, the one type--linux-fixed-baseaccepted, and expects the validation error. No relocation type reaches the fixed-base rejection from the command line any more; that rejection, itsR_X86_64_32Scase and the now unused constants stay, to keep this pull request to one topic.Tested
Ubuntu 24.04 x86_64, glibc 2.39, relinker-only Release build (
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON); synthetic fixtures only, no title or homebrew.ctest --test-dir build-relinker -j4: 238/238 passed.ValidationPolicy.cppchange, the newexecutable_tls_relocationscases fail (Linux and--lazy-bindingrelink with exit 0, Windows and macOS exit 2 with the oldUnsupported Windows relocation typemessage), andlinux_fixed_basefails because the 32S fixture relinks.mainbefore #8973 (cecb540a63), the default Linux output of the test fixture with one of these types against the null symbol relinks and then fails in ld.so witherror while loading shared libraries: unexpected reloc type 0x03(0x04,0x09,0x0b,0x29,0x2a), exit 127; type 11 does the same with--linux-fixed-base 0x400000. With this change each of them exits 2 at relink withUnsupported relocation type 0x..and leaves no output.main(4777caca3, includes #8973): no conflicts,ctest239/239 passed.python3 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 jotitadev on 2026-10-21T22:07:32Z.
Review: COMMENTED
Confirmed on macOS Apple Silicon, arm64 and x86-64 under Rosetta (your PR lists no run).
e839b2479on currentmaina6dcea9279(merged clean).-DCMAKE_OSX_ARCHITECTURES=x86_64 -DPython3_EXECUTABLE=/usr/bin/python3, Python 3.9.6) 229/229.Red/green on the new coverage: with
_initializeSupportedRelocationTypesreverted tomainso the link-time types stay accepted (tests kept),executable_tls_relocationsandlinux_fixed_basefail — the relink accepts e.g.R_X86_64_32S(0xb) into the dynamic relocation table instead of rejecting it. With the fix, GOT32/PLT32/GOTPCREL/32S/GOTPCRELX/REX_GOTPCRELX are rejected for every target withUnsupported relocation type 0x.., matching glibc/FreeBSD/musl ld.so, which never apply them.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.