build(libs): keep import libraries stable so a source edit relinks one library #4721
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4721"
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 fdfawef324 on 2026-10-12T19:44:57Z.
What
A libc or libkernel source edit relinked and re-patched every library: 124 links and 124 NID patches for one changed
.cpp. This change makes that edit relink and re-patch only the library that changed. A change to libc's export list still rebuilds everything that depends on it.Two dependencies caused the rebuild:
Import libraries. Every library links
liblibc.dll.aandliblibkernel.dll.a. GNU ld 2.46 rewrites an import library on every link with new archive timestamps, in the member headers and in the symbol map header. The bytes are otherwise identical. The link edge already hasrestat, but the file always changes, so nothing was pruned. On MinGW,core/libs/CMakeLists.txtnow changes the shared library link rule:<implib>.newwithSOURCE_DATE_EPOCH=0, which gives zero member timestamps.ranlib -Dzeroes the symbol map timestamp.cmake -E copy_if_differentreplaces the import library only when its bytes differ.The configure step fails if the rule has no
-Wl,--out-implib,<TARGET_IMPLIB>or if ranlib is missing. Linux and macOS links are unchanged.NID patch steps. Each patch step depended on the unpatched
libc.prx. It only uses the names libc exports.nid_patcher --write-export-listwrites those names, normalized and sorted, tobuild/core/libs/libc.exports, and leaves the file untouched when they did not change. The patch steps read the file with the new--preserve-export-listoption and depend on it instead oflibc.prx. This applies to every platform.A malformed list throws: missing final newline, empty name, duplicate name or empty file. So does giving both reference options.
SOURCE_DATE_EPOCH=0also sets the export directoryTimeDateStampof each.prxto 0. Without it, that field is the link time. The COFF headerTimeDateStampstill holds the link time. The unwinder's image key inUnwind.cppuses that header field, so it is unaffected.Why this is still needed with
CMAKE_LINK_DEPENDS_NO_SHARED=ON: that option drops the import libraries from the dependent link edges altogether. It is opt-in, so CI and default builds do not get it. It is also unsafe when an export is removed or renamed, because the dependents are not relinked against the new import library. With this change, default builds skip the relinks only when the import library bytes are unchanged, and still relink when an export changes. The option did not cover the 124 re-patches either. Those depended onlibc.prxitself.Sources:
ranlib -Dandld --out-implibrestatTested
Windows Server 2025, RTX 3060, GCC 15.2 (winlibs, binutils 2.46), Ninja, Release.
Red on main. I extended
nid_patcher_macho(core/libs/nid/tests/test_macho_nids.py) withcheck_export_list. It checks four things:--preserve-export-listkeeps the same exports that--preserve-exportskeeps. Malformed lists and two references are refused.On main the test fails at the first step, because main treats
--write-export-listas a library name:FAIL: ...listed.exports: cannot open. With the fix it passes (1.46 s).Rebuild after touching one file. Each run is
ninja -d explain -j 4 libsaftertouch, on a machine shared with other builds, so wall times are noisy. The edge counts are exact. I measured the default configuration by temporarily settingCMAKE_LINK_DEPENDS_NO_SHARED OFFincore/libs; that line is not committed.libc/src/Strings.cpplibkernel/Time/Time.cpplibc/src/Strings.cppNO_SHARED=ONlibkernel/Time/Time.cppNO_SHARED=ONIn every "after" run,
ninja -d explainnames onlylibc.prx(orlibkernel.prx) as dirty after the object file, and a secondninja libsreportsno work to do.An export change still rebuilds everything. I removed a temporary libc export, so
libc.exportsandliblibc.dll.achanged. The rebuild relinked and re-patched all 124 libraries.Same patched output. For 10 libraries, I patched once against
libc.prx(--preserve-exports) and once againstlibc.exports(--preserve-export-list). Both results are byte-identical to each other and to the builtlibs/*.prx: libkernel, libSceAudioIn, libSceNet, libSceVideoOut, libSceLibcInternal, libScePad, libSceSaveData, libSceAgc, libSceFiber and libSceUserService.Determinism. After a relink of libc, the
ranlib -Doutput is byte-identical. Without the change, two links of libc gave import libraries that differ in 1106 bytes, all of them archive date fields.Tests that link the new import libraries pass (13/13):
nid_patcher_macho,patched_libraries,guest_posix_scalar_io,guest_kernel_sys,guest_offline_imports,guest_memory_pool_stats,guest_time_conversion,guest_wide_strings,guest_math,guest_libc_threads,guest_libc_static_imports,guest_kernel_syncandguest_kernel_fcntl.Not tested on Linux or macOS. There the change only switches the patch steps to
libc.exports, whichnid_patcher_machocovers. Not tested with a title.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 xXPBSXx on 2026-10-13T12:27:15Z.
Windows test: head
555ac9fc3merged onto currentmainff8fe4dbc, together with 6 other open pull requests in one build (the merges were conflict-free); a failure would have been bisected per PR. Windows 10, MinGW GCC (WinLibs), Ninja Release,-j2: full build 0 errors; ctest for the tests this change adds or touches: nid_patcher_macho passed;python tools/check_conventions.py --base upstream/mainpassed for the combined tree. I did not run the new tests againstmainwithout the change.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T15:12:58Z.
Checked the diff,
nid_patcher_macho(export list written only on change, malformed lists and double reference refused, same preserved exports as--preserve-exports) and the core/libs build and tests on Linux (26/26). The MinGW link rule is covered by the Windows build and @xXPBSXx's Windows run; merging once it is green.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T16:54:45Z.
Re-checked after the rebase: the change is the same, only context lines moved. Core/libs build and tests on current main pass on Linux (32/32, incl.
nid_patcher_macho). The MinGW link rule is covered by the Windows build and @xXPBSXx's Windows run; merging once it is green.