fix(relinker): validate visibility of undefined strong symbols #11925

Merged
Mherberts merged 1 commit from upstream-pr/11925 into main 2026-10-28 09:53:22 +00:00
Mherberts commented 2026-10-27 12:44:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mherberts on 2026-10-27T12:44:09Z.


What

A referenced undefined non-weak symbol with STV_INTERNAL, STV_HIDDEN or STV_PROTECTED visibility currently becomes an ordinary external import. Both the executable pipeline and guest-module reader accept this input, so conversion can silently discard the reference's local-definition requirement.

Reject those relocation references before import filtering, provider selection or output generation, and report the symbol name. The executable diagnostic also identifies its symbol-table offset; guest errors identify the module path. Defined hidden symbols, ordinary global/weak imports and unreferenced symbol entries remain accepted. R_X86_64_NONE remains ignored.

The rule comes from gABI section 5.4, Symbol Visibility: a non-default-visibility reference must have a definition in the same component; the unresolved exception requires weak binding. This change validates non-weak references and preserves the existing weak-reference handling.

Tested

Windows x64, GCC 15.2.0 / MinGW-w64, C++20 Release, Ninja, Python 3.13; ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON. Tested head: 3ab97351f22008c75d12c79d2086464ab8eeba5c, based on current main 62b3ba2522b38543b50cbc4b7093c9ab8fdfb5df.

  • Negative control: before changing production code, built the tests on eece5da035096f4a6fd936c3dfacf667f474f3af. Both new tests fail: the internal undefined function reference converts successfully instead of being refused, for an executable and for a bundled module. No relinker source changed between that base and the final refreshed base.
  • Complete relinker-only build passed. All 22 focused CTests passed on the final head (64.61 s): none_relocations, guest_none_relocations, guest_relative_section_symbols, guest_own_tls_relocations, linux_executable_exports, executable_tls_relocations, executable_export_bounds, guest_tls_export_references, guest_symbol_names, import_symbol_types, guest_registry, guest_absolute_symbols, guest_export_lookup, weak_imports, windows_guest_weak_imports, null_symbol_relocations, both restricted_undefined_symbols_* tests, call_registry, macos_guest_weak_exports, macos_executable_exports, macos_guest_weak_imports.
  • The new tests check 240 conversions/rejections (96 executable, 144 guest): absolute/GOT/PLT relocations; internal/hidden/protected global references and local hidden references; Linux fixed-address and PIE executables, Windows PE and macOS Mach-O; standard and SCE guest dynamic tags. Controls cover default global and weak imports, ignored/unreferenced entries and defined hidden guest symbols. A filtered executable is still rejected before filtering. Rejections leave input bytes unchanged and create neither an output executable nor app0.
  • Test-registration audit passed: all 39 native test executables are registered; all 203 Python test scripts have a CTest/workflow entry. git diff --check passed. Both new CTests have a 20-second timeout.
  • Required python tools/check_conventions.py --base origin/main: 0 errors, 41 warnings in already-merged upstream debt entries because the fork's main is older. The check against actual upstream/main passed without findings.
  • Ran the repository's tools/pr_overlap.py --branch codex/fix-unresolved-restricted-symbols through a local public-API adapter because GitHub CLI is unavailable. The refreshed inventory contains 1,271 open PRs; 37 share changed files and none was reported as an overlapping implementation. Manually inspected the base-conflicting shared changes in #5021 and #6713 (CMakeLists.txt) and #10861 (CMakeLists.txt, RelinkerPipeline.cpp): those change other test registrations and syscall/code-extent analysis, leaving this relocation-symbol validation and its test registration unchanged.

