fix(relinker): preserve weak imports in Linux guest modules #6080

Merged
Zinebyte merged 1 commit from upstream-pr/6080 into main 2026-10-17 04:53:43 +00:00
Zinebyte commented 2026-10-14 21:27:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Zinebyte on 2026-10-14T21:27:16Z.


What

Linux guest-module conversion changes undefined STB_WEAK symbols to STB_GLOBAL. A module that checks an optional import for null can load before conversion, then fail at startup after conversion because the loader treats that import as required.

Keep the source symbol binding by removing the promotion in LinuxGuestModuleWriter. Available weak imports still resolve to their providers; missing strong imports and required libraries still fail. This follows the executable behavior merged in #4510, which left guest modules for separate work. The ELF symbol-binding specification describes unresolved weak symbols having a zero value; native Linux loader behavior is measured below.

Tested

Zorin OS 18.1 x86-64, Python 3.12.3, GCC 13.3.0, CMake 3.28.3. Synthetic page-aligned x86-64 ELF fixtures with declared host-module ownership and a required host import; no title files or title-unblocking claim.

  • Final branch based on 4808d9c2032129eaf9dc31015e7c8cfbffde7a5c, head 875a159f6467618385e0ec2ac97646863c332856. Relevant relinker, CMake and tool sources are unchanged between the tested base 0ae1deb85 and this upstream rebase.
  • Baseline fa539dd9bafa17005c7d890117499c208effb8d2: the original missing-weak module loads and its null-guarded function returns 42. Conversion succeeds, but the converted module fails dlopen with an undefined-symbol error. A present weak provider returns 77; missing required/global imports remain loader errors.
  • The regression checks Linux output weak/global bindings on every host and compares original and converted modules in fresh native Linux x86-64 loader subprocesses. Native host fixtures are encoded as ELF bytes, so the test needs no additional compiler or dependency.
  • Release relinker-only build and all 172 configured CTests pass in 11.33 s. The expanded weak_imports CTest passes in 0.29 s; the exact new regression fails against the saved original binary. Missing required host-library refusal is also exercised. Existing assertions remain intact. Conventions and whitespace checks pass.
  • Independent review reproduced the failure and showed that restoring only the converted symbol's weak binding makes the same module load and execute its null guard. No stub or fallback is added.
  • Checked the complete changed-file lists of 450 open PRs. #5981 changes DT_FLAGS and #5614 changes finalizer arguments in the same writer; neither changes this binding. #5473's weak-import tests concern macOS executables and are already on current main.
  • The repository's overlap checker reports no conflict with the exact heads of #5981, #5614 or #5473, with all dependency lists empty.

Hosted relinker CI passed on Linux, Windows and macOS at head 875a159f6467618385e0ec2ac97646863c332856, including the expanded weak_imports test on each platform. Eligibility, intake and conventions also passed. Full runtime-library jobs were skipped by the repository's PR policy.

Manual review of the partial-overlap notice against main fa9365ca74: #6112 changes preinit handling, and its Linux writer composes with this PR's weak-binding preservation. It introduces no additional conflict; the peer's existing base conflicts remain unchanged.

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; no silent stubs or fallback implementations added
  • No notes, investigation files or images added to the repository
  • No third-party code or dependencies added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes, OpenAI Codex; implementation, tests, independent review and description
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4864773306 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6080). Originally posted by [Zinebyte](https://github.com/Zinebyte) on 2026-10-14T21:27:16Z. --- ### What Linux guest-module conversion changes undefined `STB_WEAK` symbols to `STB_GLOBAL`. A module that checks an optional import for null can load before conversion, then fail at startup after conversion because the loader treats that import as required. Keep the source symbol binding by removing the promotion in `LinuxGuestModuleWriter`. Available weak imports still resolve to their providers; missing strong imports and required libraries still fail. This follows the executable behavior merged in #4510, which left guest modules for separate work. The [ELF symbol-binding specification](https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.symtab.html) describes unresolved weak symbols having a zero value; native Linux loader behavior is measured below. ### Tested Zorin OS 18.1 x86-64, Python 3.12.3, GCC 13.3.0, CMake 3.28.3. Synthetic page-aligned x86-64 ELF fixtures with declared host-module ownership and a required host import; no title files or title-unblocking claim. - Final branch based on `4808d9c2032129eaf9dc31015e7c8cfbffde7a5c`, head `875a159f6467618385e0ec2ac97646863c332856`. Relevant relinker, CMake and tool sources are unchanged between the tested base `0ae1deb85` and this upstream rebase. - Baseline `fa539dd9bafa17005c7d890117499c208effb8d2`: the original missing-weak module loads and its null-guarded function returns 42. Conversion succeeds, but the converted module fails `dlopen` with an undefined-symbol error. A present weak provider returns 77; missing required/global imports remain loader errors. - The regression checks Linux output weak/global bindings on every host and compares original and converted modules in fresh native Linux x86-64 loader subprocesses. Native host fixtures are encoded as ELF bytes, so the test needs no additional compiler or dependency. - Release relinker-only build and all 172 configured CTests pass in 11.33 s. The expanded `weak_imports` CTest passes in 0.29 s; the exact new regression fails against the saved original binary. Missing required host-library refusal is also exercised. Existing assertions remain intact. Conventions and whitespace checks pass. - Independent review reproduced the failure and showed that restoring only the converted symbol's weak binding makes the same module load and execute its null guard. No stub or fallback is added. - Checked the complete changed-file lists of 450 open PRs. #5981 changes `DT_FLAGS` and #5614 changes finalizer arguments in the same writer; neither changes this binding. #5473's weak-import tests concern macOS executables and are already on current `main`. - The repository's overlap checker reports no conflict with the exact heads of #5981, #5614 or #5473, with all dependency lists empty. [Hosted relinker CI](https://github.com/boykopovar/AnyPS5/actions/runs/38640458877) passed on Linux, Windows and macOS at head `875a159f6467618385e0ec2ac97646863c332856`, including the expanded `weak_imports` test on each platform. Eligibility, intake and conventions also passed. Full runtime-library jobs were skipped by the repository's PR policy. Manual review of the partial-overlap notice against main `fa9365ca74`: #6112 changes preinit handling, and its Linux writer composes with this PR's weak-binding preservation. It introduces no additional conflict; the peer's existing base conflicts remain unchanged. ### Checklist - [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 - [x] Unimplemented paths throw; no silent stubs or fallback implementations added - [x] No notes, investigation files or images added to the repository - [x] No third-party code or dependencies added - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes, OpenAI Codex; implementation, tests, independent review and description
adriadam10 commented 2026-10-16 22:15:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T22:15:08Z.


Checked the one-line change in LinuxGuestModuleWriter.cpp and the expanded weak_imports test: relinker-scope build and ctest pass (136/136), and reverting only the writer change makes weak_imports fail, so the test pins the fix. Relinker CI is green on Linux, Windows and macOS; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6225728499 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6080#issuecomment-6225728499). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-16T22:15:08Z. --- Checked the one-line change in `LinuxGuestModuleWriter.cpp` and the expanded `weak_imports` test: relinker-scope build and ctest pass (136/136), and reverting only the writer change makes `weak_imports` fail, so the test pins the fix. Relinker CI is green on Linux, Windows and macOS; merging.
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!6080
No description provided.