fix(relinker): reject imports of data exports at address 0 on Linux #24152

Merged
dsandall merged 2 commits from upstream-pr/24152 into main 2026-11-30 03:13:36 +00:00
dsandall commented 2026-11-20 08:10:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by dsandall on 2026-11-20T08:10:23Z.


What

glibc's check_match (elf/dl-lookup.c) skips a defined symbol whose st_value is 0 unless it is SHN_ABS or STT_TLS. The Linux guest-module writer already gives a function export at address 0 a jmp thunk (the ps5-payload-dev SDK links a shared object's code at 0). A data or untyped export at 0 stays at 0, though, so an import of it converted without complaint and then stopped at startup as an undefined symbol.

GuestModuleBuilder now marks every Linux export the host loader cannot see: value 0, not STT_TLS, and not a function the writer thunks (SHN_ABS exports were already left out of the export map). When a relocated import of the executable or of a guest module binds to a marked export, the conversion fails with Guest import <name> in <importer> binds to an export at address 0 in <provider> that the Linux loader skips. An import that no relocation references is not rejected, because the loader never resolves it. Windows and macOS are unchanged.

The debt entry "Guest exports at address 0 on Linux" keeps its text and only its last sentence is cut to the cases that are still not checked: an executable import that names no module and that several guest modules export (the host loader picks the provider), and a module's own relocations against such an export. #23865 changes the same debt entry; whichever merges second folds its fragment, and I will rebase this PR if #23865 lands first.

Tested

