Skip to content

fix(relinker): accept untyped guest exports for typed imports - #2173

Open
Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/28417
Open

Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/28417

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#28417, originally opened by cjt42554-crypto.

Source commit: cb2cd0d1b56bb3a74eba6a94faa5509e8b3591f5. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


What

A guest module importing a function or object from another bundled module fails conversion with Guest import/export type mismatch when the provider uses STT_NOTYPE. The executable-to-guest path already accepts this pairing; the guest-to-guest path rejects it before output is emitted.

Align the guest-to-guest type predicate with the existing executable path. STT_NOTYPE is an unspecified ordinary type (ELF gABI section 5.3); TLS imports still require a TLS export, explicitly incompatible types still fail, and the existing non-TLS relocation guard is preserved.

Extend three existing fixture suites. The Linux execution cases select b.prx (value 22) while a competing a.prx exports the same name (value 11), covering both a function call and an object read through real relocations. The conversion cases cover FUNC/OBJECT imports from NOTYPE exports, and a new TLS negative case protects the exception.

No title-specific behavior, new dependency, or game-unblock claim.

Tested

Linux x86_64, GCC 14.2.0, CMake 3.31.6, Python 3.12.14, Release, ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON. Tested local commit: bb58bbeb2ae43bdd0fe48f5fe11682207963465a; base: a0e55122cb00db002d693efdd53b101fae86a83c. Published commit: cb2cd0d1b56bb3a74eba6a94faa5509e8b3591f5. The published and tested trees are identical: e1e737b81a37dd279617ae316f11e4fdc9bf2ae3.

  • Before the fix: the four existing related suites pass on 7cca3db6e867943c676b217391f1bbc6bc43b170. With the new tests and unchanged production code, linux_guest_qualified_imports and guest_export_lookup fail with the expected import/export type mismatch. The added TLS negative case passes. The relinker source is unchanged between this RED baseline and the final base.
  • After the fix: all four focused suites pass. Linux function and object cases execute natively; Linux/Windows conversion cases pass. The TLS negative case rejects Linux, Windows and macOS output and writes no artifacts. No native Windows/macOS execution or commercial-title run was performed.
  • Final full relinker-only run: 1148/1148 passed, 0 failed, 61.36 seconds, ctest --test-dir build-relinker --parallel 6 --output-on-failure.
  • python3 tools/check_conventions.py and git diff --check pass. Rebase range-diff confirms the patch is unchanged.
  • An earlier full run had 8 environment failures because Ninja was missing and a subprocess could not find ctest. Installing Ninja and putting both tools on PATH resolved these in the final complete rerun; no tests were disabled or altered for this.

Overlap-check limitation: python3 tools/pr_overlap.py --branch fix/relinker-untyped-guest-exports --repo boykopovar/AnyPS5 --base main was attempted but could not query PRs because this environment's gh is not authenticated. The 15 open PRs returned for GuestModuleBuilder, plus the additional NOTYPE search hit boykopovar#27825, were inspected manually, with no duplicate of this fix found. boykopovar#21877 and boykopovar#27866 touch nearby provider-selection code while preserving the old type condition; boykopovar#28282 adds guest-to-executable binding, and boykopovar#28178 handles executable TLS imports. The extra trace-imports PR boykopovar#27825 touches none of these four files. This is a manual duplicate check, not an exhaustive automated overlap pass or a merge-composition test.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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

Summary by CodeRabbit

  • Bug Fixes
    • Untyped exports can now be used by function and object imports. TLS imports can also bind to untyped exports, while incompatible non-TLS references remain rejected.
  • Tests
    • Expanded coverage for untyped export compatibility, including qualified imports and TLS mismatch handling.

Match the executable import type rule for guest-to-guest bindings and add conversion, native Linux, and TLS rejection regressions.
@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Guest type matching

Layer / File(s) Summary
Type matching and validation
core/relinker/relinker/src/guest/GuestModuleBuilder.cpp, core/relinker/relinker/tests/test_guest_export_lookup.py, core/relinker/relinker/tests/test_guest_tls_export_references.py, core/relinker/relinker/tests/test_linux_guest_qualified_imports.py
Type-0 imports can match any export type. Nonzero imports must match the export type, except that a type-0 export accepts type-6 imports. Tests cover untyped exports in lookup and qualified imports, and verify a type-mismatch error for a TLS consumer importing a type-0 export. The existing rejection of referenced non-TLS imports against TLS exports is unchanged.

Suggested reviewers: dripl1x, roboterspinne, nikhilpanchal1

Change: Bug fix

Merge Risk: Minimal · up to cb2cd

Guest modules can now link against bundled exports that have no declared symbol type, matching the existing executable-to-guest behavior. Explicitly mismatched types and TLS requirements are still rejected, and the tests cover these cases. I found no merge-blocking risk.

Security architecture risk: Minimal · up to cb2cd

The Relinker now accepts untyped guest exports for typed non-TLS imports without changing which module supplies the symbol. TLS imports still require a TLS export, and conflicting explicit types still fail.

Security review details

Security Blast Radius

  • inferred — The added acceptance is scoped to guest-to-guest bindings within a Relinker conversion. It can allow the selected guest provider and its dependencies to be included in generated artifacts, but does not change how an import is routed to a host library.

Trust Boundaries and Controls

  • observed — Guest-controlled symbol names and library qualifiers go through provider selection and ambiguity checks before the changed type predicate. Export eligibility is filtered when the provider table is built. After a type match, referenced exports still pass the existing check that rejects Linux exports the loader would skip.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 4
  • Waived: $1.00 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f7850216-5e45-4283-b498-830f519c2b21
Commits

Reviewing files that changed from the base of the PR and between 4131f51 and cb2cd0d.

Files selected for processing: 4

  • core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
  • core/relinker/relinker/tests/test_guest_export_lookup.py
  • core/relinker/relinker/tests/test_guest_tls_export_references.py
  • core/relinker/relinker/tests/test_linux_guest_qualified_imports.py

@github-actions github-actions Bot added the relinker core/relinker label Dec 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

relinker core/relinker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants