Repository navigation
fix(relinker): keep weak undefined imports weak - #4510
Conversation
Weak undefined imports in the input ELF became STB_GLOBAL in the relinked output, so a title that weak-imports a function no module exports stopped at startup instead of binding the import to null. Keep STB_WEAK on the relinked dynamic symbols. On Windows, write 0 plus the addend to the slot of a weak import that no searched module exports. Fixes boykopovar#4497 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Overlaps with #4452 on the same lines in The |
|
Tested the Windows part on Windows. Setup: Windows 11 Enterprise 10.0.26200 x64, WinLibs GCC 15.2.0 r7 (
Review note, no change requested: the weak branch in |
…orts # Conflicts: # core/relinker/relinker/src/output/SysVDynamicSectionBuilder.cpp # core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp
|
@gabichuuuuu thanks for running it on Windows. #4452 is merged, so I merged On the review note: agreed, the 16/17 loads are unreachable in the weak branch because only executable imports set |
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