fix(relinker): accept identical repeated dynamic tags in code analysis #14411

Merged
roboterspinne merged 1 commit from upstream-pr/14411 into main 2026-11-14 11:33:36 +00:00
roboterspinne commented 2026-11-01 11:51:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-11-01T11:51:44Z.


What

Code analysis, which every --windows and --macos conversion runs on the executable (WindowsTlsBuilder.cpp:125, MacOsImage.cpp:294 on 26fa1212b8; line numbers below refer to it), rejects every repeat of a dynamic tag it records, also when both entries carry the same value: CodeInstructionCollector.cpp:87 throws Code analysis: duplicate dynamic tag as soon as tags.emplace finds the tag. The rest of the relinker treats an identical repeat as one tag and fails only on a conflict in a tag it reads: getTagValue in RelinkerPipeline.cpp:145-185 (#10752, throw at lines 176-177), RelativeRelocationIndex.cpp:208-250 (#7768) and RelrRelocations.cpp:17-19 throw Conflicting duplicate <NAME> tags only when a later entry differs, and the maintainer-merged #11299 and #11923 accept an identical duplicate relocation as applying once. #1938, which rejected identical repeats, was closed because "no title is shown with a second PT_DYNAMIC or repeated table tags, and rejecting identical duplicates could refuse an input the console loads"; this change relaxes a check instead of adding one. On the fixture of test_rela_size.py, a second DT_RELASZ 24, two DT_FLAGS 8 or two DT_DEBUG 0 entries converted for Linux, with --lazy-binding and with unused-filter=1, and failed on --windows and --macos with FAIL: Code analysis: duplicate dynamic tag (offset 0x470) or (offset 0x480).

  • Rule. The collector's tag loop throws only when the tag is already recorded with a different value, now as Code analysis: conflicting duplicate dynamic tag with the offset of the later entry, matching the pipeline's Conflicting duplicate wording; an identical repeat keeps the first entry, which is the same value, so every later tags.at and the standard/SCE ambiguous dynamic tag check (line 92) read what they read for a single entry. The skip rule for DT_NEEDED and the SCE range and the invalid dynamic segment and unterminated dynamic segment checks are unchanged. This deliberately reverses what the description of #10752 stated, that Windows and macOS keep rejecting an identical repeat. No title is known to carry such a repeat; the case is that an input with an identical repeat converts for Linux and fails on Windows and macOS. A conflicting repeat of a tag the pipeline does not read, such as DT_INIT, still converts for Linux and fails on Windows and macOS. Left out on purpose: the guest module reader (GuestImageReader.cpp:89, Duplicate dynamic tag <n>) and the opt-in strict filter (StrictNidFilter.cpp:46, unused-filter=2) still reject identical repeats; they are separate follow-ups.
  • Tests. test_rela_size.py (registered as rela_size, no CMake change): the same-value DT_RELASZ case, which required the code analysis failure on Windows and macOS, now requires exit 0 and an ELF, PE or Mach-O output on the default and --lazy-binding Linux, --windows and --macos targets, with DT_RELASZ 24 in both Linux outputs; two DT_FLAGS 8 and two DT_DEBUG 0 entries, tags the pipeline does not read, must convert the same way on all four. Two DT_INIT entries with 0x200 and 0x210, a tag only code analysis reads (line 235), must fail on --windows and --macos with exit 2, no output and the single line FAIL: Code analysis: conflicting duplicate dynamic tag (offset 0x480).
  • Overlap. pr_overlap.py --branch finds no shared lines with the open pull requests it can compare and cannot compare #10861, #12154, #12282 and #14107, which also change CodeInstructionCollector.cpp but do not merge with main. Checked by hand: a trial merge of this branch with each of them conflicts only in the files that main with it already conflicts in (CodeInstructionCollector.cpp for all four, plus SyscallScanner.cpp, UnusedNidFilter/ControlFlowGraph.cpp, ConversionTests.cpp and docs/dev/debt/relinker.md for #10861), and test_rela_size.py is in none of them. #10861 rewrites the same tag check (line 87) and keeps rejecting identical repeats unless its new allowIdenticalDynamicTags is set, so whichever of the two lands second has to settle that line.

Tested

Windows 11, WinLibs GCC 15.2.0, Python 3.13.9, relinker-only build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON, Ninja, Release), on 6527e2ff82 (based on 26fa1212b8; main at e67cc81869 changed neither file and merges cleanly); synthetic fixtures only, no title or homebrew.

  • Counter-check: ctest --test-dir build-relinker -R '^rela_size$' --output-on-failure with the new test and the untouched CodeInstructionCollector.cpp of 26fa1212b8 fails with 8 entries: the three identical-repeat inputs on --windows and --macos exit 2 with FAIL: Code analysis: duplicate dynamic tag (offset 0x470) (DT_RELASZ) or (offset 0x480) (DT_FLAGS, DT_DEBUG), and the conflicting DT_INIT input fails with the old message instead of the new one; the Linux targets already pass. With the change it passes (rela_size 8.3 s, dynamic_segment 5.3 s, optional_plt 1.8 s).
  • The --windows outputs of the three identical-repeat inputs, run by hand on this host, exit with 42 as the optional_plt fixture they are built from does.
  • ctest --test-dir build-relinker -j 6: 552 tests, 540 passed, long_paths skipped. select_tests and its three parts select_tests_SelectGraphStateTests, select_tests_SelectBuildTests and select_tests_SelectArgumentTests fail with the Windows symlink fixture's FileExistsError, as on main on this machine. annotate_module, check_main_sync, its parts CheckMainSyncHistoryTests, PathTests, EncodingTests, GitTests and trace_digest_TraceDigestTests_test_cli_rejects_invalid_event_fields_without_partial_output timed out while the machine ran at 99 % CPU from other builds; run again alone, the four check_main_sync_* parts passed and the other three timed out again at their 20 s and 30 s limits. They are Python tests of tools/, which this change does not touch.
  • python tools/check_conventions.py --base 26fa1212b8 --head HEAD with this title and description passed.

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:5107060038 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14411). Originally posted by [roboterspinne](https://github.com/roboterspinne) on 2026-11-01T11:51:44Z. --- ### What Code analysis, which every `--windows` and `--macos` conversion runs on the executable (`WindowsTlsBuilder.cpp:125`, `MacOsImage.cpp:294` on 26fa1212b8; line numbers below refer to it), rejects every repeat of a dynamic tag it records, also when both entries carry the same value: `CodeInstructionCollector.cpp:87` throws `Code analysis: duplicate dynamic tag` as soon as `tags.emplace` finds the tag. The rest of the relinker treats an identical repeat as one tag and fails only on a conflict in a tag it reads: `getTagValue` in `RelinkerPipeline.cpp:145-185` (#10752, throw at lines 176-177), `RelativeRelocationIndex.cpp:208-250` (#7768) and `RelrRelocations.cpp:17-19` throw `Conflicting duplicate <NAME> tags` only when a later entry differs, and the maintainer-merged #11299 and #11923 accept an identical duplicate relocation as applying once. #1938, which rejected identical repeats, was closed because "no title is shown with a second `PT_DYNAMIC` or repeated table tags, and rejecting identical duplicates could refuse an input the console loads"; this change relaxes a check instead of adding one. On the fixture of `test_rela_size.py`, a second `DT_RELASZ` 24, two `DT_FLAGS` 8 or two `DT_DEBUG` 0 entries converted for Linux, with `--lazy-binding` and with `unused-filter=1`, and failed on `--windows` and `--macos` with `FAIL: Code analysis: duplicate dynamic tag (offset 0x470)` or `(offset 0x480)`. - **Rule.** The collector's tag loop throws only when the tag is already recorded with a different value, now as `Code analysis: conflicting duplicate dynamic tag` with the offset of the later entry, matching the pipeline's `Conflicting duplicate` wording; an identical repeat keeps the first entry, which is the same value, so every later `tags.at` and the standard/SCE `ambiguous dynamic tag` check (line 92) read what they read for a single entry. The skip rule for `DT_NEEDED` and the SCE range and the `invalid dynamic segment` and `unterminated dynamic segment` checks are unchanged. This deliberately reverses what the description of #10752 stated, that Windows and macOS keep rejecting an identical repeat. No title is known to carry such a repeat; the case is that an input with an identical repeat converts for Linux and fails on Windows and macOS. A conflicting repeat of a tag the pipeline does not read, such as `DT_INIT`, still converts for Linux and fails on Windows and macOS. Left out on purpose: the guest module reader (`GuestImageReader.cpp:89`, `Duplicate dynamic tag <n>`) and the opt-in strict filter (`StrictNidFilter.cpp:46`, `unused-filter=2`) still reject identical repeats; they are separate follow-ups. - **Tests.** `test_rela_size.py` (registered as `rela_size`, no CMake change): the same-value `DT_RELASZ` case, which required the code analysis failure on Windows and macOS, now requires exit 0 and an ELF, PE or Mach-O output on the default and `--lazy-binding` Linux, `--windows` and `--macos` targets, with `DT_RELASZ` 24 in both Linux outputs; two `DT_FLAGS` 8 and two `DT_DEBUG` 0 entries, tags the pipeline does not read, must convert the same way on all four. Two `DT_INIT` entries with 0x200 and 0x210, a tag only code analysis reads (line 235), must fail on `--windows` and `--macos` with exit 2, no output and the single line `FAIL: Code analysis: conflicting duplicate dynamic tag (offset 0x480)`. - **Overlap.** `pr_overlap.py --branch` finds no shared lines with the open pull requests it can compare and cannot compare #10861, #12154, #12282 and #14107, which also change `CodeInstructionCollector.cpp` but do not merge with `main`. Checked by hand: a trial merge of this branch with each of them conflicts only in the files that `main` with it already conflicts in (`CodeInstructionCollector.cpp` for all four, plus `SyscallScanner.cpp`, `UnusedNidFilter/ControlFlowGraph.cpp`, `ConversionTests.cpp` and `docs/dev/debt/relinker.md` for #10861), and `test_rela_size.py` is in none of them. #10861 rewrites the same tag check (line 87) and keeps rejecting identical repeats unless its new `allowIdenticalDynamicTags` is set, so whichever of the two lands second has to settle that line. ### 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, WinLibs GCC 15.2.0, Python 3.13.9, relinker-only build (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`, Ninja, Release), on 6527e2ff82 (based on 26fa1212b8; `main` at e67cc81869 changed neither file and merges cleanly); synthetic fixtures only, no title or homebrew. - Counter-check: `ctest --test-dir build-relinker -R '^rela_size$' --output-on-failure` with the new test and the untouched `CodeInstructionCollector.cpp` of 26fa1212b8 fails with 8 entries: the three identical-repeat inputs on `--windows` and `--macos` exit 2 with `FAIL: Code analysis: duplicate dynamic tag (offset 0x470)` (`DT_RELASZ`) or `(offset 0x480)` (`DT_FLAGS`, `DT_DEBUG`), and the conflicting `DT_INIT` input fails with the old message instead of the new one; the Linux targets already pass. With the change it passes (`rela_size` 8.3 s, `dynamic_segment` 5.3 s, `optional_plt` 1.8 s). - The `--windows` outputs of the three identical-repeat inputs, run by hand on this host, exit with 42 as the `optional_plt` fixture they are built from does. - `ctest --test-dir build-relinker -j 6`: 552 tests, 540 passed, `long_paths` skipped. `select_tests` and its three parts `select_tests_SelectGraphStateTests`, `select_tests_SelectBuildTests` and `select_tests_SelectArgumentTests` fail with the Windows symlink fixture's `FileExistsError`, as on `main` on this machine. `annotate_module`, `check_main_sync`, its parts `CheckMainSyncHistoryTests`, `PathTests`, `EncodingTests`, `GitTests` and `trace_digest_TraceDigestTests_test_cli_rejects_invalid_event_fields_without_partial_output` timed out while the machine ran at 99 % CPU from other builds; run again alone, the four `check_main_sync_*` parts passed and the other three timed out again at their 20 s and 30 s limits. They are Python tests of `tools/`, which this change does not touch. - `python tools/check_conventions.py --base 26fa1212b8 --head HEAD` with this title and description passed. ### 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-11-01 13:43:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T13:43:58Z.

Review: COMMENTED


Reviewed — no blocking findings

Identical repeats of a dynamic tag are now accepted in code analysis, and the change matches how the rest of the relinker already treats them; the one open question is a policy reversal for maintainers, not a defect.

What I ran

  • Exact head 6527e2ff82d023f0ee501bd8e29828c4d17a9a58, base ba627802e2210187d417deb64c8f2fed8e33011f.
  • Environment: Linux, /usr/bin/python3 3.11.2, no build.
  • Precheck: python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14411 --output-dir /dev/shm/reviewer-run/precheck/14411
  • Test-quality helper by hand on the head extract:
    python3 tools/pr_test_quality.py --root /dev/shm/reviewer-run/src2/14411 --json core/relinker/relinker/tests/test_rela_size.py
  • Source read at head: CodeInstructionCollector.cpp (tag map, ambiguous-tag check) and RelinkerPipeline.cpp (getTagValue).

Results

Precheck report, checks table, unedited (/dev/shm/reviewer-run/precheck/14411/report.md):

Check Status Command / reason
build_and_compile not_applicable The precheck deliberately does not configure, build, or compile AnyPS5.
diff_check passed git diff --check ba627802e2210187d417deb64c8f2fed8e33011f...6527e2ff82d023f0ee501bd8e29828c4d17a9a58
conventions_and_pr_template passed /usr/bin/python3 tools/check_conventions.py --base ba627802e2210187d417deb64c8f2fed8e33011f --head 6527e2ff82d023f0ee501bd8e29828c4d17a9a58 --title fix(relinker): accept identical repeated dynamic tags in code analysis --body /dev/shm/reviewer-run/precheck/14411/pr-body.md
changed_export_abi_audit not_applicable No changed source or public header under core/libs/prx.
python_syntax passed /usr/bin/python3 -m py_compile core/relinker/relinker/tests/test_rela_size.py
related_python_unit_tests not_applicable No changed tools/ module has an existing sibling tools/tests/test_<module>.py suite.
python_test_registration passed /usr/bin/python3 tools/check_test_registration.py --scripts
live_dependency_and_mergeability_check passed /usr/bin/python3 /marc/AnyPS5/tools/pr_stack_check.py 14411 --repo boykopovar/AnyPS5 --output-dir /dev/shm/reviewer-run/precheck/14411/stack
build_dependent_cpp_tests not_applicable Not run: C++ tests need exact-head binaries, which require a build; the precheck does not build.
test_quality_heuristics failed /usr/bin/python3 /dev/shm/reviewer-run/precheck/14411/head-6527e2ff82d0-b2000752/tools/pr_test_quality.py --root /dev/shm/reviewer-run/precheck/14411/head-6527e2ff82d0-b2000752 --json core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp core/relinker/relinker/tests/test_rela_size.py
negative_controls not_applicable No changed Python test module in tools/ can be run as a no-build base-source control.

Manual checks: the test-quality helper reported 0 findings for test_rela_size.py.

Negative control

Not run. The relinker test needs a built binary.

Findings

Blocking: none.

Non-blocking:

  • The tag map is a std::map, so an identical repeat keeps the first entry and the later ambiguous dynamic tag check still sees one entry per tag. A conflicting repeat throws conflicting duplicate dynamic tag with the later entry's offset.
  • The PR reverses the duplicate rejection that #1938 introduced. #1938 is closed (closed 2026-10-09). The PR quotes a closure reason; I did not check that quote, so the policy call is for maintainers.

Sources

Not verified

  • The relinker test test_rela_size.py was not run (needs a build), so the PR's expected outputs for the four targets are unconfirmed here.
  • Console handling of identical duplicate tags (the PR's basis for relaxing the check) is not verifiable on this host.
  • The closure rationale quoted from #1938 was not checked.
  • Hosted: relinker ubuntu, windows and asan passed; macOS clang jobs were queued at review time.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5728345478 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14411#pullrequestreview-5728345478). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-01T13:43:58Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Identical repeats of a dynamic tag are now accepted in code analysis, and the change matches how the rest of the relinker already treats them; the one open question is a policy reversal for maintainers, not a defect. ## What I ran - Exact head `6527e2ff82d023f0ee501bd8e29828c4d17a9a58`, base `ba627802e2210187d417deb64c8f2fed8e33011f`. - Environment: Linux, `/usr/bin/python3` 3.11.2, no build. - Precheck: `python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14411 --output-dir /dev/shm/reviewer-run/precheck/14411` - Test-quality helper by hand on the head extract: `python3 tools/pr_test_quality.py --root /dev/shm/reviewer-run/src2/14411 --json core/relinker/relinker/tests/test_rela_size.py` - Source read at head: `CodeInstructionCollector.cpp` (tag map, ambiguous-tag check) and `RelinkerPipeline.cpp` (`getTagValue`). ## Results Precheck report, checks table, unedited (`/dev/shm/reviewer-run/precheck/14411/report.md`): | Check | Status | Command / reason | |---|---|---| | build_and_compile | not_applicable | `The precheck deliberately does not configure, build, or compile AnyPS5.` | | diff_check | passed | `git diff --check ba627802e2210187d417deb64c8f2fed8e33011f...6527e2ff82d023f0ee501bd8e29828c4d17a9a58` | | conventions_and_pr_template | passed | `/usr/bin/python3 tools/check_conventions.py --base ba627802e2210187d417deb64c8f2fed8e33011f --head 6527e2ff82d023f0ee501bd8e29828c4d17a9a58 --title fix(relinker): accept identical repeated dynamic tags in code analysis --body /dev/shm/reviewer-run/precheck/14411/pr-body.md` | | changed_export_abi_audit | not_applicable | `No changed source or public header under core/libs/prx.` | | python_syntax | passed | `/usr/bin/python3 -m py_compile core/relinker/relinker/tests/test_rela_size.py` | | related_python_unit_tests | not_applicable | `No changed tools/ module has an existing sibling tools/tests/test_<module>.py suite.` | | python_test_registration | passed | `/usr/bin/python3 tools/check_test_registration.py --scripts` | | live_dependency_and_mergeability_check | passed | `/usr/bin/python3 /marc/AnyPS5/tools/pr_stack_check.py 14411 --repo boykopovar/AnyPS5 --output-dir /dev/shm/reviewer-run/precheck/14411/stack` | | build_dependent_cpp_tests | not_applicable | `Not run: C++ tests need exact-head binaries, which require a build; the precheck does not build.` | | test_quality_heuristics | failed | `/usr/bin/python3 /dev/shm/reviewer-run/precheck/14411/head-6527e2ff82d0-b2000752/tools/pr_test_quality.py --root /dev/shm/reviewer-run/precheck/14411/head-6527e2ff82d0-b2000752 --json core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp core/relinker/relinker/tests/test_rela_size.py` | | negative_controls | not_applicable | `No changed Python test module in tools/ can be run as a no-build base-source control.` | Manual checks: the test-quality helper reported 0 findings for `test_rela_size.py`. ## Negative control Not run. The relinker test needs a built binary. ## Findings **Blocking:** none. **Non-blocking:** - The tag map is a `std::map`, so an identical repeat keeps the first entry and the later `ambiguous dynamic tag` check still sees one entry per tag. A conflicting repeat throws `conflicting duplicate dynamic tag` with the later entry's offset. - The PR reverses the duplicate rejection that #1938 introduced. #1938 is closed (closed 2026-10-09). The PR quotes a closure reason; I did not check that quote, so the policy call is for maintainers. ## Sources - Tag map and new conflict check at head: https://github.com/boykopovar/AnyPS5/blob/6527e2ff82d023f0ee501bd8e29828c4d17a9a58/core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp#L72-L92 - Existing `Conflicting duplicate` behaviour in the pipeline at head: https://github.com/boykopovar/AnyPS5/blob/6527e2ff82d023f0ee501bd8e29828c4d17a9a58/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp#L145-L186 ## Not verified - The relinker test `test_rela_size.py` was not run (needs a build), so the PR's expected outputs for the four targets are unconfirmed here. - Console handling of identical duplicate tags (the PR's basis for relaxing the check) is not verifiable on this host. - The closure rationale quoted from #1938 was not checked. - Hosted: relinker ubuntu, windows and asan passed; macOS clang jobs were queued at review time.
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!14411
No description provided.