fix(relinker): reject nonzero GLOB_DAT and JUMP_SLOT addends in Linux output #10971
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10971"
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-25T11:39:43Z.
What
An
R_X86_64_GLOB_DAT(6) orR_X86_64_JUMP_SLOT(7) relocation with a nonzeror_addendpassed every check and reached the Linux output'sDT_RELA/DT_JMPRELunchanged.ValidateRelocationTypeSupportedaccepts both types,extractRelainRelinkerPipeline.cppchecks no addend for them (the pipeline's only addend check is the DTPMOD64 one inextractLocal, lines 581-582),SysVDynamicSectionBuilder.cpp:153and:163copyref.Addend, andLinuxElfPatcher.cpprebases onlyr_offset(RebasedRelocations, lines 66-97). Onfixture(linux=True)oftest_jmprel_table_bounds.pywith addend 0x10 or -8, the default,--linux-fixed-base 0x10000000and--lazy-bindingruns exited 0 and emitted(0x400300, 0x10000300 or 0x300; type 6 or 7; symbol 1; addend 16 or -8), while--windowsand--macosexit 2 withFAIL: GLOB_DAT/JUMP_SLOT relocation has a nonzero addend (offset 0x300)(WindowsRelocationBuilder.cpp:66-67, reached fromMacOsMachOPatcher.cpp:67) and guest modules fail on every target (GuestImageReader.cpp:267).main.RequireZeroImportSlotAddendsinLinuxElfPatcher.cppthrowsGLOB_DAT/JUMP_SLOT relocation has a nonzero addendwith the unrebasedr_offsetfor a type 6 or 7 entry ofRelaDataorRelaPltDatawhose addend is not 0, the message and offset the Windows and macOS outputs already print.Patchcalls it unconditionally, beforeRequireOnlyDependencies,TracedImportsand the fixed-base rebasing intable(). That covers the three Linux modes: the output's interpreter is the host's/lib64/ld-linux-x86-64.so.2(line 536); the default output isET_EXECat 0x400000 (Conversion.cpp:153) and--linux-fixed-basepicks another base, both withDF_BIND_NOW(lines 476-477);--lazy-bindingkeepsET_DYNwithout the flag and cannot be combined with a fixed base (lines 351-352,CliArgs.cpp:208-209). The x86-64 psABI computes both types as S. glibc before f8587a61892c ("x86-64: Ignore r_addend for R_X86_64_GLOB_DAT/R_X86_64_JUMP_SLOT", H.J. Lu, 2022-05-21, no bug referenced) wrote S+A for eager binding (glibc-2.35 dl-machine.h#L344-L346); lazy JUMP_SLOT has always written S (elf_machine_plt_value, glibc-2.35 dl-machine.h#L235-L239, called from elf/dl-runtime.c#L121). The commit first shipped in glibc 2.36 (dl-machine.h#L305-L307) and was backported to the 2.33, 2.34 and 2.35 stable branches in July 2022 (f9f0fbbf7bba on 2.35). Ubuntu 22.04's glibc 2.35-0ubuntu3.15 does not carry the backport and writes S+A (Launchpadubuntu/+source/glibc,ubuntu/jammy-updates:debian/patches/git-updates.diffstops at release/2.35 e30c1c73da3f of 2022-03-03, 114 commits before f9f0fbbf7bba, and no entry ofdebian/patches/seriescarries it); upstream release/2.31 and release/2.32 never got it, and Debian 11's 2.31-13+deb11u11 writes S+A as well (patched source,sysdeps/x86_64/dl-machine.h:357-359); Debian 12 and Ubuntu 24.04 write S. The same relinked file therefore resolved differently by host: GLOB_DAT by glibc patch level only, sinceDT_RELAis always bound eagerly, JUMP_SLOT also between the eager outputs and--lazy-binding. FreeBSD rtld is itself mixed: GLOB_DAT S, eager JMP_SLOT S+A, lazy S (freebsd-src dc1514eda55clibexec/rtld-elf/amd64/reloc.c:326-327and:474-475,rtld.c:1109). The console's result is unknown, so the Linux output now refuses the entry as the other outputs do, and a new entry indocs/dev/debt/relinker.mdrecords it.TracedImportsloses its|| Io::ReadU64(table, entry + 16) != 0: its only caller (line 359) runs after the new check on the samedynSection, and the disjunct is evaluated only for types 6 and 7, whose addend is then 0. Zero-addend entries andR_X86_64_64import addends (S+A) are unchanged. GNU ld 2.42-z mark-pltand lld since 7f8640b7bdab write the PLT entry address into the JUMP_SLOT addend (bfd/elf64-x86-64.c:4618-4619in binutils 2.42). No title executable was scanned for such entries; all existing tests and fixtures use addend 0.test_jmprel_table_bounds.py:fixture()gains an optionaladdendkeyword (default 0) andrun()maps the targetsmacos,lazyandfixed(--linux-fixed-base 0x10000000); existing callers are unchanged. For the default Linux, fixed-base,--lazy-binding,--windowsand--macostargets and both the GLOB_DAT (data_relocations=True) and JUMP_SLOT fixtures, addends 0x10 and -8 must exit 2 with the message,(offset 0x300)and no output file, and addend 0 must convert. On untouched code the test fails withAssertionError: ('linux-jump-slot-addend-10', 0, 'Converting linux-jump-slot-addend-10.elf ...'); a run of the whole matrix there showed all 12 nonzero Linux cases at exit 0 with the addend emitted and the 8 nonzero Windows and macOS cases already at exit 2.pr_overlap.pyreports no shared lines with open pull requests that merge withmain; #10402, #10564 and #10607 also changeLinuxElfPatcher.cppand merge cleanly with this branch, and a trial merge with #10402 built and passedjmprel_table_bounds,linux_load_boundsandentry_point_bounds. It cannot compare this branch with #5021, #8076, #9408 and #10647 (docs/dev/debt/relinker.md), because those do not merge withmain. Checked by hand: they insert next to the guest import registry, syscall scan and--trace-importsentries or rewrite the--trace-importsentry, while this PR inserts after theUnscoped imports on Linuxentry, a place where #7173, #10518, #10861, #10871 and #10947, which edit other lines of the file, also merge cleanly. #11041 adds a-none-in-pltrun at the end of the inner loop oftest_jmprel_table_bounds.pythat this PR follows with its addend loop; git reports a conflict because the hunks touch, and the resolution keeps both, #11041's run inside the existing loop and this PR's loop after it.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.16ff208dc3(#10646 merged). Counter-check:jmprel_table_boundswithLinuxElfPatcher.cppreverted to16ff208dc3fails at the first new case,linux-jump-slot-addend-10(exit 0, output written,AssertionErroratrun()); with the change it passes in 1.2 s and all 30 matrix runs give exit 2 with(offset 0x300)for every nonzero addend and exit 0 for addend 0.16ff208dc3plus this change (ctest -Rover the names below):jmprel_table_bounds(1.2 s),copy_relocations(0.4 s),entry_point_bounds(0.2 s),game_patches(1.7 s),gnu_hash_analysis(0.9 s),init_array_roots(5.5 s),null_symbol_relocations(1.1 s),linux_trace_imports(0.4 s),windows_trace_imports(2.1 s),linux_fixed_base(0.6 s),linux_named_imports(0.4 s),weak_imports(1.1 s),windows_guest_weak_imports(0.6 s),macos_guest_weak_imports(0.5 s),linux_executable_exports(0.1 s),executable_export_bounds(3.3 s),linux_load_pages,linux_dynamic_strings,amd64_only_converterandentry_stub(each under 0.4 s);amd64_only_converter, which likelinux_load_pagescompilesLinuxElfPatcher.cpp, passed as well.amd64_only_windowspassed in the full suite.ctest --test-dir build-relinker -j 6on16ff208dc3: 262 tests, 259 passed,long_pathsskipped; failures known on this machine onmainas well:select_tests(Windows symlink fixture) andpatch_advisor_unit(repository path with spaces, fixed by #10667); no timeouts.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-25T11:50:07Z.
Review: APPROVED
Reviewed the relocation-table validation, offset/addend handling, trace-import enumeration, and the new fixtures across Linux, fixed-base, lazy, Windows, and macOS output modes. The rejection is limited to nonzero addends on GLOB_DAT/JUMP_SLOT entries; zero-addend entries and other relocation types remain on their existing paths. Ubuntu, both macOS relinker jobs, Windows, ASan, conventions, eligibility, intake, and labels all passed.