fix(tools): audit unscoped Windows imports against searched libraries #17564
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17564"
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 adam25136 on 2026-11-08T22:19:37Z.
What
On Windows the executable's entry stub searches an import that names no library only in the libraries it loads: the title's converted modules, then the libraries the converted executable lists (the title's host dependencies and its modules').
WindowsImportBuilder::ReadLibrariesadds the three kernel libraries when the title needs one of them, andlibc.prxwhen it needs a kernel library orlibSceLibcInternal.prx(WindowsEntryStubBuilder.cppputs every library in the search order when the import has no library).tools/import_audit.pycounted every built library that exports the NID instead. A title can therefore pass the audit and stop at load: inFAMOUS Second Son (CUSA00223, a PS4 title) passes onmainwith no absent import and no current stop, while 47 of its imports are exported only bylibSceGnmDriverForNeoMode.prx, which it does not list. The registry gives every import of a PS4 executable an emptylibrary, because the relinker reads an executable's import modules only from tag0x61000045(RelinkerPipeline.cpp:321), while a PS4 executable lists them under0x6100000f, whichGuestImageReader.cppreads for modules. So the library mismatch note does not catch them either. PS5 executables have unscoped imports too: 29 of the 2,079 entries in Planet Zoo's executable registry..needed.jsoncompanions and PE libraries, an import without a library now counts only the built libraries that stub searches. The title's modules are all searched, as the stub puts every converted module in the order, so the needed-list filter on modules no longer applies on that path.absent: it fails the audit and can be the current stop. Its JSON record lists the built libraries that do export it inunsearched_providers; the summary counts them per library underunsearched_providers, and the report names them.--modulesELF imports and Linux builds are classified as before. Their records and summary get an emptyunsearched_providers, and the report's absent heading now reads "no built library the loader searches exports these".library_mismatchnote (a failure with--strict-providers), although for a built library the stub searches that library andlibc.prx, plus the kernel family for a kernel library and a title module that provideslibc.prxforlibSceLibcInternal.prx. If the relinker scoped PS4 imports, the 47 would become such notes.docs/user/USAGE.md: theabsentrow and a paragraph on the Windows search. It also says that the companions of all registries passed are pooled, so one executable's registries go together, and that without a module's folder in--modules, imports only that module provides areabsent.Tested
Windows 10 Pro 22H2 (19045), Python 3.13.3, on
main0bae53facd; rebased onto22ae9a397dbefore opening, whose one new merge changes onlycore/libs/prx/libSceFios2/src/Diagnostics.cpp, and the tests pass there too:tools/tests/test_import_audit.py: 190 tests run, 2 skipped;mainruns 187, 2 skipped. The three new tests fail againstmain's audit:libSceLibcInternalcases, wheremaincountslibkernel_sys.prxandlibkernel_web.prxas providers;unsearched_providersfield. Theremainbinds the name tolibSceOther.prx, which exports it literally but is not searched, where the stub falls back to the NID inlibc.prx.ctest -R '^import_audit$'passes, and so dotest_audit_dump.py,test_audit_strict_partial.pyandtest_job_reference_errors.py.import_audit.py, each reverted afterwards, are each caught by the new tests: no kernel family, nolibc.prx, no.sprxmapping of the needed names, hosts not filtered, the Windows path turned off, modules still filtered by the needed list on the Windows path, andunsearched_providerskept on a resolved import.relinker --registry --windowson0bae53facd. The eboot was unwrapped with a local change totools/unwrap_self.py(it fails on this PS4 eboot with "segment 5 does not fit the file");--moduleswas the converted.guest.prxmodules, because the unwrapped PS4 modules have noDT_STRTABorDT_SYMTAB.main: exit 0; 550 implemented, 10 partial, 34 stub, 0 absent; no current stop.libSceGnmDriverForNeoMode.prx; current stop0BzLGljcwBo(sceGnmDispatchDirect). The 41libSceFios2imports now resolve to the title's own module instead of the builtlibSceFios2.prx, which the convertedapp.exedoes not load because the title's module supplies that library; 28 others lose a.native.prxorlibSceAmpr.prxprovider and keep a searched one.main22ae9a397d(this branch rebased, which changes no library) with the libraries built there; the conversion is byte-identical to the0bae53facdone. It exits with0xC0000139after 0.2 s, printingunresolved ELF importfor the same 47 NIDs, the first being0BzLGljcwBo. ItsSearched librarieslist is the set this change computes from the companions: 33 entries, the title's two modules first, withoutlibSceGnmDriverForNeoMode.prx.relinker --registry --windows --to-intelon0bae53facd:mainand this branch both exit 0 with the same counts (649 implemented, 7 partial, 1 stub, 0 absent, 268 module) and no class change. 26 imports loselibSceAjm.prx,libSceMsgDialog.prxorlibSceSaveDataDialog.prxas a provider and keep the.native.prxlibrary the title lists.python tools/check_conventions.py --base origin/mainwith this title and description passed.python tools/pr_overlap.py --branchover all 1,979 open pull requests: 45 share a file with this branch, and none of the 32 it compared conflicts with it. It could not compare 13 that conflict withmain, all throughdocs/user/USAGE.md(#5021, #5925, #6924, #7642, #9345, #10193, #12678, #12863, #13928, #13929, #14298, #15169, #15456). On each one's merge base, every hunk they make in that file ends before the "Import audit" section, and none of their changed lines mentions the audit.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code