fix(relinker): validate visibility of undefined strong symbols #11925
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11925"
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 Mherberts on 2026-10-27T12:44:09Z.
What
A referenced undefined non-weak symbol with
STV_INTERNAL,STV_HIDDENorSTV_PROTECTEDvisibility 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_NONEremains 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 currentmain62b3ba2522b38543b50cbc4b7093c9ab8fdfb5df.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.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, bothrestricted_undefined_symbols_*tests,call_registry,macos_guest_weak_exports,macos_executable_exports,macos_guest_weak_imports.app0.git diff --checkpassed. Both new CTests have a 20-second timeout.python tools/check_conventions.py --base origin/main: 0 errors, 41 warnings in already-merged upstream debt entries because the fork'smainis older. The check against actualupstream/mainpassed without findings.tools/pr_overlap.py --branch codex/fix-unresolved-restricted-symbolsthrough 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
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 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)
extractRelalambda, i.e. it fires only for relocation-referenced symbols, and beforenidRefs.push_back— so rejection precedes import collection, the unused-NID filter and provider selection (the-filteredcase proves it beatsunused-filter=1). Field math checked against the Elf64_Sym layout:st_shndx@+6 == SHN_UNDEF, bindst_info@+4 >> 4 != STB_WEAK, visibilityst_other@+5 & 3 != 0. RELATIVE(8) and undefined-TLS paths are handled upstream exactly as the description claims.GuestSymbol::{Info,Visibility,Section}semantics verified against the parse site (visibility is rawst_other, pre-validated to 2 bits; binds pre-restricted to LOCAL/GLOBAL/WEAK, so!= 2covers local-hidden too — consistent on both sides). Therelocation != 8exemption 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.RelinkerException(msg, symOff)mirrors the neighbouring unnamed-import exception; guestfail()carries the module path.Red/green reproduced independently
62b3ba2522build + your test file: first case (R_X86_64_64, STV_INTERNAL, GLOBAL) converts with exit 0 on both lanes — the guest output even showsNID input: 0 references, i.e. the reference is silently dropped. Exactly the bug described.3ab97351f2: both new tests pass (96 + 144 = 240 conversions).macOS lane
Overlap
pr_overlap: no implementation overlap; the three uncomparables (#5021/#6713/#10861) share onlyCMakeLists.txttest registrations, and I verified #10861'sRelinkerPipeline.cpphunks (@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.
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.