fix(relinker): reject executable relocations against defined local, hidden or internal symbols #14370
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14370"
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-11-01T10:42:52Z.
What
On
26fa1212b8(line numbers below refer to it) anR_X86_64_64,R_X86_64_GLOB_DATorR_X86_64_JUMP_SLOTrelocation in the main executable against a symbol that the executable itself defines withSTB_LOCALbinding orSTV_HIDDENorSTV_INTERNALvisibility is converted into an import of that name from a library.extractRelachecks the visibility of undefined symbols (RelinkerPipeline.cpp:426, from #11925) but turns every other named, non-TLS reference into aNidReferencewithout looking atst_shndxor the binding, andSysVDynamicSectionBuilder.cpp:151and:161write each one as an undefinedSTV_DEFAULTsymbol withst_shndx0. The definition is dropped: for aGLOB_DATagainst a defined local or hiddenSTT_FUNCsymbol, the Linux output's.dynsymholds onlysymbolwithst_shndx0, so the host loader binds the slot to whatever library exports the name, while for a default or protected definition it also keeps the export (st_shndx1, 0x400200). The Windows output loads the name from a library at start, and the macOS output takes the same import path. Linux,--lazy-binding,--windowsand--macosall convert such input with exit 0. The ELF gABI symbol table (binding and visibility) says that a local symbol is not visible outside its object and that a hidden or internal symbol is not visible to other components, so such a reference binds to the definition in the same component, as the psABI'sSfor these relocation types assumes. The guest path already does that:WindowsGuestModuleWriter.cpp:68-70writes the module's own relocatedst_valuefor a defined symbol, and the guestdefined-hiddencase oftest_restricted_undefined_symbols.pyis accepted. The executable path has no such resolution, andWindowsRelocationBuilder.cpp:66-67(Defined symbols require explicit relocation support) shows that the import builders are not meant to receive a defined symbol, but that check is never reached because the SysV builder has already made every symbol undefined. #11925 states that "Defined hidden symbols, ordinary global/weak imports and unreferenced symbol entries remain accepted."; the defined hidden case was tested on the guest branch only, and its executable cases have no defined symbol. Binding the slot to the executable's own definition, as closed #5229 proposed, is not implemented here; this PR refuses the input instead of converting it into a wrong binding, in the same family as #11925, #11881 and #11367.extractRelathrowsRelocation names a defined symbol that is local, hidden or internal: <name>at the symbol entry's offset whenst_shndxis notSHN_UNDEFand the binding isSTB_LOCALor the visibility isSTV_INTERNALorSTV_HIDDEN. It covers every relocation that reaches the import list, on every target, and runs before NID filtering, sounused-filterlevels refuse as well. Global and weak definitions with default or protected visibility are unchanged; the Linux output keeps their export, and the executable comes first in the lookup scope. Section symbols keep theUnnamed import symbol is not a null symbol entrymessage, because the new check comes after that one. The gap is recorded indocs/dev/debt/relinker.md, next to the null-symbol entry. 14 retail executables checked for #5229 have no such relocation, so no title changes.test_restricted_undefined_symbols.pygives the executable fixture adefinedoption (st_shndx1,st_value0x200 inside itsPT_LOAD) and adds six executable cases per relocation type (1, 6, 7) and target (Linux,--lazy-binding,--windows,--macos):defined-defaultanddefined-protectedconvert, whiledefined-local,defined-internal,defined-hiddenanddefined-hidden-filtered(unused-filter=1) fail with exit 2 and the new message, write neither the output norapp0, and leave the input unchanged. The expected message is now passed per case. The existing cases and the guest cases are unchanged.pr_overlap.py --branchfinds no shared lines with the open pull requests it can compare and cannot compare twelve that do not merge with its base: #10861, which also changesRelinkerPipeline.cpp, and #5021, #10518, #11628, #11661, #11689, #11698, #11991, #12678, #12910, #14107 and #14212, which share onlydocs/dev/debt/relinker.md. Checked by hand: a trial merge of this branch with each of the first eleven conflicts only in the files that26fa1212b8with it already conflicts in, andRelinkerPipeline.cppmerges cleanly with #10861; #14212 puts a blank line between debt entries; it already conflicts with26fa1212b8in 31 other debt files but not indocs/dev/debt/relinker.md, and with this branch it also conflicts there, only at the one entry this PR adds, so whichever lands second needs a one-line rebase. My open #12341 and #13862 (RelinkerPipeline.cpp) and #11487 and #11883 (docs/dev/debt/relinker.md) merge with this branch without conflict.Tested
Windows 11, WinLibs GCC 15.2.0, relinker-only build (
cmake -S . -B build-relinker -G Ninja -DCMAKE_BUILD_TYPE=Release -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON,cmake --build build-relinker --parallel 6) on26fa1212b8and on this branch:26fa1212b8,ctest --test-dir build-relinker -R restricted_undefined_symbols --output-on-failurefailsrestricted_undefined_symbols_executable_1,_6and_7, each withAssertionError: ('<type>-linux-False-defined-local', [], 0, 'Converting input.elf ... Conversion complete ...', ''), afterdefined-defaultanddefined-protectedconverted; the three guest partitions pass. A probe with the same fixtures converts every local, internal, hidden, default and protected case for types 1, 6 and 7 with exit 0 on Linux,--lazy-binding,--windowsand--macos.Restricted undefined symbol tests passed: 56 conversions (executable), up from 32. The probe now gives exit 2 for every local, internal and hidden case and exit 0 for every default and protected case.ctest --test-dir build-relinker -j 6: 552 tests, 546 passed,long_pathsskipped;annotate_module, which teststools/annotate_module.pyand does not run the relinker, timed out under the parallel load and passes alone in 14.0 s;select_testsand its three partsselect_tests_SelectGraphStateTests,select_tests_SelectBuildTestsandselect_tests_SelectArgumentTestsfail with the Windows symlink fixture'sFileExistsError, as onmainon this machine; this change touches nothing undertools/.e4bf9457c5changes only the message text andDEFINED_ERROR: with the updated test file and the relinker built frome3db043f72,restricted_undefined_symbols_executable_1,_6and_7fail with anAssertionErrorwhose stderr containsFAIL: Relocation names a locally bound defined symbol: symbol (offset 0x638); withe4bf9457c5,ctest --test-dir build-relinker -R 'restricted_undefined_symbols|executable_tls_relocations|call_registry|unused_filter' --output-on-failurepasses 11 of 11, again with 56 conversions per executable partition and 48 per guest partition. The fullctest -j 6, the timings and the probe above ran one3db043f72; no other file in the repository contains the old text.python tools/check_conventions.py --base 26fa1212b8with 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-11-01T11:14:18Z.
Review: COMMENTED
Reviewed — no blocking findings
The change adds one conversion-time check to the main-executable relocation scan, which rejects a relocation against a symbol the executable defines with local binding or hidden or internal visibility, and I found no defect in it, but its error text says "locally bound" for symbols that are global with hidden or internal visibility.
What I ran
Exact head
e3db043f72493756011f1197ff8a19d4c7366159, PR basee6f57307fa7f47165d7fc1bee945abdb2f6816e7. Environment: Debian 12, Python 3.11.2, git 2.39.5. No build and no relinker test was run locally.I also read the head version of
RelinkerPipeline.cpp(extractRela, lines 377-442) and the hosted log of the Windows relinker job. The precheck's test-quality helper could not find its script in its isolated head tree, so I ran it by hand as listed.Results
git diff --check(precheck)pr_test_quality.py(by hand)test_restricted_undefined_symbols.py.web_release, which hit its 20 s timeout. Allrestricted_undefined_symbols_executable_*andrestricted_undefined_symbols_guest_*tests that ran in that job passed.Unedited output from the Windows relinker job
Findings
Blocking: None.
Non-blocking:
st_shndxis defined and either the binding is local orst_other & 3is 1 (internal) or 2 (hidden). The message text, "Relocation names a locally bound defined symbol", is accurate only for the local-binding case. For a global symbol with hidden or internal visibility it reads as if the binding were local. Suggested wording: "Relocation names a defined symbol with local binding or hidden or internal visibility: ". TheDEFINED_ERRORconstant attest_restricted_undefined_symbols.pyline 14 would need the same change.Sources
extractRelaat the headNot verified
web_releasetimeout is in a different test and I did not investigate it further.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T14:08:54Z.
Review: COMMENTED
Reviewed — no blocking findings
Rejecting an executable relocation against a defined symbol that is local, hidden or internal matches the ELF visibility rules and the existing undefined-symbol visibility check; the rejection is intentional and documented in the debt file.
What I ran
e4bf9457c50d036bfe4b5bf4798637b2142e1b7d, basee6f57307fa./usr/bin/python33.11.2, no build.python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14370 --output-dir /dev/shm/reviewer-run/precheck/14370core/relinker/relinker/tests/test_restricted_undefined_symbols.pyfrom a head extract: no findings.core/relinker/relinker/src/pipeline/RelinkerPipeline.cppnear line 432, including the bit tests onst_other(& 3equal to 1 forSTV_INTERNAL, 2 forSTV_HIDDEN) and the binding test (< STB_GLOBAL).Results
Precheck report, checks table, unedited (
/dev/shm/reviewer-run/precheck/14370/report.md):The precheck deliberately does not configure, build, or compile AnyPS5.git diff --check e6f57307fa7f47165d7fc1bee945abdb2f6816e7...e4bf9457c50d036bfe4b5bf4798637b2142e1b7d/usr/bin/python3 tools/check_conventions.py --base e6f57307fa7f47165d7fc1bee945abdb2f6816e7 --head e4bf9457c50d036bfe4b5bf4798637b2142e1b7d --title fix(relinker): reject executable relocations against defined local, hidden or internal symbols --body /dev/shm/reviewer-run/precheck/14370/pr-body.mdNo changed source or public header under core/libs/prx./usr/bin/python3 -m py_compile core/relinker/relinker/tests/test_restricted_undefined_symbols.pyNo changed tools/ module has an existing sibling tools/tests/test_<module>.py suite./usr/bin/python3 tools/check_test_registration.py --scripts/usr/bin/python3 /marc/AnyPS5/tools/pr_stack_check.py 14370 --repo boykopovar/AnyPS5 --output-dir /dev/shm/reviewer-run/precheck/14370/stackNot run: C++ tests need exact-head binaries, which require a build; the precheck does not build./usr/bin/python3 /dev/shm/reviewer-run/precheck/14370/head-e4bf9457c50d-1e320f6c/tools/pr_test_quality.py --root /dev/shm/reviewer-run/precheck/14370/head-e4bf9457c50d-1e320f6c --json core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp core/relinker/relinker/tests/test_restricted_undefined_symbols.py docs/dev/debt/relinker.mdNo changed Python test module in tools/ can be run as a no-build base-source control.Negative control
Not run. The relinker test needs a built relinker binary, which the no-build policy does not allow here.
Findings
Blocking: none.
Non-blocking:
Sources
github.com/boykopovar/AnyPS5@e4bf9457c5/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp (L432-L433)Not verified
test_restricted_undefined_symbols.pywas not run (needs a build).conventionswas cancelled once andeligibilityandlabelssucceeded;linux,register-contextandwrite-watchwere skipped.