fix(relinker): reject conflicting duplicates of the dynamic tags the pipeline reads #10752

Merged
roboterspinne merged 1 commit from upstream-pr/10752 into main 2026-10-25 16:49:08 +00:00
roboterspinne commented 2026-10-24 21:18:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-24T21:18:57Z.


What

getTagValue in RelinkerPipeline.cpp returned the first entry of a dynamic tag, so an executable whose PT_DYNAMIC repeats a tag the pipeline reads with a different value was converted with the first value. On the fixture of test_rela_size.py (one R_X86_64_RELATIVE relocation of the slot the entry jumps through), DT_RELASZ 0 followed by DT_RELASZ 24 relinked for the default and --lazy-binding Linux outputs with exit 0 and an output without DT_RELA and DT_RELASZ, so the relocation was gone, while the order 24 then 0 kept it. The same input fails with Conflicting duplicate DT_RELASZ tags under unused-filter=1 (#7768), with Strict filter: duplicate dynamic tag under unused-filter=2 and with Code analysis: duplicate dynamic tag on Windows and macOS.

  • Rule. getTagValue now scans every entry of the tag it is asked for and throws Conflicting duplicate <NAME> tags when a later entry carries a different value; it covers exactly the single-valued tags the pipeline reads (DT_STRTAB, DT_STRSZ, DT_SYMTAB, DT_SYMENT, DT_PLTGOT, DT_PLTREL, DT_PLTRELSZ, DT_JMPREL, DT_RELA, DT_RELASZ, DT_RELAENT, their DT_OS_ variants and DT_OS_SYMTABSZ). This is the rule and message RelativeRelocationIndex.cpp has applied to DT_RELA, DT_RELASZ, DT_JMPREL and DT_PLTRELSZ with unused-filter=1 since #7768. The gABI fixes the position only of the final DT_NULL and the relative order of DT_NEEDED entries, which it allows to repeat, and says nothing about a repeated single-valued tag; glibc and FreeBSD rtld keep the last entry (read from their source), the PS5 loader's choice is unknown, so a conflict fails instead of picking a value. A repeat with the same value is accepted as before: it is not ambiguous, and #1938, which also rejected identical repeats, was closed because no title was shown and because rejecting identical repeats could refuse an input the console loads. No title is known to carry such a conflict; the case for the check is that one input today converts for Linux with unused-filter=0, fails with unused-filter=1, with unused-filter=2 and on Windows and macOS, and its Linux output depends on entry order. Windows and macOS already fail every repeat of these tags in code analysis (CodeInstructionCollector.cpp), and so does unused-filter=2 (StrictNidFilter.cpp), so no input that converts there today is affected and an identical repeat still fails there; tags the pipeline does not read, DT_NEEDED and the not-found message are unchanged.
  • Tests. test_rela_size.py (registered as rela_size, no CMake change) runs the default and --lazy-binding Linux, Windows and macOS outputs: DT_RELASZ 0 then 24 and 24 then 0, DT_OS_RELASZ 0 then 24 and DT_STRTAB 0x600 then 0x700 each fail with exit 2, no output and the identical FAIL line on all four targets and with unused-filter=1; DT_RELASZ 24 twice converts on both Linux outputs with DT_RELASZ 24 in the output and still fails in code analysis on Windows and macOS; two DT_NEEDED entries still convert on all four. The output dynamic-table parsing of the existing size loop moved into output_tags so the new case can use it.
  • Overlap. pr_overlap.py cannot compare this branch with #8076 (RelinkerPipeline.cpp), because it does not merge with main, and reports no other shared lines. Checked by hand: the hunk of #8076 covers lines 374 to 387 (unwind ranges), this PR changes the getTagValue lambda at lines 122 to 159; the author's open PRs change the same file at lines 22 to 73, 103 to 112, 278 to 281, 315 to 316, 434 to 477 and 548 to 549, and git merge-tree with each is clean.

Tested

Windows 11, GCC 15.2.0 (WinLibs UCRT), Python 3.13.9, relinker-only Release build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON); synthetic fixtures only, no title or homebrew, relinked outputs not run.

  • rela_size against an untouched build of upstream/main (c8d34aa8f4) fails with 17 entries: the four conflicting inputs relink with exit 0 on both Linux outputs (DT_RELASZ and DT_OS_RELASZ 0 then 24 give an output without DT_RELA and DT_RELASZ, 24 then 0 keeps DT_RELASZ 24) and fail on Windows and macOS with Code analysis: duplicate dynamic tag (offset 0x470); with unused-filter=1 the DT_RELASZ and DT_OS_RELASZ inputs already fail with Conflicting duplicate ... tags and the DT_STRTAB input relinks with exit 0; the same-value and DT_NEEDED cases pass. With this change all 20 conflicting runs print the same FAIL line and the controls behave as before.
  • ctest --test-dir build-relinker -R rela_size: passed in 2.6 s; dynamic_segment, optional_plt, optional_rela, linux_dynamic_strings, needed_libraries, string_table_bounds, jmprel_table_bounds, unused_filter_indirect, strict_nid_filter and guest_needed_modules passed (4.7 s with -j 6).
  • ctest --test-dir build-relinker -j 6: 244 tests, 241 passed, long_paths skipped; select_tests (FileExistsError creating the symlink fixture in tools/tests/test_select_tests.py) and patch_advisor_unit (temporary directory path with a space, fix open in #10667) are known local failures on this machine, unrelated to this change.
  • 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:4999251947 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10752). Originally posted by [roboterspinne](https://github.com/roboterspinne) on 2026-10-24T21:18:57Z. --- ### What `getTagValue` in `RelinkerPipeline.cpp` returned the first entry of a dynamic tag, so an executable whose `PT_DYNAMIC` repeats a tag the pipeline reads with a different value was converted with the first value. On the fixture of `test_rela_size.py` (one `R_X86_64_RELATIVE` relocation of the slot the entry jumps through), `DT_RELASZ` 0 followed by `DT_RELASZ` 24 relinked for the default and `--lazy-binding` Linux outputs with exit 0 and an output without `DT_RELA` and `DT_RELASZ`, so the relocation was gone, while the order 24 then 0 kept it. The same input fails with `Conflicting duplicate DT_RELASZ tags` under `unused-filter=1` (#7768), with `Strict filter: duplicate dynamic tag` under `unused-filter=2` and with `Code analysis: duplicate dynamic tag` on Windows and macOS. - **Rule.** `getTagValue` now scans every entry of the tag it is asked for and throws `Conflicting duplicate <NAME> tags` when a later entry carries a different value; it covers exactly the single-valued tags the pipeline reads (`DT_STRTAB`, `DT_STRSZ`, `DT_SYMTAB`, `DT_SYMENT`, `DT_PLTGOT`, `DT_PLTREL`, `DT_PLTRELSZ`, `DT_JMPREL`, `DT_RELA`, `DT_RELASZ`, `DT_RELAENT`, their `DT_OS_` variants and `DT_OS_SYMTABSZ`). This is the rule and message `RelativeRelocationIndex.cpp` has applied to `DT_RELA`, `DT_RELASZ`, `DT_JMPREL` and `DT_PLTRELSZ` with `unused-filter=1` since #7768. The gABI fixes the position only of the final `DT_NULL` and the relative order of `DT_NEEDED` entries, which it allows to repeat, and says nothing about a repeated single-valued tag; glibc and FreeBSD rtld keep the last entry (read from their source), the PS5 loader's choice is unknown, so a conflict fails instead of picking a value. A repeat with the same value is accepted as before: it is not ambiguous, and #1938, which also rejected identical repeats, was closed because no title was shown and because rejecting identical repeats could refuse an input the console loads. No title is known to carry such a conflict; the case for the check is that one input today converts for Linux with `unused-filter=0`, fails with `unused-filter=1`, with `unused-filter=2` and on Windows and macOS, and its Linux output depends on entry order. Windows and macOS already fail every repeat of these tags in code analysis (`CodeInstructionCollector.cpp`), and so does `unused-filter=2` (`StrictNidFilter.cpp`), so no input that converts there today is affected and an identical repeat still fails there; tags the pipeline does not read, `DT_NEEDED` and the not-found message are unchanged. - **Tests.** `test_rela_size.py` (registered as `rela_size`, no CMake change) runs the default and `--lazy-binding` Linux, Windows and macOS outputs: `DT_RELASZ` 0 then 24 and 24 then 0, `DT_OS_RELASZ` 0 then 24 and `DT_STRTAB` 0x600 then 0x700 each fail with exit 2, no output and the identical `FAIL` line on all four targets and with `unused-filter=1`; `DT_RELASZ` 24 twice converts on both Linux outputs with `DT_RELASZ` 24 in the output and still fails in code analysis on Windows and macOS; two `DT_NEEDED` entries still convert on all four. The output dynamic-table parsing of the existing size loop moved into `output_tags` so the new case can use it. - **Overlap.** `pr_overlap.py` cannot compare this branch with #8076 (`RelinkerPipeline.cpp`), because it does not merge with `main`, and reports no other shared lines. Checked by hand: the hunk of #8076 covers lines 374 to 387 (unwind ranges), this PR changes the `getTagValue` lambda at lines 122 to 159; the author's open PRs change the same file at lines 22 to 73, 103 to 112, 278 to 281, 315 to 316, 434 to 477 and 548 to 549, and `git merge-tree` with each is clean. ### 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), Python 3.13.9, relinker-only Release build (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`); synthetic fixtures only, no title or homebrew, relinked outputs not run. - `rela_size` against an untouched build of `upstream/main` (c8d34aa8f4) fails with 17 entries: the four conflicting inputs relink with exit 0 on both Linux outputs (`DT_RELASZ` and `DT_OS_RELASZ` 0 then 24 give an output without `DT_RELA` and `DT_RELASZ`, 24 then 0 keeps `DT_RELASZ` 24) and fail on Windows and macOS with `Code analysis: duplicate dynamic tag (offset 0x470)`; with `unused-filter=1` the `DT_RELASZ` and `DT_OS_RELASZ` inputs already fail with `Conflicting duplicate ... tags` and the `DT_STRTAB` input relinks with exit 0; the same-value and `DT_NEEDED` cases pass. With this change all 20 conflicting runs print the same `FAIL` line and the controls behave as before. - `ctest --test-dir build-relinker -R rela_size`: passed in 2.6 s; `dynamic_segment`, `optional_plt`, `optional_rela`, `linux_dynamic_strings`, `needed_libraries`, `string_table_bounds`, `jmprel_table_bounds`, `unused_filter_indirect`, `strict_nid_filter` and `guest_needed_modules` passed (4.7 s with `-j 6`). - `ctest --test-dir build-relinker -j 6`: 244 tests, 241 passed, `long_paths` skipped; `select_tests` (`FileExistsError` creating the symlink fixture in `tools/tests/test_select_tests.py`) and `patch_advisor_unit` (temporary directory path with a space, fix open in #10667) are known local failures on this machine, unrelated to this change. - `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-24 21:43:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T21:43:33Z.

Review: APPROVED


Reviewed exact head 76e32bca2d. The new tag lookup rejects only conflicting duplicate values for the requested single-valued tags, preserves identical repeats and repeated DT_NEEDED entries, and keeps the existing missing-tag diagnostic. The added fixtures cover both conflict orders, the OS variant, DT_STRTAB, same-value and repeated-needed controls across requested output modes. I built the exact PR relinker in a relinker-only Release configuration and ran ctest --test-dir build-review -R ^rela_size$ --output-on-failure (1/1 passed); check_conventions.py and git diff --check also passed. This local run was on Linux only; I did not execute Windows/macOS outputs here.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5640140821 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10752#pullrequestreview-5640140821). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T21:43:33Z. **Review:** APPROVED --- Reviewed exact head 76e32bca2da02719849f359bc89a1afba3e1a5cf. The new tag lookup rejects only conflicting duplicate values for the requested single-valued tags, preserves identical repeats and repeated DT_NEEDED entries, and keeps the existing missing-tag diagnostic. The added fixtures cover both conflict orders, the OS variant, DT_STRTAB, same-value and repeated-needed controls across requested output modes. I built the exact PR relinker in a relinker-only Release configuration and ran `ctest --test-dir build-review -R ^rela_size$ --output-on-failure` (1/1 passed); `check_conventions.py` and `git diff --check` also passed. This local run was on Linux only; I did not execute Windows/macOS outputs here.
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!10752
No description provided.