Arch Linux x86-64, relinker-only build (-DANYPS5_RELINKER_ONLY=ON, Release), homebrew synthetic ELFs only, no title. test_linux_guest_zero_address_exports.py gains synthetic-ELF cases. For both STT_NOTYPE and STT_OBJECT exports at address 0, an import from a guest module and an import from the executable each fail the conversion with exit code 2, name the import, importer and provider, and write no output. The same import with no relocation still converts. The new cases fail on main (the conversion succeeds) and pass with this change. The existing function-thunk cases and the native run of the thunked function still pass. Full relinker suite: ctest --test-dir build-relinker -j8 passes 1046 of 1046 tests. tools/check_conventions.py --base upstream/main passes, and tools/debt_fold.py --check passes.

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
    • Relinking now reports an error when an executable or guest module references an export that the Linux loader cannot resolve, rather than allowing conversion to produce an unusable result. Unreferenced imports remain unaffected.
  • Documentation
    • Clarified which address-zero export imports may pass conversion but later fail as undefined symbols.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5410021460 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24152). Originally posted by [dsandall](https://github.com/dsandall) on 2026-11-20T08:10:23Z. --- ### What glibc's `check_match` (`elf/dl-lookup.c`) skips a defined symbol whose `st_value` is 0 unless it is `SHN_ABS` or `STT_TLS`. The Linux guest-module writer already gives a function export at address 0 a `jmp` thunk (the ps5-payload-dev SDK links a shared object's code at 0). A data or untyped export at 0 stays at 0, though, so an import of it converted without complaint and then stopped at startup as an undefined symbol. `GuestModuleBuilder` now marks every Linux export the host loader cannot see: value 0, not `STT_TLS`, and not a function the writer thunks (`SHN_ABS` exports were already left out of the export map). When a relocated import of the executable or of a guest module binds to a marked export, the conversion fails with `Guest import <name> in <importer> binds to an export at address 0 in <provider> that the Linux loader skips`. An import that no relocation references is not rejected, because the loader never resolves it. Windows and macOS are unchanged. The debt entry "Guest exports at address 0 on Linux" keeps its text and only its last sentence is cut to the cases that are still not checked: an executable import that names no module and that several guest modules export (the host loader picks the provider), and a module's own relocations against such an export. #23865 changes the same debt entry; whichever merges second folds its fragment, and I will rebase this PR if #23865 lands first. ### 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. --> Arch Linux x86-64, relinker-only build (`-DANYPS5_RELINKER_ONLY=ON`, Release), homebrew synthetic ELFs only, no title. `test_linux_guest_zero_address_exports.py` gains synthetic-ELF cases. For both `STT_NOTYPE` and `STT_OBJECT` exports at address 0, an import from a guest module and an import from the executable each fail the conversion with exit code 2, name the import, importer and provider, and write no output. The same import with no relocation still converts. The new cases fail on `main` (the conversion succeeds) and pass with this change. The existing function-thunk cases and the native run of the thunked function still pass. Full relinker suite: `ctest --test-dir build-relinker -j8` passes 1046 of 1046 tests. `tools/check_conventions.py --base upstream/main` passes, and `tools/debt_fold.py --check` passes. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Relinking now reports an error when an executable or guest module references an export that the Linux loader cannot resolve, rather than allowing conversion to produce an unusable result. Unreferenced imports remain unaffected. * **Documentation** * Clarified which address-zero export imports may pass conversion but later fail as undefined symbols. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
MarcZX10 commented 2026-11-20 08:23:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T08:23:05Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the implementation and its targeted cases appear sound based on the source read.

What I ran

Reviewed head d39019f719dfc5137d47148f026dc74a3824bb2c using the prepared diff and repo_read.py for targeted source context. No build or tests were run during this review; the test results in the PR description are author-reported.

Results

Check Result Note
Diff and source review passed Three changed files read
Build and test suite not run Results supplied by author only

Findings

Blocking

None.

Non-blocking

None.

Not verified

The full relinker suite, Linux execution test, convention check, and debt-fold check were not run in this review. Read: core/relinker/relinker/src/guest/GuestModuleBuilder.cpp, core/relinker/relinker/tests/test_linux_guest_zero_address_exports.py, core/relinker/relinker/src/guest/GuestImageReader.cpp (targeted range), and docs/dev/debt/changes/fix-relinker-addr0-data-import.md. The manifest lists three changed files and all three were read. No exclusions were reported in the available manifest.

To get this to a good state

Nothing is required. The PR description reports successful tests and checks; those results were not independently verified.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5989546740 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24152#pullrequestreview-5989546740). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T08:23:05Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the implementation and its targeted cases appear sound based on the source read. ## What I ran Reviewed head `d39019f719dfc5137d47148f026dc74a3824bb2c` using the prepared diff and `repo_read.py` for targeted source context. No build or tests were run during this review; the test results in the PR description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Diff and source review | passed | Three changed files read | | Build and test suite | not run | Results supplied by author only | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The full relinker suite, Linux execution test, convention check, and debt-fold check were not run in this review. Read: `core/relinker/relinker/src/guest/GuestModuleBuilder.cpp`, `core/relinker/relinker/tests/test_linux_guest_zero_address_exports.py`, `core/relinker/relinker/src/guest/GuestImageReader.cpp` (targeted range), and `docs/dev/debt/changes/fix-relinker-addr0-data-import.md`. The manifest lists three changed files and all three were read. No exclusions were reported in the available manifest. ## To get this to a good state Nothing is required. The PR description reports successful tests and checks; those results were not independently verified.
edglz commented 2026-11-20 21:52:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by edglz on 2026-11-20T21:52:40Z.

Review: APPROVED


Summary

glibc's check_match skips a defined symbol with st_value == 0 unless it is SHN_ABS or STT_TLS, so an import bound to a data or untyped export at 0 converted cleanly and then failed at load time. HostInvisible mirrors that rule minus the functions the writer thunks, and the rejection only fires for relocated imports, so unreferenced imports still convert. The executable path checks both the declared-provider and single-provider cases; the ambiguous multi-provider case is documented as remaining debt.

Verification

Environment: macOS 26, Apple M4 (arm64), Apple clang 21.0.0, CMake relinker-only Release build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON), PR diff applied on current main.

Check Result
Full ctest suite with this PR 947/947 pass
linux_guest_zero_address_exports with the builder change reverted Fails

Not verified: execution of the converted outputs on Linux or Windows; the tests that run them are host-gated.

Notes

If #23865 lands first, the fragment's "two names for it get two jmps at different addresses" no longer holds and should be dropped on rebase, as the description already anticipates.

Verdict

Approved.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5999887117 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24152#pullrequestreview-5999887117). Originally posted by [edglz](https://github.com/edglz) on 2026-11-20T21:52:40Z. **Review:** APPROVED --- ## Summary glibc's `check_match` skips a defined symbol with `st_value == 0` unless it is `SHN_ABS` or `STT_TLS`, so an import bound to a data or untyped export at 0 converted cleanly and then failed at load time. `HostInvisible` mirrors that rule minus the functions the writer thunks, and the rejection only fires for relocated imports, so unreferenced imports still convert. The executable path checks both the declared-provider and single-provider cases; the ambiguous multi-provider case is documented as remaining debt. ## Verification **Environment:** macOS 26, Apple M4 (arm64), Apple clang 21.0.0, CMake relinker-only Release build (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`), PR diff applied on current `main`. | Check | Result | |---|---| | Full ctest suite with this PR | 947/947 pass | | `linux_guest_zero_address_exports` with the builder change reverted | Fails | Not verified: execution of the converted outputs on Linux or Windows; the tests that run them are host-gated. ## Notes If #23865 lands first, the fragment's "two names for it get two `jmp`s at different addresses" no longer holds and should be dropped on rebase, as the description already anticipates. ## Verdict Approved.
MarcZX10 commented 2026-11-30 01:21:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T01:21:39Z.

