fix(relinker): import undefined global symbols with non-default visibility #17105
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17105"
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 ntamas94 on 2026-11-08T10:17:05Z.
What
Since #11925 the relinker refuses any relocation against an undefined, non-weak symbol whose
st_othervisibility isSTV_INTERNAL,STV_HIDDENorSTV_PROTECTED, in both the executable pipeline (RelinkerPipeline.cpp,extractRela) and the guest module reader (GuestImageReader.cpp). Retail PS4 modules contain such references and load on the console. Knowledge is Power (CUSA09558, Unity/Il2Cpp) shipsMedia/Modules/Il2CppUserAssemblies.prxwith aR_X86_64_JUMP_SLOTagainstf1zwJ3jAI2k#J#C(_Unwind_Resume, exported by libc):STB_GLOBAL,STT_FUNC,STV_PROTECTED,st_shndx0. On currentmainthe conversion stops withUndefined non-weak symbol has non-default visibility: f1zwJ3jAI2kand none of the 47 modules is converted. The same title boots and runs on a retail PS4 (FW 10.71), so the PS4 loader resolves that reference as an ordinary import from libc.The gABI rule #11925 cites describes what a correct producer emits: a reference with non-default visibility should be satisfied inside its own component. The PS4 toolchain that built this module did not enforce it, and the PS4 loader does not either: it binds the reference to libc's export by NID, as it does for a default-visibility import, and the game runs. The relinker has to accept what the console loader accepts, so an undefined global or weak reference becomes an import again, whatever its visibility.
What stays refused: an undefined
STB_LOCALsymbol with non-default visibility. A local symbol is not visible outside its object, so no other module can provide it and there is nothing to import. Both checks now testSTB_LOCALinstead of "notSTB_WEAK", and the message readsUndefined local symbol has non-default visibility: <name>.STB_LOCALis added next toSTB_GLOBALandSTB_WEAKinElfConstants.hpp. Defined symbols,R_X86_64_NONEand unreferenced entries are handled as before.Survey of the decrypted FW 10.71 system modules (452 with a dynamic table): none has a referenced undefined symbol with non-default visibility, so system modules are unaffected; the case only comes from game-side toolchains. In CUSA09558 it is the single such reference across
eboot.bin,Media/Modules,Media/Pluginsandsce_module.test_restricted_undefined_symbols.pykeeps its fixtures and target matrix. For each relocation type (1, 6, 7), target and (guest) standard/SCE dynamic tags, global and weak references with internal, hidden and protected visibility now convert; local references with each of the three visibilities are refused with the new message, leave the input unchanged and write neither output norapp0. The PLT/SCE/protected guest case is the Il2Cpp shape above. The filtered executable case uses a local hidden symbol and is still refused before filtering; the unreferenced case uses a local hidden entry and converts.Credit to #11925 for the checks and the fixtures this builds on.
Tested
Windows 11, WinLibs GCC 15.2.0, Ninja, Release,
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON, ond333e6d428(this branch merged withmain141cc61132). The later merge ofmain429035f99fonly changes an AGC execution test outside the relinker-only build..cppfiles ofmain, all sixrestricted_undefined_symbols_*partitions fail, and CUSA09558 exits 2 withUndefined non-weak symbol has non-default visibility: f1zwJ3jAI2kat0/47.ctest --test-dir build -j8: 814 of 815 pass, including all sixrestricted_undefined_symbols_*partitions. The one failure,vulkan_validation_gate_commands, isos.symlinkfailing withWinError 1314(no symlink privilege on this Windows account) intools/tests/test_vulkan_validation_gate.pyand is unrelated.relinker --windows --registry --module-dir Media/Modules --module-dir Media/Plugins app0/eboot.bin kip1.exeexits 0 withPRX conversion 100% (47/47)and writeskip1.exe. Not run past conversion here.python3 tools/check_conventions.py --base origin/main: all checks passed.tools/pr_overlap.py --branch fix/relinker-undefined-visibility-imports: 13 of 1,759 open PRs share files. It reports one line conflict: #14370 (refuses executable relocations against defined local, hidden or internal symbols) edits the same lines oftest_restricted_undefined_symbols.py(theERRORconstant and the case loop), where both PRs add cases. The rules do not overlap: #14370 is about defined symbols, this PR about undefined ones, so whichever lands second needs a small merge of the test loop. It could not compare #11525, #15900 and #15903, which already conflict withmain. Checked by hand: #11525'sRelinkerPipeline.cpphunks are in the unwind/data-table code afterextractRela, #15900 adds two page-size constants toElfConstants.hppaway from theSTB_*lines, and #15903 conflicts with this branch only indocs/dev/debt/relinker.md, as it does withmain.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)Il2CppUserAssemblies.prx)Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T10:53:01Z.
Review: COMMENTED
Windows check of head
cf3673c3ac, merged ontomain49f3653632(clean merge). It also checks one thing the tests don't: what the converted output says about the reference's visibility.Setup: Windows 11, WinLibs GCC 15.2, Release, relinker-only with
BUILD_TESTING=ON.restricted_undefined_symbols_*tests and 22 other import tests (-R 'restricted_undefined|guest_unused_import|needed_libraries|import', 28 tests) all pass.main'sGuestImageReader.cppandRelinkerPipeline.cppand this PR's test: 0 / 6. Each one stops on the first global case, for example7-linux-False-visibility-1, withUndefined non-weak symbol has non-default visibility: symbol. With the PR's files put back, 6 / 6 pass.Visibility in the output. The test only checks the exit code and that the output exists. If a Linux output kept
STV_HIDDENorSTV_INTERNALon the import, glibc'sld.sowould bind the reference to the module itself (dl_symbol_visibility_binds_local_p) instead of to libc. So I converted the test's executable fixture forlinuxandpie, with relocation types 1, 6 and 7, visibilities 0 to 3, and global and weak binding: 48 outputs. I then readsymbolin each output's.dynsym. Every one hasst_other0 andst_shndxUND, with its binding kept.SysVDynamicSectionBuilderwritesSTV_DEFAULTfor every import (lines 151 and 161), so the source visibility doesn't reachld.so. The guest-module outputs for the same matrix, also with and without the SCE tags, convert, and their section-header symbol tables have no undefined entries, and the guest-side checks inGuestImageReaderandGuestModuleBuilderonly look at visibility on defined symbols.I haven't run a converted title, on Linux or Windows.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T12:03:29Z.
Review: APPROVED
Reviewed — looks good
The change consistently permits undefined global and weak symbols with non-default visibility while continuing to reject referenced undefined local symbols in both executable and guest relocation paths.
What I ran
Read the prepared diff and all four changed files at head
cf3673c3ac2292b5fa0345625e344c061a10274, then checked the CMake registration for the updated test. No build or tests were run during this review.repo_read.pywas not invoked; the pinned repository reader tools were used.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The author reports 814 of 815 tests passing, with one unrelated Windows symlink privilege failure, and successful conversion of CUSA09558. These results were not independently run or verified. No hardware or console behavior was tested during this review.
review/files.jsonwas not available through the reader; the manifest lists four changed files, all included and read.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T10:11:06Z.
Review: APPROVED
Reviewed — looks good
The change accepts undefined global and weak symbols with non-default visibility while continuing to reject referenced undefined local symbols, and the inspected code supports that behavior.
What I ran
Reviewed head
cbb85e152abeedbe7191c59b883bb5b5001b5512; basemainis listed in the manifest. I read the prepared description, commits, manifest and diff, then inspected the changed code, tests, and test registration with the pinned reader. I did not run tests or build commands.Commands run: none.
Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not run the tests, build, or independently verify the author-reported console conversion and runtime behavior. The prepared review bundle lists all four changed files as included, and I read all four; no changed files were excluded.
To get this to a good state
Nothing is required.