fix(relinker): preserve weak imports #4624
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4624"
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 kallmek3nny on 2026-10-12T17:02:16Z.
What
Fixes #4497.
Preserve weak undefined imports through relinking instead of promoting them to required global imports:
STB_WEAKbinding throughNidReferenceand emit weak undefined symbols in the rebuilt SysV dynamic symbol table, so a missing weak import can bind to zero on LinuxThis is generic weak-symbol behavior rather than a
chrootspecial case. Porpoise (PPSA99764) is the motivating title from #4497.Tested
Ubuntu 24.04, GCC 13.3.0, Release relinker-only build on current
main(2a5eca11cd1bf583db39ce67034e8453842ac244):python3 tools/check_conventions.py --base upstream/mainpassedgit diff --check upstream/main...HEADpassedstrict_nid_filterandwindows_import_modulesThe Windows fixture conversion path is covered by the Linux run, but native Windows execution was not run in this validation.
Checklist
main; no open PR found implementing the same weak-import behavior.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-12T21:48:53Z.
Checked this with Porpoise (PPSA99764, the title from #4497) on both systems. It conflicts with
mainnow, so I merged it locally ontomain559979dc(fork branchtest/verify-weak, ed42b152). InSysVDynamicSectionBuilder.cpp,mainnow builds the binding in asymbolInfo(ref)helper (from #4452), so I kept that and gave it yourref.Weakcheck. InRelinkerPipeline.cppI keptmain's null-symbol check and addedweakto thepush_back.main559979dc:undefined symbol: AKknh8Cx-V8 (chroot)on Linux,FAIL: unresolved ELF import AKknh8Cx-V8 (chroot) from libkernel_sys.prxon Windows.chroot,fchdirandmalloc_usable_sizeleft unresolved. On Windows the stub writes0 + addendfor the unresolved weak slot. Porpoise starts (Porpoise: main() entered) and runs to its HEN loop (jailbreak: /data isn't reachable (uid 0); asking the HEN, then polling ports 9028/9069 and the/download0jailbreak files). That's the same place it reached whenchrootwas a real export; what remains there is #4643.windows_import_modulespasses 5/5 on Windows;windows_import_modulesandstrict_nid_filterpass on Linux. No new warnings in the PR's files on Windows; the only warnings in that rebuild are the existingstl_construct.hones fromWindowsTlsBuilder.cpp, recompiled becauseWindowsPeFormat.hppchanged.Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-12T22:29:02Z.
FYI: #4510 (keep weak undefined imports weak) merged at 22:17 and closed #4497. On
main43e3a70f, Porpoise (PPSA99764) already gets past its weakchrootimport on Linux and reaches the same HEN loop as with this PR, so this one now overlaps #4510.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:46:55Z.
Closing as a duplicate: #4510 (merged 2026-10-12) already preserves weak undefined imports with the same approach (
NidReference/PeImportweak flag,STB_WEAKin the rebuilt.dynsym, Windows startup stub writing 0 plus addend for a missing weak import) and closed #4497. This PR touches the same files, and conflicts withmainnow.If you think a case is left uncovered (for example the
symOffbounds check inRelinkerPipeline.cpp, or a test of the Windows missing-weak path), feel free to open a new small PR on top of currentmainwith just that.Pull request closed