Review: COMMENTED


Reviewed — no blocking findings

The change at e7124b74d293b71901a89ba233c8360b45016f18 rejects referenced Linux imports that bind to defined guest exports at address zero when the host loader skips them; I found no verified blocking defect.

What I ran

  • Read the prepared description, commits, manifest, diff, both changed source files, and the debt entry at the pinned head.
  • No build or tests run; the test results in the description are author-reported.

Results

Check Result Note
Changed-code review passed Three changed files read
Build and tests not run Author reports 1046 tests passed

Findings

Blocking

None.

Non-blocking

None.

Not verified

  • Build, test suite, and convention checks were not run independently.
  • files.json was not available in the prepared review bundle, so I could not compare the files read against its reviewed list. The manifest lists three changed files, and all three were read.
  • Linux loader behavior and the explicitly deferred ambiguous-provider cases were not independently exercised.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6105882876 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24152#pullrequestreview-6105882876). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-30T01:21:39Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The change at `e7124b74d293b71901a89ba233c8360b45016f18` rejects referenced Linux imports that bind to defined guest exports at address zero when the host loader skips them; I found no verified blocking defect. ## What I ran - Read the prepared description, commits, manifest, diff, both changed source files, and the debt entry at the pinned head. - No build or tests run; the test results in the description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Changed-code review | passed | Three changed files read | | Build and tests | not run | Author reports 1046 tests passed | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified - Build, test suite, and convention checks were not run independently. - `files.json` was not available in the prepared review bundle, so I could not compare the files read against its reviewed list. The manifest lists three changed files, and all three were read. - Linux loader behavior and the explicitly deferred ambiguous-provider cases were not independently exercised. ## To get this to a good state Nothing is required.
coderabbitai[bot] commented 2026-11-30 01:24:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T01:24:00Z.

Review: COMMENTED


Architecture findings (1)

Advisory architecture findings (1)

  • Trivial — A referenced import in a deferred Linux module can now stop the entire conversion. The head checks every supplied guest image before distinguishing startup dependencies from runtime-only modules. The base did not reject this condition during conversion, so an otherwise valid executable could still be emitted and start without the affected module.
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: 1d2d0f8f-d6a2-4c0b-9371-5862f27085a6
Commits

Reviewing files that changed from the base of the PR and between 2608316185 and e7124b74d2.

Files selected for processing: 3

  • core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
  • core/relinker/relinker/tests/test_linux_guest_zero_address_exports.py
  • docs/dev/debt/changes/linux-zero-export-aliases.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6105893968 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24152#pullrequestreview-6105893968). Originally posted by [coderabbitai[bot]](https://github.com/apps/coderabbitai) on 2026-11-30T01:24:00Z. **Review:** COMMENTED --- <!-- coderabbit-ai-generated:v1 --> **Architecture findings (1)** <details> <summary>Advisory architecture findings (1)</summary> <dl> <dd> <br> - **Trivial** — A referenced import in a deferred Linux module can now stop the entire conversion. The head checks every supplied guest image before distinguishing startup dependencies from runtime-only modules. The base did not reject this condition during conversion, so an otherwise valid executable could still be emitted and start without the affected module. </dd> </dl> </details> <h6> <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <br> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</summary> <dl> <dd> <br> - **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**: `1d2d0f8f-d6a2-4c0b-9371-5862f27085a6` </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</summary> <dl> <dd> <br> Reviewing files that changed from the base of the PR and between 26083161852672105e7df6ecc1ac365973f1e45a and e7124b74d293b71901a89ba233c8360b45016f18. </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 3</summary> <dl> <dd> <br> * `core/relinker/relinker/src/guest/GuestModuleBuilder.cpp` * `core/relinker/relinker/tests/test_linux_guest_zero_address_exports.py` * `docs/dev/debt/changes/linux-zero-export-aliases.md` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. </dd> </dl> </details> </h6> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=2c1d9b74-9ab8-4060-ae8d-39bd7f90ac1d attempt=039c3432-1134-4090-8011-464c7d84fa6a batch=1/1 -->
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!24152
No description provided.