fix(relinker): import undefined global symbols with non-default visibility #17105

Merged
ntamas94 merged 5 commits from upstream-pr/17105 into main 2026-11-22 21:30:02 +00:00
ntamas94 commented 2026-11-08 10:17:05 +00:00 (Migrated from github.com)

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_other visibility is STV_INTERNAL, STV_HIDDEN or STV_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) ships Media/Modules/Il2CppUserAssemblies.prx with a R_X86_64_JUMP_SLOT against f1zwJ3jAI2k#J#C (_Unwind_Resume, exported by libc): STB_GLOBAL, STT_FUNC, STV_PROTECTED, st_shndx 0. On current main the conversion stops with Undefined non-weak symbol has non-default visibility: f1zwJ3jAI2k and 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_LOCAL symbol 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 test STB_LOCAL instead of "not STB_WEAK", and the message reads Undefined local symbol has non-default visibility: <name>. STB_LOCAL is added next to STB_GLOBAL and STB_WEAK in ElfConstants.hpp. Defined symbols, R_X86_64_NONE and 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/Plugins and sce_module.

  • Tests. test_restricted_undefined_symbols.py keeps 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 nor app0. 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, on d333e6d428 (this branch merged with main 141cc61132). The later merge of main 429035f99f only changes an AGC execution test outside the relinker-only build.

  • Counter-check: with the new test file and the two .cpp files of main, all six restricted_undefined_symbols_* partitions fail, and CUSA09558 exits 2 with Undefined non-weak symbol has non-default visibility: f1zwJ3jAI2k at 0/47.
  • ctest --test-dir build -j8: 814 of 815 pass, including all six restricted_undefined_symbols_* partitions. The one failure, vulkan_validation_gate_commands, is os.symlink failing with WinError 1314 (no symlink privilege on this Windows account) in tools/tests/test_vulkan_validation_gate.py and is unrelated.
  • CUSA09558 in a scratch copy of the dump: relinker --windows --registry --module-dir Media/Modules --module-dir Media/Plugins app0/eboot.bin kip1.exe exits 0 with PRX conversion 100% (47/47) and writes kip1.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 of test_restricted_undefined_symbols.py (the ERROR constant 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 with main. Checked by hand: #11525's RelinkerPipeline.cpp hunks are in the unwind/data-table code after extractRela, #15900 adds two page-size constants to ElfConstants.hpp away from the STB_* lines, and #15903 conflicts with this branch only in docs/dev/debt/relinker.md, as it does with main.

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: CUSA09558 (relinking stops at Il2CppUserAssemblies.prx)
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5210497073 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17105). Originally posted by [ntamas94](https://github.com/ntamas94) on 2026-11-08T10:17:05Z. --- ### What Since #11925 the relinker refuses any relocation against an undefined, non-weak symbol whose `st_other` visibility is `STV_INTERNAL`, `STV_HIDDEN` or `STV_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) ships `Media/Modules/Il2CppUserAssemblies.prx` with a `R_X86_64_JUMP_SLOT` against `f1zwJ3jAI2k#J#C` (`_Unwind_Resume`, exported by libc): `STB_GLOBAL`, `STT_FUNC`, `STV_PROTECTED`, `st_shndx` 0. On current `main` the conversion stops with `Undefined non-weak symbol has non-default visibility: f1zwJ3jAI2k` and 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_LOCAL` symbol 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 test `STB_LOCAL` instead of "not `STB_WEAK`", and the message reads `Undefined local symbol has non-default visibility: <name>`. `STB_LOCAL` is added next to `STB_GLOBAL` and `STB_WEAK` in `ElfConstants.hpp`. Defined symbols, `R_X86_64_NONE` and 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/Plugins` and `sce_module`. - **Tests.** `test_restricted_undefined_symbols.py` keeps 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 nor `app0`. 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`, on `d333e6d428` (this branch merged with `main` `141cc61132`). The later merge of `main` `429035f99f` only changes an AGC execution test outside the relinker-only build. - Counter-check: with the new test file and the two `.cpp` files of `main`, all six `restricted_undefined_symbols_*` partitions fail, and CUSA09558 exits 2 with `Undefined non-weak symbol has non-default visibility: f1zwJ3jAI2k` at `0/47`. - `ctest --test-dir build -j8`: 814 of 815 pass, including all six `restricted_undefined_symbols_*` partitions. The one failure, `vulkan_validation_gate_commands`, is `os.symlink` failing with `WinError 1314` (no symlink privilege on this Windows account) in `tools/tests/test_vulkan_validation_gate.py` and is unrelated. - CUSA09558 in a scratch copy of the dump: `relinker --windows --registry --module-dir Media/Modules --module-dir Media/Plugins app0/eboot.bin kip1.exe` exits 0 with `PRX conversion 100% (47/47)` and writes `kip1.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 of `test_restricted_undefined_symbols.py` (the `ERROR` constant 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 with `main`. Checked by hand: #11525's `RelinkerPipeline.cpp` hunks are in the unwind/data-table code after `extractRela`, #15900 adds two page-size constants to `ElfConstants.hpp` away from the `STB_*` lines, and #15903 conflicts with this branch only in `docs/dev/debt/relinker.md`, as it does with `main`. ### 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: none - [x] Fixes: none - [x] Unblocks: CUSA09558 (relinking stops at `Il2CppUserAssemblies.prx`) - [x] GPUs tested: n/a - [x] AI-assisted: yes
gabichuuuuu commented 2026-11-08 10:53:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T10:53:01Z.

Review: COMMENTED


Windows check of head cf3673c3ac, merged onto main 49f3653632 (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.

  • The six restricted_undefined_symbols_* tests and 22 other import tests (-R 'restricted_undefined|guest_unused_import|needed_libraries|import', 28 tests) all pass.
  • Negative control, with main's GuestImageReader.cpp and RelinkerPipeline.cpp and this PR's test: 0 / 6. Each one stops on the first global case, for example 7-linux-False-visibility-1, with Undefined 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_HIDDEN or STV_INTERNAL on the import, glibc's ld.so would 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 for linux and pie, with relocation types 1, 6 and 7, visibilities 0 to 3, and global and weak binding: 48 outputs. I then read symbol in each output's .dynsym. Every one has st_other 0 and st_shndx UND, with its binding kept. SysVDynamicSectionBuilder writes STV_DEFAULT for every import (lines 151 and 161), so the source visibility doesn't reach ld.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 in GuestImageReader and GuestModuleBuilder only look at visibility on defined symbols.

I haven't run a converted title, on Linux or Windows.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5817596237 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17105#pullrequestreview-5817596237). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-08T10:53:01Z. **Review:** COMMENTED --- Windows check of head `cf3673c3ac`, merged onto `main` `49f3653632` (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`. - The six `restricted_undefined_symbols_*` tests and 22 other import tests (`-R 'restricted_undefined|guest_unused_import|needed_libraries|import'`, 28 tests) all pass. - **Negative control**, with `main`'s `GuestImageReader.cpp` and `RelinkerPipeline.cpp` and this PR's test: 0 / 6. Each one stops on the first global case, for example `7-linux-False-visibility-1`, with `Undefined 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_HIDDEN` or `STV_INTERNAL` on the import, glibc's `ld.so` would 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 for `linux` and `pie`, with relocation types 1, 6 and 7, visibilities 0 to 3, and global and weak binding: 48 outputs. I then read `symbol` in each output's `.dynsym`. Every one has `st_other` 0 and `st_shndx` `UND`, with its binding kept. `SysVDynamicSectionBuilder` writes `STV_DEFAULT` for every import (lines 151 and 161), so the source visibility doesn't reach `ld.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 in `GuestImageReader` and `GuestModuleBuilder` only look at visibility on defined symbols. I haven't run a converted title, on Linux or Windows.
MarcZX10 commented 2026-11-21 12:03:29 +00:00 (Migrated from github.com)

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.py was not invoked; the pinned repository reader tools were used.

Results

Check Result Note
Changed code review passed Four changed files read
Test registration passed Updated test remains registered
Build and tests not run Author-reported results are not independently verified

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.json was 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6005067620 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17105#pullrequestreview-6005067620). Originally posted by [MarcZX10](https://github.com/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.py` was not invoked; the pinned repository reader tools were used. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | Four changed files read | | Test registration | passed | Updated test remains registered | | Build and tests | not run | Author-reported results are not independently verified | ## 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.json` was 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.
MarcZX10 commented 2026-11-22 10:11:06 +00:00 (Migrated from github.com)

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; base main is 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

Check Result Note
Changed code review passed Four changed files read
Automated checks not run No tests or build run

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6011637925 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17105#pullrequestreview-6011637925). Originally posted by [MarcZX10](https://github.com/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`; base `main` is 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 | Check | Result | Note | |---|---|---| | Changed code review | passed | Four changed files read | | Automated checks | not run | No tests or build run | ## 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.
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!17105
No description provided.