fix(relinker): keep weak undefined imports weak #4510
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4510"
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 simonbronk on 2026-10-12T13:50:35Z.
What
Fixes #4497.
Weak undefined imports (
STB_WEAK, section 0) in the input ELF were written to the relinked.dynsymasSTB_GLOBAL, so a title that weak-imports a function no module exports stopped at startup instead of binding the import to null.NidReferencerecords whether the source symbol was weak;SysVDynamicSectionBuilderwritesSTB_WEAKfor those imports instead ofSTB_GLOBAL. On Linux,ld.sothen binds a missing weak import to 0.WindowsRelocationBuilderreads the binding intoPeImport::Weak. When no searched module exports a weak import, the startup stub writes 0 plus the addend to its slot and continues; it does not printunresolved ELF importor install a lazy stub. A weak import that is exported resolves as before.Guest module imports (
LinuxGuestModuleWriter,WindowsGuestModuleWriter) are not touched.Tested
macOS 27 (Apple Silicon, AppleClang 21), relinker-only build, Release:
ctest --test-dir build-relinker: 125/125 passed, including the newweak_imports.weak_importsbuilds an executable with one weakGLOB_DATimport whose code returns 33 when the slot is null and calls through it otherwise:STB_WEAK, and a non-weak import is stillSTB_GLOBAL. Without the fix the test fails with{'absent': 1}.a.prx). I could not run the Windows executables; this part needs Windows CI.python3 tools/check_conventions.py --base origin/main: passed.Porpoise itself not tested (no dump).
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-12T14:33:57Z.
Overlaps with #4452 on the same lines in
SysVDynamicSectionBuilder.cppandRelinkerPipeline.cpp, but the changes are independent and compatible (#4452 handles all-zero symbol entries, this one keepsSTB_WEAKfrom named symbols). Happy to rebase onto #4452 if it lands first.The
CMakeLists.txtoverlap with #4062 is resolved: the test registration moved next toelf_header.Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-12T21:41:04Z.
@gabichuuuuu thanks for running it on Windows.
#4452 is merged, so I merged
maininto this branch:symbolInfofrom #4452 is kept (all-zero entries staySTB_WEAK | STT_NOTYPE) and named imports now takeSTB_WEAKorSTB_GLOBALfrom the source symbol. Relinker-only build on macOS: 134/134 tests pass; conventions check passes.On the review note: agreed, the 16/17 loads are unreachable in the weak branch because only executable imports set
Weak, so I left it as is.