fix(relinker): reject conflicting duplicates of the dynamic tags the pipeline reads #10752
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10752"
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-24T21:18:57Z.
What
getTagValueinRelinkerPipeline.cppreturned the first entry of a dynamic tag, so an executable whosePT_DYNAMICrepeats a tag the pipeline reads with a different value was converted with the first value. On the fixture oftest_rela_size.py(oneR_X86_64_RELATIVErelocation of the slot the entry jumps through),DT_RELASZ0 followed byDT_RELASZ24 relinked for the default and--lazy-bindingLinux outputs with exit 0 and an output withoutDT_RELAandDT_RELASZ, so the relocation was gone, while the order 24 then 0 kept it. The same input fails withConflicting duplicate DT_RELASZ tagsunderunused-filter=1(#7768), withStrict filter: duplicate dynamic tagunderunused-filter=2and withCode analysis: duplicate dynamic tagon Windows and macOS.getTagValuenow scans every entry of the tag it is asked for and throwsConflicting duplicate <NAME> tagswhen 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, theirDT_OS_variants andDT_OS_SYMTABSZ). This is the rule and messageRelativeRelocationIndex.cpphas applied toDT_RELA,DT_RELASZ,DT_JMPRELandDT_PLTRELSZwithunused-filter=1since #7768. The gABI fixes the position only of the finalDT_NULLand the relative order ofDT_NEEDEDentries, 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 withunused-filter=0, fails withunused-filter=1, withunused-filter=2and 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 doesunused-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_NEEDEDand the not-found message are unchanged.test_rela_size.py(registered asrela_size, no CMake change) runs the default and--lazy-bindingLinux, Windows and macOS outputs:DT_RELASZ0 then 24 and 24 then 0,DT_OS_RELASZ0 then 24 andDT_STRTAB0x600 then 0x700 each fail with exit 2, no output and the identicalFAILline on all four targets and withunused-filter=1;DT_RELASZ24 twice converts on both Linux outputs withDT_RELASZ24 in the output and still fails in code analysis on Windows and macOS; twoDT_NEEDEDentries still convert on all four. The output dynamic-table parsing of the existing size loop moved intooutput_tagsso the new case can use it.pr_overlap.pycannot compare this branch with #8076 (RelinkerPipeline.cpp), because it does not merge withmain, and reports no other shared lines. Checked by hand: the hunk of #8076 covers lines 374 to 387 (unwind ranges), this PR changes thegetTagValuelambda 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, andgit merge-treewith 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_sizeagainst an untouched build ofupstream/main(c8d34aa8f4) fails with 17 entries: the four conflicting inputs relink with exit 0 on both Linux outputs (DT_RELASZandDT_OS_RELASZ0 then 24 give an output withoutDT_RELAandDT_RELASZ, 24 then 0 keepsDT_RELASZ24) and fail on Windows and macOS withCode analysis: duplicate dynamic tag (offset 0x470); withunused-filter=1theDT_RELASZandDT_OS_RELASZinputs already fail withConflicting duplicate ... tagsand theDT_STRTABinput relinks with exit 0; the same-value andDT_NEEDEDcases pass. With this change all 20 conflicting runs print the sameFAILline 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_filterandguest_needed_modulespassed (4.7 s with-j 6).ctest --test-dir build-relinker -j 6: 244 tests, 241 passed,long_pathsskipped;select_tests(FileExistsErrorcreating the symlink fixture intools/tests/test_select_tests.py) andpatch_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/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-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 ranctest --test-dir build-review -R ^rela_size$ --output-on-failure(1/1 passed);check_conventions.pyandgit diff --checkalso passed. This local run was on Linux only; I did not execute Windows/macOS outputs here.