This is focused native/synthetic-fixture validation on Windows, not the full product suite. Linux and macOS outputs were generated on Windows; no native Linux/macOS execution or commercial title was run. No performance claim.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5034101907 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11925). Originally posted by [Mherberts](https://github.com/Mherberts) on 2026-10-27T12:44:09Z. --- ### What A referenced undefined non-weak symbol with `STV_INTERNAL`, `STV_HIDDEN` or `STV_PROTECTED` visibility currently becomes an ordinary external import. Both the executable pipeline and guest-module reader accept this input, so conversion can silently discard the reference's local-definition requirement. Reject those relocation references before import filtering, provider selection or output generation, and report the symbol name. The executable diagnostic also identifies its symbol-table offset; guest errors identify the module path. Defined hidden symbols, ordinary global/weak imports and unreferenced symbol entries remain accepted. `R_X86_64_NONE` remains ignored. The rule comes from [gABI section 5.4, Symbol Visibility](https://gabi.xinuos.com/elf/05-symtab.html#symbol-visibility): a non-default-visibility reference must have a definition in the same component; the unresolved exception requires weak binding. This change validates non-weak references and preserves the existing weak-reference handling. ### 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 x64, GCC 15.2.0 / MinGW-w64, C++20 Release, Ninja, Python 3.13; `ANYPS5_RELINKER_ONLY=ON`, `BUILD_TESTING=ON`. Tested head: `3ab97351f22008c75d12c79d2086464ab8eeba5c`, based on current `main` `62b3ba2522b38543b50cbc4b7093c9ab8fdfb5df`. - **Negative control:** before changing production code, built the tests on `eece5da035096f4a6fd936c3dfacf667f474f3af`. Both new tests fail: the internal undefined function reference converts successfully instead of being refused, for an executable and for a bundled module. No relinker source changed between that base and the final refreshed base. - **Complete relinker-only build passed. All 22 focused CTests passed** on the final head (64.61 s): `none_relocations`, `guest_none_relocations`, `guest_relative_section_symbols`, `guest_own_tls_relocations`, `linux_executable_exports`, `executable_tls_relocations`, `executable_export_bounds`, `guest_tls_export_references`, `guest_symbol_names`, `import_symbol_types`, `guest_registry`, `guest_absolute_symbols`, `guest_export_lookup`, `weak_imports`, `windows_guest_weak_imports`, `null_symbol_relocations`, both `restricted_undefined_symbols_*` tests, `call_registry`, `macos_guest_weak_exports`, `macos_executable_exports`, `macos_guest_weak_imports`. - The new tests check **240 conversions/rejections** (96 executable, 144 guest): absolute/GOT/PLT relocations; internal/hidden/protected global references and local hidden references; Linux fixed-address and PIE executables, Windows PE and macOS Mach-O; standard and SCE guest dynamic tags. Controls cover default global and weak imports, ignored/unreferenced entries and defined hidden guest symbols. A filtered executable is still rejected before filtering. Rejections leave input bytes unchanged and create neither an output executable nor `app0`. - Test-registration audit passed: all 39 native test executables are registered; all 203 Python test scripts have a CTest/workflow entry. `git diff --check` passed. Both new CTests have a 20-second timeout. - Required `python tools/check_conventions.py --base origin/main`: 0 errors, 41 warnings in already-merged upstream debt entries because the fork's `main` is older. The check against actual `upstream/main` passed without findings. - Ran the repository's `tools/pr_overlap.py --branch codex/fix-unresolved-restricted-symbols` through a local public-API adapter because GitHub CLI is unavailable. The refreshed inventory contains 1,271 open PRs; 37 share changed files and none was reported as an overlapping implementation. Manually inspected the base-conflicting shared changes in #5021 and #6713 (`CMakeLists.txt`) and #10861 (`CMakeLists.txt`, `RelinkerPipeline.cpp`): those change other test registrations and syscall/code-extent analysis, leaving this relocation-symbol validation and its test registration unchanged. This is focused native/synthetic-fixture validation on Windows, not the full product suite. Linux and macOS outputs were generated on Windows; no native Linux/macOS execution or commercial title was run. No performance claim. ### 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
rooklz commented 2026-10-27 12:51:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-27T12:51:24Z.

Review: APPROVED


Verified on macOS (arm64, AppleClang Release, ANYPS5_RELINKER_ONLY=ON, Python 3.13) — this covers the macOS lane you couldn't run:

Code parity audit (both lanes)

  • Executable: the check sits in the extractRela lambda, i.e. it fires only for relocation-referenced symbols, and before nidRefs.push_back — so rejection precedes import collection, the unused-NID filter and provider selection (the -filtered case proves it beats unused-filter=1). Field math checked against the Elf64_Sym layout: st_shndx@+6 == SHN_UNDEF, bind st_info@+4 >> 4 != STB_WEAK, visibility st_other@+5 & 3 != 0. RELATIVE(8) and undefined-TLS paths are handled upstream exactly as the description claims.
  • Guest: GuestSymbol::{Info,Visibility,Section} semantics verified against the parse site (visibility is raw st_other, pre-validated to 2 bits; binds pre-restricted to LOCAL/GLOBAL/WEAK, so != 2 covers local-hidden too — consistent on both sides). The relocation != 8 exemption is load-bearing rather than incidental: a guest RELATIVE entry uses the symbol's value (validated below), not a resolution, so rejecting on it would be wrong.
  • Diagnostics match the surrounding patterns: RelinkerException(msg, symOff) mirrors the neighbouring unnamed-import exception; guest fail() carries the module path.

Red/green reproduced independently

  • Base = upstream/main 62b3ba2522 build + your test file: first case (R_X86_64_64, STV_INTERNAL, GLOBAL) converts with exit 0 on both lanes — the guest output even shows NID input: 0 references, i.e. the reference is silently dropped. Exactly the bug described.
  • Head 3ab97351f2: both new tests pass (96 + 144 = 240 conversions).

macOS lane

  • Full ctest at head: 363/363 (361 baseline + your 2 tests).

Overlap

  • pr_overlap: no implementation overlap; the three uncomparables (#5021/#6713/#10861) share only CMakeLists.txt test registrations, and I verified #10861's RelinkerPipeline.cpp hunks (@25/@409+) are disjoint from your single 4-line hunk @396 — merges alongside cleanly.
  • check_conventions --base upstream/main: PASS.

Non-blocking: the guest-side TLS relocation types (16/17/18) also pass through the new check but aren't in the test matrix (only 1/6/7); pre-existing TLS validation rejects most of those inputs anyway, so this is fine as-is.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5667303587 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11925#pullrequestreview-5667303587). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-27T12:51:24Z. **Review:** APPROVED --- Verified on macOS (arm64, AppleClang Release, `ANYPS5_RELINKER_ONLY=ON`, Python 3.13) — this covers the macOS lane you couldn't run: **Code parity audit (both lanes)** - Executable: the check sits in the `extractRela` lambda, i.e. it fires only for relocation-*referenced* symbols, and before `nidRefs.push_back` — so rejection precedes import collection, the unused-NID filter and provider selection (the `-filtered` case proves it beats `unused-filter=1`). Field math checked against the Elf64_Sym layout: `st_shndx@+6 == SHN_UNDEF`, bind `st_info@+4 >> 4 != STB_WEAK`, visibility `st_other@+5 & 3 != 0`. RELATIVE(8) and undefined-TLS paths are handled upstream exactly as the description claims. - Guest: `GuestSymbol::{Info,Visibility,Section}` semantics verified against the parse site (visibility is raw `st_other`, pre-validated to 2 bits; binds pre-restricted to LOCAL/GLOBAL/WEAK, so `!= 2` covers local-hidden too — consistent on both sides). The `relocation != 8` exemption is load-bearing rather than incidental: a guest RELATIVE entry uses the symbol's *value* (validated below), not a resolution, so rejecting on it would be wrong. - Diagnostics match the surrounding patterns: `RelinkerException(msg, symOff)` mirrors the neighbouring unnamed-import exception; guest `fail()` carries the module path. **Red/green reproduced independently** - Base = upstream/main `62b3ba2522` build + your test file: first case (`R_X86_64_64`, STV_INTERNAL, GLOBAL) **converts with exit 0** on both lanes — the guest output even shows `NID input: 0 references`, i.e. the reference is silently dropped. Exactly the bug described. - Head `3ab97351f2`: both new tests pass (96 + 144 = 240 conversions). **macOS lane** - Full ctest at head: **363/363** (361 baseline + your 2 tests). **Overlap** - `pr_overlap`: no implementation overlap; the three uncomparables (#5021/#6713/#10861) share only `CMakeLists.txt` test registrations, and I verified #10861's `RelinkerPipeline.cpp` hunks (@25/@409+) are disjoint from your single 4-line hunk @396 — merges alongside cleanly. - `check_conventions --base upstream/main`: PASS. Non-blocking: the guest-side TLS relocation types (16/17/18) also pass through the new check but aren't in the test matrix (only 1/6/7); pre-existing TLS validation rejects most of those inputs anyway, so this is fine as-is.
MarcZX10 commented 2026-10-27 12:54:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T12:54:02Z.

Review: COMMENTED


I reviewed both validation paths and the synthetic fixtures. RelinkerPipeline checks referenced non-weak undefined executable symbols; GuestImageReader applies the same visibility rule to guest-module relocations, while R_X86_64_RELATIVE is separately handled. The tests cover hidden/internal/protected visibility, weak/default/defined/unreferenced controls, and Linux/PIE/Windows/macOS conversion modes. Ubuntu, Windows, ASan, conventions, intake, eligibility and labels pass; both macOS relinker jobs were still pending. I will revisit after those complete.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5667336263 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11925#pullrequestreview-5667336263). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-27T12:54:02Z. **Review:** COMMENTED --- I reviewed both validation paths and the synthetic fixtures. RelinkerPipeline checks referenced non-weak undefined executable symbols; GuestImageReader applies the same visibility rule to guest-module relocations, while R_X86_64_RELATIVE is separately handled. The tests cover hidden/internal/protected visibility, weak/default/defined/unreferenced controls, and Linux/PIE/Windows/macOS conversion modes. Ubuntu, Windows, ASan, conventions, intake, eligibility and labels pass; both macOS relinker jobs were still pending. I will revisit after those complete.
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!11925
No description provided.