fix(relinker): reject nonzero GLOB_DAT and JUMP_SLOT addends in Linux output #10971

Merged
roboterspinne merged 1 commit from upstream-pr/10971 into main 2026-10-26 21:58:17 +00:00
roboterspinne commented 2026-10-25 11:39:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-25T11:39:43Z.


What

An R_X86_64_GLOB_DAT (6) or R_X86_64_JUMP_SLOT (7) relocation with a nonzero r_addend passed every check and reached the Linux output's DT_RELA/DT_JMPREL unchanged. ValidateRelocationTypeSupported accepts both types, extractRela in RelinkerPipeline.cpp checks no addend for them (the pipeline's only addend check is the DTPMOD64 one in extractLocal, lines 581-582), SysVDynamicSectionBuilder.cpp:153 and :163 copy ref.Addend, and LinuxElfPatcher.cpp rebases only r_offset (RebasedRelocations, lines 66-97). On fixture(linux=True) of test_jmprel_table_bounds.py with addend 0x10 or -8, the default, --linux-fixed-base 0x10000000 and --lazy-binding runs exited 0 and emitted (0x400300, 0x10000300 or 0x300; type 6 or 7; symbol 1; addend 16 or -8), while --windows and --macos exit 2 with FAIL: GLOB_DAT/JUMP_SLOT relocation has a nonzero addend (offset 0x300) (WindowsRelocationBuilder.cpp:66-67, reached from MacOsMachOPatcher.cpp:67) and guest modules fail on every target (GuestImageReader.cpp:267).

  • Rule. Line numbers are those on main. RequireZeroImportSlotAddends in LinuxElfPatcher.cpp throws GLOB_DAT/JUMP_SLOT relocation has a nonzero addend with the unrebased r_offset for a type 6 or 7 entry of RelaData or RelaPltData whose addend is not 0, the message and offset the Windows and macOS outputs already print. Patch calls it unconditionally, before RequireOnlyDependencies, TracedImports and the fixed-base rebasing in table(). 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 is ET_EXEC at 0x400000 (Conversion.cpp:153) and --linux-fixed-base picks another base, both with DF_BIND_NOW (lines 476-477); --lazy-binding keeps ET_DYN without 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 (Launchpad ubuntu/+source/glibc, ubuntu/jammy-updates: debian/patches/git-updates.diff stops at release/2.35 e30c1c73da3f of 2022-03-03, 114 commits before f9f0fbbf7bba, and no entry of debian/patches/series carries 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, since DT_RELA is 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 dc1514eda55c libexec/rtld-elf/amd64/reloc.c:326-327 and :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 in docs/dev/debt/relinker.md records it. TracedImports loses its || Io::ReadU64(table, entry + 16) != 0: its only caller (line 359) runs after the new check on the same dynSection, and the disjunct is evaluated only for types 6 and 7, whose addend is then 0. Zero-addend entries and R_X86_64_64 import addends (S+A) are unchanged. GNU ld 2.42 -z mark-plt and lld since 7f8640b7bdab write the PLT entry address into the JUMP_SLOT addend (bfd/elf64-x86-64.c:4618-4619 in binutils 2.42). No title executable was scanned for such entries; all existing tests and fixtures use addend 0.
  • Tests. test_jmprel_table_bounds.py: fixture() gains an optional addend keyword (default 0) and run() maps the targets macos, lazy and fixed (--linux-fixed-base 0x10000000); existing callers are unchanged. For the default Linux, fixed-base, --lazy-binding, --windows and --macos targets 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 with AssertionError: ('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.
  • Overlap. pr_overlap.py reports no shared lines with open pull requests that merge with main; #10402, #10564 and #10607 also change LinuxElfPatcher.cpp and merge cleanly with this branch, and a trial merge with #10402 built and passed jmprel_table_bounds, linux_load_bounds and entry_point_bounds. It cannot compare this branch with #5021, #8076, #9408 and #10647 (docs/dev/debt/relinker.md), because those do not merge with main. Checked by hand: they insert next to the guest import registry, syscall scan and --trace-imports entries or rewrite the --trace-imports entry, while this PR inserts after the Unscoped imports on Linux entry, a place where #7173, #10518, #10861, #10871 and #10947, which edit other lines of the file, also merge cleanly. #11041 adds a -none-in-plt run at the end of the inner loop of test_jmprel_table_bounds.py that 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.

  • Rebased onto 16ff208dc3 (#10646 merged). Counter-check: jmprel_table_bounds with LinuxElfPatcher.cpp reverted to 16ff208dc3 fails at the first new case, linux-jump-slot-addend-10 (exit 0, output written, AssertionError at run()); 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.
  • 20 related tests passed on 16ff208dc3 plus this change (ctest -R over 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_converter and entry_stub (each under 0.4 s); amd64_only_converter, which like linux_load_pages compiles LinuxElfPatcher.cpp, passed as well. amd64_only_windows passed in the full suite.
  • Full suite: ctest --test-dir build-relinker -j 6 on 16ff208dc3: 262 tests, 259 passed, long_paths skipped; failures known on this machine on main as well: select_tests (Windows symlink fixture) and patch_advisor_unit (repository path with spaces, fixed by #10667); no timeouts.
  • python tools/check_conventions.py --base upstream/main with this title and description passed.
  • Not tested on Linux or macOS; CI runs the tests on all three hosts.

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 (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5004392828 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10971). Originally posted by [roboterspinne](https://github.com/roboterspinne) on 2026-10-25T11:39:43Z. --- ### What An `R_X86_64_GLOB_DAT` (6) or `R_X86_64_JUMP_SLOT` (7) relocation with a nonzero `r_addend` passed every check and reached the Linux output's `DT_RELA`/`DT_JMPREL` unchanged. `ValidateRelocationTypeSupported` accepts both types, `extractRela` in `RelinkerPipeline.cpp` checks no addend for them (the pipeline's only addend check is the DTPMOD64 one in `extractLocal`, lines 581-582), `SysVDynamicSectionBuilder.cpp:153` and `:163` copy `ref.Addend`, and `LinuxElfPatcher.cpp` rebases only `r_offset` (`RebasedRelocations`, lines 66-97). On `fixture(linux=True)` of `test_jmprel_table_bounds.py` with addend 0x10 or -8, the default, `--linux-fixed-base 0x10000000` and `--lazy-binding` runs exited 0 and emitted `(0x400300, 0x10000300 or 0x300; type 6 or 7; symbol 1; addend 16 or -8)`, while `--windows` and `--macos` exit 2 with `FAIL: GLOB_DAT/JUMP_SLOT relocation has a nonzero addend (offset 0x300)` (`WindowsRelocationBuilder.cpp:66-67`, reached from `MacOsMachOPatcher.cpp:67`) and guest modules fail on every target (`GuestImageReader.cpp:267`). - **Rule.** Line numbers are those on `main`. `RequireZeroImportSlotAddends` in `LinuxElfPatcher.cpp` throws `GLOB_DAT/JUMP_SLOT relocation has a nonzero addend` with the unrebased `r_offset` for a type 6 or 7 entry of `RelaData` or `RelaPltData` whose addend is not 0, the message and offset the Windows and macOS outputs already print. `Patch` calls it unconditionally, before `RequireOnlyDependencies`, `TracedImports` and the fixed-base rebasing in `table()`. 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 is `ET_EXEC` at 0x400000 (`Conversion.cpp:153`) and `--linux-fixed-base` picks another base, both with `DF_BIND_NOW` (lines 476-477); `--lazy-binding` keeps `ET_DYN` without 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](https://github.com/bminor/glibc/commit/f8587a61892cbafd98ce599131bf4f103466f084) ("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](https://github.com/bminor/glibc/blob/glibc-2.35/sysdeps/x86_64/dl-machine.h#L344-L346)); lazy JUMP_SLOT has always written S (`elf_machine_plt_value`, [glibc-2.35 dl-machine.h#L235-L239](https://github.com/bminor/glibc/blob/glibc-2.35/sysdeps/x86_64/dl-machine.h#L235-L239), called from [elf/dl-runtime.c#L121](https://github.com/bminor/glibc/blob/glibc-2.35/elf/dl-runtime.c#L121)). The commit first shipped in glibc 2.36 ([dl-machine.h#L305-L307](https://github.com/bminor/glibc/blob/glibc-2.36/sysdeps/x86_64/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 (Launchpad `ubuntu/+source/glibc`, `ubuntu/jammy-updates`: `debian/patches/git-updates.diff` stops at release/2.35 e30c1c73da3f of 2022-03-03, 114 commits before f9f0fbbf7bba, and no entry of `debian/patches/series` carries 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](https://sources.debian.org/src/glibc/2.31-13+deb11u11/sysdeps/x86_64/dl-machine.h/#L357), `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, since `DT_RELA` is 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 dc1514eda55c `libexec/rtld-elf/amd64/reloc.c:326-327` and `: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 in `docs/dev/debt/relinker.md` records it. `TracedImports` loses its `|| Io::ReadU64(table, entry + 16) != 0`: its only caller (line 359) runs after the new check on the same `dynSection`, and the disjunct is evaluated only for types 6 and 7, whose addend is then 0. Zero-addend entries and `R_X86_64_64` import addends (S+A) are unchanged. GNU ld 2.42 `-z mark-plt` and lld since 7f8640b7bdab write the PLT entry address into the JUMP_SLOT addend (`bfd/elf64-x86-64.c:4618-4619` in binutils 2.42). No title executable was scanned for such entries; all existing tests and fixtures use addend 0. - **Tests.** `test_jmprel_table_bounds.py`: `fixture()` gains an optional `addend` keyword (default 0) and `run()` maps the targets `macos`, `lazy` and `fixed` (`--linux-fixed-base 0x10000000`); existing callers are unchanged. For the default Linux, fixed-base, `--lazy-binding`, `--windows` and `--macos` targets 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 with `AssertionError: ('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. - **Overlap.** `pr_overlap.py` reports no shared lines with open pull requests that merge with `main`; #10402, #10564 and #10607 also change `LinuxElfPatcher.cpp` and merge cleanly with this branch, and a trial merge with #10402 built and passed `jmprel_table_bounds`, `linux_load_bounds` and `entry_point_bounds`. It cannot compare this branch with #5021, #8076, #9408 and #10647 (`docs/dev/debt/relinker.md`), because those do not merge with `main`. Checked by hand: they insert next to the guest import registry, syscall scan and `--trace-imports` entries or rewrite the `--trace-imports` entry, while this PR inserts after the `Unscoped imports on Linux` entry, a place where #7173, #10518, #10861, #10871 and #10947, which edit other lines of the file, also merge cleanly. #11041 adds a `-none-in-plt` run at the end of the inner loop of `test_jmprel_table_bounds.py` that 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 <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> 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. - Rebased onto 16ff208dc3 (#10646 merged). Counter-check: `jmprel_table_bounds` with `LinuxElfPatcher.cpp` reverted to 16ff208dc3 fails at the first new case, `linux-jump-slot-addend-10` (exit 0, output written, `AssertionError` at `run()`); 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. - 20 related tests passed on 16ff208dc3 plus this change (`ctest -R` over 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_converter` and `entry_stub` (each under 0.4 s); `amd64_only_converter`, which like `linux_load_pages` compiles `LinuxElfPatcher.cpp`, passed as well. `amd64_only_windows` passed in the full suite. - Full suite: `ctest --test-dir build-relinker -j 6` on 16ff208dc3: 262 tests, 259 passed, `long_paths` skipped; failures known on this machine on `main` as well: `select_tests` (Windows symlink fixture) and `patch_advisor_unit` (repository path with spaces, fixed by #10667); no timeouts. - `python tools/check_conventions.py --base upstream/main` with this title and description passed. - Not tested on Linux or macOS; CI runs the tests on all three hosts. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code)
MarcZX10 commented 2026-10-25 11:50:07 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643073359 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10971#pullrequestreview-5643073359). Originally posted by [MarcZX10](https://github.com/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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!10971
No description provided.